lib/eddy/models/transaction_set.rb in eddy-0.8.1 vs lib/eddy/models/transaction_set.rb in eddy-0.8.2
- old
+ new
@@ -66,11 +66,11 @@
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.all_components.length + 2
+ se.NumberOfIncludedSegments = self.number_of_included_segments()
se.TransactionSetControlNumber = self.control_number
self.components.unshift(st)
self.components.push(se)
end
@@ -81,9 +81,17 @@
# @param s_sep [String] (self.store.segment_separator)
# @return [String]
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
+
+ # Return the count of Segments in the Transaction Set where `skip` is false,
+ # plus 2 for `ST` and `SE`.
+ #
+ # @return [Integer]
+ def number_of_included_segments()
+ return (self.all_components.reject(&:skip).length + 2)
end
# Return all contained Segments in a single, flattened array.
#
# @return [Array<Eddy::Models::Segment>]