Class: Eddy::Models::TransactionSet
- Inherits:
-
Object
- Object
- Eddy::Models::TransactionSet
show all
- Defined in:
- lib/eddy/models/transaction_set.rb
Overview
Base class for EDI Transaction Sets.
Constant Summary
collapse
- ID =
nil
- NAME =
nil
- FUNCTIONAL_GROUP =
nil
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(store, *components) ⇒ void
21
22
23
24
25
|
# File 'lib/eddy/models/transaction_set.rb', line 21
def initialize(store, *components)
self.store = store
components.flatten!
self.components = components || []
end
|
Instance Attribute Details
#components ⇒ Array<Segment, Loop>
14
15
16
|
# File 'lib/eddy/models/transaction_set.rb', line 14
def components
@components
end
|
Returns Container used to distribute state throughout an Interchange.
16
17
18
|
# File 'lib/eddy/models/transaction_set.rb', line 16
def store
@store
end
|
Class Method Details
.functional_group ⇒ String
43
44
45
|
# File 'lib/eddy/models/transaction_set.rb', line 43
def self.functional_group
return self::FUNCTIONAL_GROUP
end
|
.id ⇒ String
33
34
35
|
# File 'lib/eddy/models/transaction_set.rb', line 33
def self.id
return self::ID
end
|
.name ⇒ String
53
54
55
|
# File 'lib/eddy/models/transaction_set.rb', line 53
def self.name
return self::NAME
end
|
Instance Method Details
#add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id)) ⇒ void
This method returns an undefined value.
Add ST and SE segments to the components array.
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/eddy/models/transaction_set.rb', line 61
def add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id))
st = Eddy::Segments::ST.new(self.store)
st.TransactionSetIdentifierCode = self.id
st.TransactionSetControlNumber = control_number
se = Eddy::Segments::SE.new(self.store)
se.NumberOfIncludedSegments = self.all_components.length + 2
se.TransactionSetControlNumber = control_number
self.components.unshift(st)
self.components.push(se)
end
|
Return all contained Segments in a single, flattened array.
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/eddy/models/transaction_set.rb', line 87
def all_components()
comps = self.components.map do |c|
if c.is_a?(Eddy::Models::Loop::Base)
c.all_contents()
elsif c.is_a?(Eddy::Models::Segment)
c
else
raise Eddy::Errors::RenderError
end
end
return comps.flatten
end
|
#functional_group ⇒ String
38
39
40
|
# File 'lib/eddy/models/transaction_set.rb', line 38
def functional_group
return self.class::FUNCTIONAL_GROUP
end
|
#id ⇒ String
28
29
30
|
# File 'lib/eddy/models/transaction_set.rb', line 28
def id
return self.class::ID
end
|
#name ⇒ String
48
49
50
|
# File 'lib/eddy/models/transaction_set.rb', line 48
def name
return self.class::NAME
end
|
#render(s_sep = self.store.segment_separator) ⇒ String
This shouldn't be used.
An Interchange or FunctionalGroup should call all_components and render those itself.
79
80
81
82
|
# File 'lib/eddy/models/transaction_set.rb', line 79
def render(s_sep = self.store.segment_separator)
add_envelope()
return self.all_components.map { |s| s.render(self.store.element_separator) }.compact.join(s_sep)
end
|