Class: Eddy::Models::Interchange

Inherits:
Object
  • Object
show all
Defined in:
lib/eddy/models/interchange.rb

Overview

Top level EDI interchange.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_numberInteger

A unique control number for the Interchange.



9
10
11
# File 'lib/eddy/models/interchange.rb', line 9

def control_number
  @control_number
end

#storeEddy::Data::Store



6
7
8
# File 'lib/eddy/models/interchange.rb', line 6

def store
  @store
end

#transaction_setsArray<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_groupsArray<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

Yield Parameters:



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