Class: Sie::Parser::LineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/sie/parser/line_parser.rb

Instance Method Summary collapse

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sie/parser/line_parser.rb', line 10

def parse
  tokens = tokenize(line)
  first_token = tokens.shift

  entry = Entry.new(first_token.label)
  entry_type = first_token.entry_type

  entry_type.each_with_index do |entry_type, i|
    break if i >= tokens.size

    if entry_type.is_a?(Hash)
      skip_array(tokens, i)
      next
    else
      label = entry_type
      entry.attributes[label] = tokens[i].value
    end
  end

  entry
end