Class: Eddy::Models::TransactionSet
- Inherits:
-
Object
- Object
- Eddy::Models::TransactionSet
- Defined in:
- lib/eddy/models/transaction_set.rb
Overview
Base class for EDI Transaction Sets.
Direct Known Subclasses
TransactionSets::TS810::TS, TransactionSets::TS846::TS846, TransactionSets::TS850::TS850, TransactionSets::TS855::TS, TransactionSets::TS856::TS
Constant Summary collapse
- ID =
nil
- NAME =
nil
- FUNCTIONAL_GROUP =
nil
Instance Attribute Summary collapse
- #components ⇒ Array<Segment, Loop>
-
#control_number ⇒ Integer
A unique control number for the Transaction Set.
-
#store ⇒ Eddy::Data::Store
Container used to distribute state throughout an Interchange.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_envelope ⇒ void
Add
ST
andSE
segments to thecomponents
array. -
#all_components ⇒ Array<Eddy::Models::Segment>
Return all contained Segments in a single, flattened array.
- #functional_group ⇒ String
- #id ⇒ String
- #initialize(store, *components) ⇒ void constructor
- #name ⇒ String
-
#number_of_included_segments ⇒ Integer
Return the count of Segments in the Transaction Set where
skip
is false, plus 2 forST
andSE
. -
#render(s_sep = self.store.segment_separator) ⇒ String
This shouldn't be used.
Constructor Details
#initialize(store, *components) ⇒ void
25 26 27 28 29 30 |
# File 'lib/eddy/models/transaction_set.rb', line 25 def initialize(store, *components) self.store = store components.flatten! self.components = components || [] self.control_number = Eddy::Data.new_transaction_set_control_number(self.id) end |
Instance Attribute Details
#components ⇒ Array<Segment, Loop>
14 15 16 |
# File 'lib/eddy/models/transaction_set.rb', line 14 def components @components end |
#control_number ⇒ Integer
A unique control number for the Transaction Set.
20 21 22 |
# File 'lib/eddy/models/transaction_set.rb', line 20 def control_number @control_number end |
#store ⇒ Eddy::Data::Store
Container used to distribute state throughout an Interchange.
17 18 19 |
# File 'lib/eddy/models/transaction_set.rb', line 17 def store @store end |
Class Method Details
.functional_group ⇒ String
48 49 50 |
# File 'lib/eddy/models/transaction_set.rb', line 48 def self.functional_group return self::FUNCTIONAL_GROUP end |
.id ⇒ String
38 39 40 |
# File 'lib/eddy/models/transaction_set.rb', line 38 def self.id return self::ID end |
.name ⇒ String
58 59 60 |
# File 'lib/eddy/models/transaction_set.rb', line 58 def self.name return self::NAME end |
Instance Method Details
#add_envelope ⇒ void
This method returns an undefined value.
Add ST
and SE
segments to the components
array.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/eddy/models/transaction_set.rb', line 65 def add_envelope() st = Eddy::Segments::ST.new(self.store) st.TransactionSetIdentifierCode = self.id st.TransactionSetControlNumber = self.control_number se = Eddy::Segments::SE.new(self.store) se.NumberOfIncludedSegments = self.number_of_included_segments() se.TransactionSetControlNumber = self.control_number self.components.unshift(st) self.components.push(se) end |
#all_components ⇒ Array<Eddy::Models::Segment>
Return all contained Segments in a single, flattened array.
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/eddy/models/transaction_set.rb', line 99 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
43 44 45 |
# File 'lib/eddy/models/transaction_set.rb', line 43 def functional_group return self.class::FUNCTIONAL_GROUP end |
#id ⇒ String
33 34 35 |
# File 'lib/eddy/models/transaction_set.rb', line 33 def id return self.class::ID end |
#name ⇒ String
53 54 55 |
# File 'lib/eddy/models/transaction_set.rb', line 53 def name return self.class::NAME end |
#number_of_included_segments ⇒ Integer
Return the count of Segments in the Transaction Set where skip
is false,
plus 2 for ST
and SE
.
92 93 94 |
# File 'lib/eddy/models/transaction_set.rb', line 92 def number_of_included_segments() return (self.all_components.reject(&:skip).length + 2) 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.
83 84 85 86 |
# File 'lib/eddy/models/transaction_set.rb', line 83 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).rstrip() end |