Class: Hippo::TransactionSets::Base
- Inherits:
-
Object
- Object
- Hippo::TransactionSets::Base
- Includes:
- Outputters::HTML::TransactionSet, Outputters::PDF::TransactionSet, Outputters::PrettyString::TransactionSet, Parser::TransactionSet, Separator
- Defined in:
- lib/hippo/transaction_sets/base.rb
Direct Known Subclasses
HIPAA_270::Base, HIPAA_270::L2000A, HIPAA_270::L2000B, HIPAA_270::L2000C, HIPAA_270::L2000D, HIPAA_270::L2100A, HIPAA_270::L2100B, HIPAA_270::L2100C, HIPAA_270::L2100D, HIPAA_270::L2110C, HIPAA_270::L2110D, HIPAA_271::Base, HIPAA_271::L2000A, HIPAA_271::L2000B, HIPAA_271::L2000C, HIPAA_271::L2000D, HIPAA_271::L2100A, HIPAA_271::L2100B, HIPAA_271::L2100C, HIPAA_271::L2100D, HIPAA_271::L2110C, HIPAA_271::L2110D, HIPAA_271::L2115C, HIPAA_271::L2115D, HIPAA_271::L2120C, HIPAA_271::L2120D, HIPAA_276::Base, HIPAA_276::L2000A, HIPAA_276::L2000B, HIPAA_276::L2000C, HIPAA_276::L2000D, HIPAA_276::L2000E, HIPAA_276::L2100A, HIPAA_276::L2100B, HIPAA_276::L2100C, HIPAA_276::L2100D, HIPAA_276::L2100E, HIPAA_276::L2200D, HIPAA_276::L2200E, HIPAA_276::L2210D, HIPAA_276::L2210E, HIPAA_277::Base, HIPAA_277::L2000A, HIPAA_277::L2000B, HIPAA_277::L2000C, HIPAA_277::L2000D, HIPAA_277::L2000E, HIPAA_277::L2100A, HIPAA_277::L2100B, HIPAA_277::L2100C, HIPAA_277::L2100D, HIPAA_277::L2100E, HIPAA_277::L2200A, HIPAA_277::L2200B, HIPAA_277::L2200C, HIPAA_277::L2200D, HIPAA_277::L2200E, HIPAA_277::L2220D, HIPAA_277::L2220E, HIPAA_835::Base, HIPAA_835::L1000A, HIPAA_835::L1000B, HIPAA_835::L2000, HIPAA_835::L2100, HIPAA_835::L2110, HIPAA_837::Base, HIPAA_837::L1000A, HIPAA_837::L1000B, HIPAA_837::L2000A, HIPAA_837::L2000B, HIPAA_837::L2000C, HIPAA_837::L2010AA, HIPAA_837::L2010AB, HIPAA_837::L2010AC, HIPAA_837::L2010BA, HIPAA_837::L2010BB, HIPAA_837::L2010CA, HIPAA_837::L2300, HIPAA_837::L2310A, HIPAA_837::L2310B, HIPAA_837::L2310C, HIPAA_837::L2310D, HIPAA_837::L2310E, HIPAA_837::L2310F, HIPAA_837::L2320, HIPAA_837::L2330A, HIPAA_837::L2330B, HIPAA_837::L2330C, HIPAA_837::L2330D, HIPAA_837::L2330E, HIPAA_837::L2330F, HIPAA_837::L2330G, HIPAA_837::L2400, HIPAA_837::L2410, HIPAA_837::L2420A, HIPAA_837::L2420B, HIPAA_837::L2420C, HIPAA_837::L2420D, HIPAA_837::L2420E, HIPAA_837::L2420F, HIPAA_837::L2420G, HIPAA_837::L2420H, HIPAA_837::L2430, HIPAA_837::L2440, HIPAA_997::Base, HIPAA_997::L2000, HIPAA_997::L2100, HIPAA_999::Base, HIPAA_999::L2000AK2, HIPAA_999::L2100AK2, HIPAA_999::L2110AK2
Class Attribute Summary collapse
-
.components ⇒ Object
Returns the value of attribute components.
-
.identifier ⇒ Object
Returns the value of attribute identifier.
Instance Attribute Summary collapse
-
#GE ⇒ Object
Returns the value of attribute GE.
-
#GS ⇒ Object
Returns the value of attribute GS.
-
#IEA ⇒ Object
Returns the value of attribute IEA.
-
#ISA ⇒ Object
Returns the value of attribute ISA.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#sequences ⇒ Object
Returns the value of attribute sequences.
-
#values ⇒ Object
Returns the value of attribute values.
Attributes included from Parser::TransactionSet
Attributes included from Separator
#composite_separator, #field_separator, #repetition_separator, #segment_separator
Class Method Summary collapse
- .add_component(klass, options = {}) ⇒ Object (also: segment, loop)
- .build_grouped_components ⇒ Object
- .grouped_components ⇒ Object
- .loop_name(id) ⇒ Object
Instance Method Summary collapse
- #ancestors ⇒ Object
- #get_component(identifier, sequence = nil) ⇒ Object
- #get_component_by_name(name, sequence = nil) ⇒ Object
- #increment(segment_identifier) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #method_missing(method_name, *args) {|| ... } ⇒ Object
- #populate(segments) ⇒ Object
- #segment? ⇒ Boolean
- #segment_count ⇒ Object
- #segments ⇒ Object
- #to_ary ⇒ Object (also: #to_a)
- #to_s ⇒ Object
- #transaction_set? ⇒ Boolean
Methods included from Outputters::PrettyString::TransactionSet
#pretty_print, #to_pretty_string
Methods included from Outputters::PDF::TransactionSet
Methods included from Outputters::HTML::TransactionSet
Methods included from Parser::TransactionSet
#find_first_segment, #parse, #parsed_segments, #read
Methods included from Separator
#empty_field_regexp, #parent_or_default_separator, #parse_separators, #regexp_escaped_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.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/hippo/transaction_sets/base.rb', line 53 def initialize( = {}) @parent = [:parent] @ISA = [:ISA] @GS = [:GS] @GE = [:GE] @IEA = [:IEA] super populate([:segments]) if [:segments] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) {|| ... } ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/hippo/transaction_sets/base.rb', line 217 def method_missing(method_name, *args) component = if method_name == :find_by_name get_component_by_name(args[0], args[1]) else component_name, component_sequence = method_name.to_s.split('_') get_component(component_name, component_sequence) end if component.nil? raise Hippo::Exceptions::InvalidSegment.new "Invalid segment specified: '#{method_name.to_s}'." end values[component.sequence] ||= component.initialize_component(self) yield values[component.sequence] if block_given? values[component.sequence] end |
Class Attribute Details
.components ⇒ Object
Returns the value of attribute components.
10 11 12 |
# File 'lib/hippo/transaction_sets/base.rb', line 10 def components @components end |
.identifier ⇒ Object
Returns the value of attribute identifier.
10 11 12 |
# File 'lib/hippo/transaction_sets/base.rb', line 10 def identifier @identifier end |
Instance Attribute Details
#GE ⇒ Object
Returns the value of attribute GE.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def GE @GE end |
#GS ⇒ Object
Returns the value of attribute GS.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def GS @GS end |
#IEA ⇒ Object
Returns the value of attribute IEA.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def IEA @IEA end |
#ISA ⇒ Object
Returns the value of attribute ISA.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def ISA @ISA end |
#parent ⇒ Object
Returns the value of attribute parent.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def parent @parent end |
#sequences ⇒ Object
Returns the value of attribute sequences.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def sequences @sequences end |
#values ⇒ Object
Returns the value of attribute values.
51 52 53 |
# File 'lib/hippo/transaction_sets/base.rb', line 51 def values @values end |
Class Method Details
.add_component(klass, options = {}) ⇒ Object Also known as: segment, loop
20 21 22 |
# File 'lib/hippo/transaction_sets/base.rb', line 20 def add_component(klass, ={}) components << Component.new(.merge(:klass => klass, :sequence => components.length)) end |
.build_grouped_components ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hippo/transaction_sets/base.rb', line 31 def build_grouped_components output = [] last_entry = nil components.each do |component| if component.segment? output << [] if last_entry != :segment output.last << component last_entry = :segment else output << component last_entry = :transaction_set end end output end |
.grouped_components ⇒ Object
27 28 29 |
# File 'lib/hippo/transaction_sets/base.rb', line 27 def grouped_components @grouped_components ||= build_grouped_components end |
.loop_name(id) ⇒ Object
16 17 18 |
# File 'lib/hippo/transaction_sets/base.rb', line 16 def loop_name(id) @identifier = id end |
Instance Method Details
#ancestors ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/hippo/transaction_sets/base.rb', line 166 def ancestors if parent [parent, parent.ancestors].flatten else [] end end |
#get_component(identifier, sequence = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/hippo/transaction_sets/base.rb', line 189 def get_component(identifier, sequence = nil) if sequence.nil? sequence = 0 else sequence = sequence.to_i - 1 end self.class.components.select do |c| c.identifier == identifier end[sequence] end |
#get_component_by_name(name, sequence = nil) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/hippo/transaction_sets/base.rb', line 201 def get_component_by_name(name, sequence = nil) sequence = if sequence.nil? 0 else sequence.to_i - 1 end self.class.components.select do |c| if name.class == Regexp c.[:name] =~ name else c.[:name] == name end end[sequence] end |
#increment(segment_identifier) ⇒ Object
144 145 146 147 148 |
# File 'lib/hippo/transaction_sets/base.rb', line 144 def increment(segment_identifier) @sequences ||= Hash.new(0) @sequences[segment_identifier] += 1 end |
#populate(segments) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/hippo/transaction_sets/base.rb', line 65 def populate(segments) grouped_components = self.class.grouped_components grouped_components.each_with_index do |component, component_index| if component.class == Array # segments starting_segment_count = segments.count ending_segment_count = 0 while starting_segment_count > ending_segment_count starting_segment_count = segments.count component.each do |individual_component| segment = segments.first break unless segment next unless individual_component.valid?(segment) next unless individual_component.conditions_match?(self, segment) segment.parent = self if individual_component.repeating? values[individual_component.sequence] ||= individual_component.initialize_component(self) values[individual_component.sequence] << segment else values[individual_component.sequence] = segment end segments.delete(segment) end ending_segment_count = segments.count end else # loops while true do initial_segment = segments.first break unless initial_segment break unless component.valid?(initial_segment) break unless component.conditions_match?(self, initial_segment) component_matches_found = [] starting_index = component.repeating? ? component_index : component_index + 1 grouped_components.slice(starting_index, grouped_components.length - starting_index).each do |next_component| index = segments.find_index do |segment| if segment == segments.first false elsif next_component.class == Array next_component.any?{|subcomponent| subcomponent.valid?(segment)} else next_component.valid?(segment) end end component_matches_found << index if index end child_segments = segments.slice!(0, component_matches_found.min || segments.length) values[component.sequence] ||= component.initialize_component(self) if component.repeating? values[component.sequence].build {|comp| comp.populate(child_segments) } else values[component.sequence].populate(child_segments) end end end end unless segments.empty? raise Hippo::Exceptions::ParseError.new "Remaining Segments for #{self.class.identifier} after parsing was completed. Segments remaining: \n" + segments.map(&:to_s).join("\n") end end |
#segment? ⇒ Boolean
150 151 152 |
# File 'lib/hippo/transaction_sets/base.rb', line 150 def segment? false end |
#segment_count ⇒ Object
162 163 164 |
# File 'lib/hippo/transaction_sets/base.rb', line 162 def segment_count segments.count end |
#segments ⇒ Object
158 159 160 |
# File 'lib/hippo/transaction_sets/base.rb', line 158 def segments values.values.collect(&:segments).flatten end |
#to_ary ⇒ Object Also known as: to_a
174 175 176 |
# File 'lib/hippo/transaction_sets/base.rb', line 174 def to_ary nil end |
#to_s ⇒ Object
179 180 181 182 183 184 185 186 187 |
# File 'lib/hippo/transaction_sets/base.rb', line 179 def to_s output = '' values.sort.each do |sequence, component| output += component.to_s end output end |
#transaction_set? ⇒ Boolean
154 155 156 |
# File 'lib/hippo/transaction_sets/base.rb', line 154 def transaction_set? true end |