Module: Hippo::Parser::TransactionSet

Included in:
Hippo::Parser, TransactionSets::Base
Defined in:
lib/hippo/parser/transaction_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#unparsed_dataObject

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(options={})
  super
end

#parse(input) ⇒ Object



37
38
39
40
41
# File 'lib/hippo/parser/transaction_set.rb', line 37

def parse(input)
  read(input)
  populate(parsed_segments)
  self
end

#parsed_segmentsObject



20
21
22
23
24
25
26
27
28
# File 'lib/hippo/parser/transaction_set.rb', line 20

def parsed_segments
  @segments ||= @unparsed_data.split(@segment_separator).collect do |segment_string|
    segment = Hippo::Segments.const_get(segment_string.split(@field_separator).first).new(:parent => self)

    segment.parse(segment_string)

    segment.to_s == '' ? nil : segment
  end.compact
end

#read(input = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/hippo/parser/transaction_set.rb', line 30

def read(input = nil)
  input ||= ''

  @unparsed_data = input.gsub(/[\a\e\f\n\r\t\v]/,'')
  parse_separators(@unparsed_data)
end