Class: Athena::Formats::Sisis

Inherits:
Base
  • Object
show all
Defined in:
lib/athena/formats/sisis.rb

Constant Summary collapse

RECORD_RE =
%r{(\d+).*?:\s*(.*)}

Instance Attribute Summary

Attributes inherited from Base

#config, #output, #record_element

Instance Method Summary collapse

Methods inherited from Base

#convert, #deferred?, directions, format, has_direction?, init, #init, #raw?, #run

Instance Method Details

#parse(input, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/athena/formats/sisis.rb', line 39

def parse(input, &block)
  record, num = nil, 0

  input.each { |line|
    element, value = line.match(RECORD_RE)[1, 2]

    if element == record_element
      record.close if record
      record = Athena::Record.new(value, block)
      num += 1
    else
      record.update(element, value, config[element])
    end
  }

  record.close if record

  num
end