class Eddy::Models::TransactionSet
Base class for EDI Transaction Sets.
Constants
- FUNCTIONAL_GROUP
@return [String]
- ID
@return [Integer]
- NAME
@return [String]
- NumberOfIncludedSegments
- TransactionSetControlNumber
- TransactionSetIdentifierCode
Attributes
@return [Array<Segment, Loop>]
A unique control number for the Transaction Set. @return [Integer]
Container used to distribute state throughout an Interchange
. @return [Eddy::Data::Store]
Public Class Methods
@return [String]
# File lib/eddy/models/transaction_set.rb, line 48 def self.functional_group return self::FUNCTIONAL_GROUP end
@return [String]
# File lib/eddy/models/transaction_set.rb, line 38 def self.id return self::ID end
@return [String]
# File lib/eddy/models/transaction_set.rb, line 58 def self.name return self::NAME end
@param store [Eddy::Data::Store] @param components [Array<Segment, Loop>] @return [void]
# 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
Public Instance Methods
Add `ST` and `SE` segments to the `components` array.
@return [void]
# 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
Return all contained Segments
in a single, flattened array.
@return [Array<Eddy::Models::Segment>]
# 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
@return [String]
# File lib/eddy/models/transaction_set.rb, line 43 def functional_group return self.class::FUNCTIONAL_GROUP end
@return [String]
# File lib/eddy/models/transaction_set.rb, line 33 def id return self.class::ID end
@return [String]
# File lib/eddy/models/transaction_set.rb, line 53 def name return self.class::NAME end
Return the count of Segments
in the Transaction Set where `skip` is false, plus 2 for `ST` and `SE`.
@return [Integer]
# File lib/eddy/models/transaction_set.rb, line 92 def number_of_included_segments() return (self.all_components.reject(&:skip).length + 2) end
This shouldn't be used. An Interchange
or FunctionalGroup
should call `all_components` and render those itself.
@param s_sep [String] (self.store.segment_separator) @return [String]
# 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