Class: Athena::Formats::Sisis
- Inherits:
-
Athena::Formats
- Object
- Athena::Formats
- Athena::Formats::Sisis
- Defined in:
- lib/athena/formats/sisis.rb
Defined Under Namespace
Classes: IllegalRecordElementError, NoRecordElementError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#record_element ⇒ Object
readonly
Returns the value of attribute record_element.
Instance Method Summary collapse
-
#initialize(parser) ⇒ Sisis
constructor
A new instance of Sisis.
- #parse(source) ⇒ Object
Methods inherited from Athena::Formats
[], convert, deferred?, formats, valid_format?
Constructor Details
#initialize(parser) ⇒ Sisis
Returns a new instance of Sisis.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/athena/formats/sisis.rb', line 37 def initialize(parser) config = parser.config.dup case @record_element = config.delete(:__record_element) when String # fine! when nil raise NoRecordElementError, 'no record element specified' else raise IllegalRecordElementError, "illegal record element #{@record_element}" end @config = config @parser = parser end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
35 36 37 |
# File 'lib/athena/formats/sisis.rb', line 35 def config @config end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
35 36 37 |
# File 'lib/athena/formats/sisis.rb', line 35 def parser @parser end |
#record_element ⇒ Object (readonly)
Returns the value of attribute record_element.
35 36 37 |
# File 'lib/athena/formats/sisis.rb', line 35 def record_element @record_element end |
Instance Method Details
#parse(source) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/athena/formats/sisis.rb', line 53 def parse(source) record = nil source.each { |line| element, value = line.match(/(\d+).*?:\s*(.*)/)[1, 2] case element when record_element record.close if record record = Athena::Record.new(parser.block, value) else record.update(element, value, config[element]) end } record.close if record end |