Eno::Section » #lookup

lookup(index) → Hash or nil
lookup(line, column) → Hash or nil

Ask the document Hey what's at column X in line Y in my eno file?. The lookup always returns an element for valid indices (the document/section in case of an empty line/space), only indices outside the range of the document return nil. Note that all arguments are zero-indexed, i.e. the first lines and columns are numbered 0, not 1.

enocolor: blue

# notes
rubydocument = Eno.parse(input)

document.lookup(3)  # 'o'
  #=> { element: #<Eno::Field name="color" value="blue">, zone: :name }
document.lookup(7)  # 'b'
  #=> { element: #<Eno::Field name="color" value="blue">, zone: :value }
document.lookup(0, 3)  # 'o'
  #=> { element: #<Eno::Field name="color" value="blue">, zone: :name }
document.lookup(0, 7)  # 'b'
  #=> { element: #<Eno::Field name="color" value="blue">, zone: :value }
document.lookup(13)  # '#'
  #=> { element: #<Eno::Section name="notes" elements=0>, zone: :section_operator }
document.lookup(19)  # 's'
  #=> { element: #<Eno::Section name="notes" elements=0>, zone: :name }
document.lookup(2, 0)  # '#'
  #=> { element: #<Eno::Section name="notes" elements=0>, zone: :section_operator }
document.lookup(2, 6)  # 's'
  #=> { element: #<Eno::Section name="notes" elements=0>, zone: :name }

Parameters

index

A one-dimensional index to look up (0-indexed, i.e. the first position is 0, not 1)- only applies when it's the only given argument.

line

The line to look up (0-indexed, i.e. the first line is 0, not 1) - only applies when you supply a column as well.

column

The column to look up (0-indexed, i.e. the first column is 0, not 1) - only applies when you supply a line as well.

Return value

For all valid indices within the document returns a Hash with two keys:

element: An Eno::Section, Eno::Fieldset, Eno::Field.. . For empty lines you get the containing section.

zone: A symbol denoting the token at the specified position, here's the full list:

'[empty-lines-and-spaces-between-tokens]' => :element
'[inside-blocks]' => :content
'[inside-comments]' => :comment
'[name]' => :name
'[template]' => :value
'[value]' => :value
':' => :name_operator
'-' => :item_operator
'=' => :entry_operator
'--' => :block_operator
'>' => :comment_operator
'`' => :escape_begin_operator
'`' => :escape_end_operator
'|' => :newline_continuation_operator
'\' => :line_continuation_operator
'#' => :section_operator
'<' => :copy_operator
'<<' => :deep_copy_operator

When an index outside the document is supplied, nil is returned.