Class: Hippo::TransactionSets::Base
- Inherits:
-
Object
- Object
- Hippo::TransactionSets::Base
- Includes:
- Outputters::HTML::TransactionSet, Outputters::PDF::TransactionSet, Parser::TransactionSet, Separator
- Defined in:
- lib/hippo/transaction_sets/base.rb
Direct Known Subclasses
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)
- .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_count ⇒ Object
- #segments ⇒ Object
- #to_ary ⇒ Object (also: #to_a)
- #to_s ⇒ Object
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
#parent_or_default_separator, #parse_separators, #separators
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hippo/transaction_sets/base.rb', line 28 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
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/hippo/transaction_sets/base.rb', line 163 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.
9 10 11 |
# File 'lib/hippo/transaction_sets/base.rb', line 9 def components @components end |
.identifier ⇒ Object
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/hippo/transaction_sets/base.rb', line 9 def identifier @identifier end |
Instance Attribute Details
#GE ⇒ Object
Returns the value of attribute GE.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def GE @GE end |
#GS ⇒ Object
Returns the value of attribute GS.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def GS @GS end |
#IEA ⇒ Object
Returns the value of attribute IEA.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def IEA @IEA end |
#ISA ⇒ Object
Returns the value of attribute ISA.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def ISA @ISA end |
#parent ⇒ Object
Returns the value of attribute parent.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def parent @parent end |
#sequences ⇒ Object
Returns the value of attribute sequences.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def sequences @sequences end |
#values ⇒ Object
Returns the value of attribute values.
26 27 28 |
# File 'lib/hippo/transaction_sets/base.rb', line 26 def values @values end |
Class Method Details
.add_component(klass, options = {}) ⇒ Object Also known as: segment, loop
19 20 21 |
# File 'lib/hippo/transaction_sets/base.rb', line 19 def add_component(klass, ={}) components << Component.new(.merge(:klass => klass, :sequence => components.length)) end |
.loop_name(id) ⇒ Object
15 16 17 |
# File 'lib/hippo/transaction_sets/base.rb', line 15 def loop_name(id) @identifier = id end |
Instance Method Details
#ancestors ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/hippo/transaction_sets/base.rb', line 112 def ancestors if parent [parent, parent.ancestors].flatten else [] end end |
#get_component(identifier, sequence = nil) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/hippo/transaction_sets/base.rb', line 135 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
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/hippo/transaction_sets/base.rb', line 147 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
98 99 100 101 102 |
# File 'lib/hippo/transaction_sets/base.rb', line 98 def increment(segment_identifier) @sequences ||= Hash.new(0) @sequences[segment_identifier] += 1 end |
#populate(segments) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 |
# File 'lib/hippo/transaction_sets/base.rb', line 40 def populate(segments) self.class.components.each_with_index do |component, component_index| if component.klass.ancestors.include? Hippo::Segments::Base # segments while true do segment = segments.first break unless segment break unless component.valid?(segment) segment.parent = self if component.repeating? values[component.sequence] ||= component.initialize_component(self) values[component.sequence] << segment else values[component.sequence] = segment end segments.delete(segment) end else # loops while true do initial_segment = segments.first break unless initial_segment break unless component.valid?(initial_segment) ending_index = nil starting_index = component.repeating? ? component_index : component_index + 1 remaining_components = self.class.components.slice(starting_index, self.class.components.length - starting_index) remaining_components.each do |next_component| break if ending_index ending_index = segments.find_index{|segment| segment != segments.first && next_component.valid?(segment)} end child_segments = segments.slice!(0, ending_index || 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_count ⇒ Object
108 109 110 |
# File 'lib/hippo/transaction_sets/base.rb', line 108 def segment_count segments.count end |
#segments ⇒ Object
104 105 106 |
# File 'lib/hippo/transaction_sets/base.rb', line 104 def segments values.values.collect(&:segments).flatten end |
#to_ary ⇒ Object Also known as: to_a
120 121 122 |
# File 'lib/hippo/transaction_sets/base.rb', line 120 def to_ary nil end |
#to_s ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/hippo/transaction_sets/base.rb', line 125 def to_s output = '' values.sort.each do |sequence, component| output += component.to_s end output end |