Class: Eddy::Models::Interchange
- Inherits:
-
Object
- Object
- Eddy::Models::Interchange
- Defined in:
- lib/eddy/models/interchange.rb
Overview
Top level EDI interchange.
Instance Attribute Summary collapse
-
#control_number ⇒ Integer
A unique control number for the Interchange.
-
#store ⇒ Eddy::Data::Store
Data store for the Interchange.
- #transaction_sets ⇒ Array<Eddy::Models::TransactionSet>
Class Method Summary collapse
Instance Method Summary collapse
- #functional_groups ⇒ Array<Eddy::Models::FunctionalGroup>
- #initialize(store = Eddy::Data::Store.new()) ⇒ void constructor
- #render {|isa, iea| ... } ⇒ String
Constructor Details
#initialize(store = Eddy::Data::Store.new()) ⇒ void
15 16 17 18 19 |
# File 'lib/eddy/models/interchange.rb', line 15 def initialize(store = Eddy::Data::Store.new()) self.control_number = Eddy::Data.new_interchange_control_number() self.store = store self.transaction_sets = [] end |
Instance Attribute Details
#control_number ⇒ Integer
A unique control number for the Interchange.
9 10 11 |
# File 'lib/eddy/models/interchange.rb', line 9 def control_number @control_number end |
#store ⇒ Eddy::Data::Store
Returns Data store for the Interchange.
6 7 8 |
# File 'lib/eddy/models/interchange.rb', line 6 def store @store end |
#transaction_sets ⇒ Array<Eddy::Models::TransactionSet>
11 12 13 |
# File 'lib/eddy/models/interchange.rb', line 11 def transaction_sets @transaction_sets end |
Class Method Details
.create(_transaction_sets) ⇒ Eddy::Models::Interchange
23 24 25 26 |
# File 'lib/eddy/models/interchange.rb', line 23 def self.create(_transaction_sets) itch = Eddy::Models::Interchange.new() return itch end |
Instance Method Details
#functional_groups ⇒ Array<Eddy::Models::FunctionalGroup>
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/eddy/models/interchange.rb', line 41 def functional_groups() sorted_sets = {} self.transaction_sets.each do |ts| sorted_sets[ts.functional_group] ||= [] sorted_sets[ts.functional_group] << ts end i = 0 return sorted_sets.map do |_, value| i += 1 Eddy::Models::FunctionalGroup.new(self.store, i, *value) end end |
#render {|isa, iea| ... } ⇒ String
31 32 33 34 35 36 37 38 |
# File 'lib/eddy/models/interchange.rb', line 31 def render() f_groups = self.functional_groups() sep = self.store.segment_separator isa = Eddy::Segments::ISA.new(self.store, self.control_number) iea = Eddy::Segments::IEA.new(self.store, self.control_number, f_groups.length) yield(isa, iea) if block_given? return ([isa, f_groups, iea].flatten.map(&:render).join(sep) + sep).rstrip() end |