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

components[RW]

@return [Array<Segment, Loop>]

control_number[RW]

A unique control number for the Transaction Set. @return [Integer]

store[RW]

Container used to distribute state throughout an Interchange. @return [Eddy::Data::Store]

Public Class Methods

functional_group() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 48
def self.functional_group
  return self::FUNCTIONAL_GROUP
end
id() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 38
def self.id
  return self::ID
end
name() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 58
def self.name
  return self::NAME
end
new(store, *components) click to toggle source

@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_envelope() click to toggle source

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
all_components() click to toggle source

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
functional_group() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 43
def functional_group
  return self.class::FUNCTIONAL_GROUP
end
id() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 33
def id
  return self.class::ID
end
name() click to toggle source

@return [String]

# File lib/eddy/models/transaction_set.rb, line 53
def name
  return self.class::NAME
end
number_of_included_segments() click to toggle source

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
render(s_sep = self.store.segment_separator) click to toggle source

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