Class: Hippo::Segments::Base
Direct Known Subclasses
AAA, AK1, AK2, AK3, AK4, AK5, AK9, AMT, BHT, BPR, CAS, CL1, CLM, CLP, CN1, CR1, CR2, CR3, CR4, CR5, CR6, CR7, CR8, CRC, CTP, CTX, CUR, DMG, DN1, DN2, DSB, DTM, DTP, EB, EM, EQ, FRM, GE, GS, HCP, HI, HL, HSD, IEA, III, IK3, IK4, IK5, IMM, INS, ISA, K3, LE, LIN, LQ, LS, LX, MEA, MIA, MOA, MPI, MSG, N1, N2, N3, N4, NM1, NTE, OI, PAT, PCT, PDP, PDR, PER, PID, PKD, PLB, PRV, PS1, PWK, QTY, RDM, REF, SBR, SD1, SE, ST, STC, SV1, SV2, SV3, SV4, SV5, SV6, SV7, SVC, SVD, TA1, TOO, TRN, TS2, TS3, UR, VEH
Class Attribute Summary collapse
Instance Attribute Summary collapse
#composite_separator, #field_separator, #repetition_separator, #segment_separator
Class Method Summary
collapse
Instance Method Summary
collapse
#to_pdf
#to_html
#parse
#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(options = {}) ⇒ Base
Returns a new instance of Base.
91
92
93
94
95
|
# File 'lib/hippo/segments/base.rb', line 91
def initialize(options = {})
@parent = options.delete(:parent)
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/hippo/segments/base.rb', line 163
def method_missing(method_name, *args)
values
field = get_field(get_field_name(method_name.to_s))
if field.nil? || field.class == Array
raise Hippo::Exceptions::InvalidField.new("Invalid field '#{method_name.to_s}' specified.")
end
if method_name.to_s =~ /=\z/
if field.composite
self.values[field.composite_sequence] ||= {}
self.values[field.composite_sequence][field.sequence] = field.formatted_value(args[0])
else
self.values[field.sequence] = field.formatted_value(args[0])
end
else
if field.composite
self.values[field.composite_sequence] ||= {}
self.values[field.composite_sequence][field.sequence]
else
self.values[field.sequence]
end
end
end
|
Class Attribute Details
.fields ⇒ Object
Returns the value of attribute fields.
9
10
11
|
# File 'lib/hippo/segments/base.rb', line 9
def fields
@fields
end
|
.fixed_width ⇒ Object
Returns the value of attribute fixed_width.
9
10
11
|
# File 'lib/hippo/segments/base.rb', line 9
def fixed_width
@fixed_width
end
|
.identifier ⇒ Object
Returns the value of attribute identifier.
9
10
11
|
# File 'lib/hippo/segments/base.rb', line 9
def identifier
@identifier
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
68
69
70
|
# File 'lib/hippo/segments/base.rb', line 68
def parent
@parent
end
|
#values ⇒ Object
Returns the value of attribute values.
68
69
70
|
# File 'lib/hippo/segments/base.rb', line 68
def values
@values
end
|
Class Method Details
.composite_field(field_name) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/hippo/segments/base.rb', line 49
def composite_field(field_name)
@composite_block = true
@default_separator = :composite_separator
fields << []
yield
@default_separator = :field_separator
@composite_block = false
end
|
.field(field) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/hippo/segments/base.rb', line 19
def field(field)
f = Hippo::Field.new
f.sequence = fields.length + 1
f.name = field[:name]
f.datatype = field[:datatype]
f.minimum = field[:minimum]
f.maximum = field[:maximum]
f.options = field[:options]
f.restrictions = field[:restrictions]
f.required = field[:required] || false
f.separator = field[:separator] || @default_separator || :field_separator
if @composite_block
f.composite = true
f.composite_sequence = fields.length
f.sequence = fields.last.length + 1
fields.last << f
else
fields << f
end
end
|
.segment? ⇒ Boolean
41
42
43
|
# File 'lib/hippo/segments/base.rb', line 41
def segment?
true
end
|
.segment_fixed_width ⇒ Object
63
64
65
|
# File 'lib/hippo/segments/base.rb', line 63
def segment_fixed_width
@fixed_width = true
end
|
.segment_identifier(id) ⇒ Object
58
59
60
61
|
# File 'lib/hippo/segments/base.rb', line 58
def segment_identifier(id)
@identifier = id
@fields = []
end
|
.transaction_set? ⇒ Boolean
45
46
47
|
# File 'lib/hippo/segments/base.rb', line 45
def transaction_set?
false
end
|
Instance Method Details
#ancestors ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/hippo/segments/base.rb', line 78
def ancestors
if parent
parent.ancestors.flatten
else
[]
end
end
|
#get_field(field) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/hippo/segments/base.rb', line 105
def get_field(field)
if field =~ /\A#{self.class.identifier}(?:(\d+)(?:_(\d+)){0,1})\z/
if $2 && self.class.fields[$1.to_i - 1].class == Array
self.class.fields[$1.to_i - 1][$2.to_i - 1]
else
self.class.fields[$1.to_i - 1]
end
else
fields = self.class.fields.flatten.select{|f| f.name == field.gsub(/_\d{1,2}\z/,'')}
if field =~ /_(\d{1,2})\z/
fields[$1.to_i - 1]
else
fields.first
end
end
end
|
#get_field_name(text) ⇒ Object
101
102
103
|
# File 'lib/hippo/segments/base.rb', line 101
def get_field_name(text)
text.to_s.gsub(' ','').gsub('=','')
end
|
#identifier ⇒ Object
159
160
161
|
# File 'lib/hippo/segments/base.rb', line 159
def identifier
self.class.identifier
end
|
#segment_count ⇒ Object
74
75
76
|
# File 'lib/hippo/segments/base.rb', line 74
def segment_count
segments.count
end
|
#segments ⇒ Object
70
71
72
|
# File 'lib/hippo/segments/base.rb', line 70
def segments
[self]
end
|
#to_ary ⇒ Object
Also known as:
to_a
86
87
88
|
# File 'lib/hippo/segments/base.rb', line 86
def to_ary
nil
end
|
#to_s ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/hippo/segments/base.rb', line 123
def to_s
output = self.class.identifier + @field_separator
self.class.fields.each_with_index do |field, index|
if field.class == Array field.each do |comp_field|
field_value = if values[comp_field.composite_sequence]
comp_field.string_value(values[comp_field.composite_sequence][comp_field.sequence])
else
''
end
output += field_value + @composite_separator
end
output += @field_separator
else field_value = field.string_value(values[field.sequence])
output += field_value + @field_separator
end
end
unless self.class.fixed_width
output = remove_empty_fields(output)
output = output.gsub(repeating_composite_separator_regexp, @field_separator)
end
output += @segment_separator
output = output.gsub(repeating_field_separator_at_end_of_segment_regexp, @segment_separator)
output =~ /\A#{self.class.identifier}~/ ? '' : output
end
|