Class: Hippo::Parser
- Inherits:
-
Object
show all
- Includes:
- TransactionSet, Separator
- Defined in:
- lib/hippo/parser.rb,
lib/hippo/parser/segment.rb,
lib/hippo/parser/transaction_set.rb
Defined Under Namespace
Modules: Segment, TransactionSet
Instance Attribute Summary
#unparsed_data
Attributes included from Separator
#composite_separator, #field_separator, #repetition_separator, #segment_separator
Class Method Summary
collapse
Instance Method Summary
collapse
#find_first_segment, #parse, #parsed_segments, #read
Methods included from Separator
#empty_field_regexp, #parent_or_default_separator, #parse_separators, #remove_empty_fields, #repeating_composite_separator_regexp, #repeating_field_separator_at_end_of_segment_regexp, #separators
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
19
20
21
|
# File 'lib/hippo/parser.rb', line 19
def initialize
super
end
|
Class Method Details
.parse_file(input) ⇒ Object
9
10
11
12
|
# File 'lib/hippo/parser.rb', line 9
def self.parse_file(input)
parser = new
parser.parse_string(input)
end
|
.parse_string(input) ⇒ Object
14
15
16
17
|
# File 'lib/hippo/parser.rb', line 14
def self.parse_string(input)
parser = new
parser.parse_string(input)
end
|
Instance Method Details
#initialize_transaction_set(index) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/hippo/parser.rb', line 23
def initialize_transaction_set(index)
{
:segments => [],
:ISA => find_first_segment(parsed_segments[0,index + 1], 'ISA', true),
:GS => find_first_segment(parsed_segments[0,index + 1], 'GS', true),
:GE => find_first_segment(parsed_segments[index + 1, parsed_segments.length - index + 1], 'GE'),
:IEA => find_first_segment(parsed_segments[index + 1, parsed_segments.length - index + 1], 'IEA')
}
end
|
#parse_file(filename) ⇒ Object
61
62
63
|
# File 'lib/hippo/parser.rb', line 61
def parse_file(filename)
parse_string(File.read(filename))
end
|
#parse_string(input) ⇒ Object
65
66
67
68
|
# File 'lib/hippo/parser.rb', line 65
def parse_string(input)
read(input)
populate_transaction_sets
end
|
#parse_transaction_sets ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/hippo/parser.rb', line 33
def parse_transaction_sets
raw_transaction_sets = []
inside_transaction = false
parsed_segments.each_with_index do |segment, index|
if segment.identifier == 'ST'
raw_transaction_sets << initialize_transaction_set(index)
inside_transaction = true
end
raw_transaction_sets.last[:segments] << segment if inside_transaction
inside_transaction = false if segment.identifier == 'SE'
end
raw_transaction_sets
end
|
#populate_transaction_sets ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/hippo/parser.rb', line 52
def populate_transaction_sets
parse_transaction_sets.collect do |transaction|
transaction_set_id = transaction[:segments].first.ST01
transaction_set = Hippo::TransactionSets.constants.select{|c| c.to_s.end_with?(transaction_set_id) }.first
Hippo::TransactionSets.const_get(transaction_set)::Base.new(separators.merge(transaction))
end
end
|