Module: Hippo::Parser::TransactionSet
- Included in:
- Hippo::Parser, TransactionSets::Base
- Defined in:
- lib/hippo/parser/transaction_set.rb
Instance Attribute Summary collapse
-
#unparsed_data ⇒ Object
Returns the value of attribute unparsed_data.
Instance Method Summary collapse
- #find_first_segment(segments, identifier, reverse = false) ⇒ Object
- #initialize(options = {}) ⇒ Object
- #parse(input) ⇒ Object
- #parsed_segments ⇒ Object
- #read(input = nil) ⇒ Object
Instance Attribute Details
#unparsed_data ⇒ Object
Returns the value of attribute unparsed_data.
4 5 6 |
# File 'lib/hippo/parser/transaction_set.rb', line 4 def unparsed_data @unparsed_data end |
Instance Method Details
#find_first_segment(segments, identifier, reverse = false) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/hippo/parser/transaction_set.rb', line 10 def find_first_segment(segments, identifier, reverse = false) segments.reverse! if reverse if index = segments.index{|o| o.identifier == identifier} segments[index] else nil end end |
#initialize(options = {}) ⇒ Object
6 7 8 |
# File 'lib/hippo/parser/transaction_set.rb', line 6 def initialize(={}) super end |
#parse(input) ⇒ Object
38 39 40 41 42 |
# File 'lib/hippo/parser/transaction_set.rb', line 38 def parse(input) read(input) populate(parsed_segments) self end |
#parsed_segments ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hippo/parser/transaction_set.rb', line 20 def parsed_segments @segments ||= @unparsed_data.split(@segment_separator).collect do |segment_string| segment_identifier = segment_string.split(@field_separator).first segment = Hippo::Segments.const_get(segment_identifier.lstrip).new(:parent => self) segment.parse(segment_string) segment.to_s == '' ? nil : segment end.compact end |
#read(input = nil) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/hippo/parser/transaction_set.rb', line 31 def read(input = nil) input ||= '' @unparsed_data = input.gsub(/[\a\e\f\n\r\t\v]/,'') parse_separators(@unparsed_data) end |