lib/eddy/models/transaction_set.rb in eddy-0.8.0 vs lib/eddy/models/transaction_set.rb in eddy-0.8.1
- old
+ new
@@ -10,20 +10,25 @@
# @return [String]
FUNCTIONAL_GROUP = nil
# @return [Array<Segment, Loop>]
attr_accessor :components
- # @return [Eddy::Data::Store] Container used to distribute state throughout an Interchange.
+ # Container used to distribute state throughout an Interchange.
+ # @return [Eddy::Data::Store]
attr_accessor :store
+ # A unique control number for the Transaction Set.
+ # @return [Integer]
+ attr_accessor :control_number
# @param store [Eddy::Data::Store]
# @param components [Array<Segment, Loop>]
# @return [void]
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
# @return [String]
def id
return self.class::ID
@@ -54,19 +59,18 @@
return self::NAME
end
# Add `ST` and `SE` segments to the `components` array.
#
- # @param control_number [Integer] (Eddy::Data.new_transaction_set_control_number())
# @return [void]
- def add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id))
+ def add_envelope()
st = Eddy::Segments::ST.new(self.store)
st.TransactionSetIdentifierCode = self.id
- st.TransactionSetControlNumber = control_number
+ st.TransactionSetControlNumber = self.control_number
se = Eddy::Segments::SE.new(self.store)
se.NumberOfIncludedSegments = self.all_components.length + 2
- se.TransactionSetControlNumber = control_number
+ se.TransactionSetControlNumber = self.control_number
self.components.unshift(st)
self.components.push(se)
end