Class: Eddy::Models::TransactionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/eddy/models/transaction_set.rb

Overview

Base class for EDI Transaction Sets.

Constant Summary collapse

ID =

Returns:

  • (Integer)
nil
NAME =

Returns:

  • (String)
nil
FUNCTIONAL_GROUP =

Returns:

  • (String)
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, *components) ⇒ void

Parameters:



21
22
23
24
25
# File 'lib/eddy/models/transaction_set.rb', line 21

def initialize(store, *components)
  self.store = store
  components.flatten!
  self.components = components || []
end

Instance Attribute Details

#componentsArray<Segment, Loop>

Returns:



14
15
16
# File 'lib/eddy/models/transaction_set.rb', line 14

def components
  @components
end

#storeEddy::Data::Store

Returns Container used to distribute state throughout an Interchange.

Returns:

  • (Eddy::Data::Store)

    Container used to distribute state throughout an Interchange.



16
17
18
# File 'lib/eddy/models/transaction_set.rb', line 16

def store
  @store
end

Class Method Details

.functional_groupString

Returns:

  • (String)


43
44
45
# File 'lib/eddy/models/transaction_set.rb', line 43

def self.functional_group
  return self::FUNCTIONAL_GROUP
end

.idString

Returns:

  • (String)


33
34
35
# File 'lib/eddy/models/transaction_set.rb', line 33

def self.id
  return self::ID
end

.nameString

Returns:

  • (String)


53
54
55
# File 'lib/eddy/models/transaction_set.rb', line 53

def self.name
  return self::NAME
end

Instance Method Details

#add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id)) ⇒ void

This method returns an undefined value.

Add ST and SE segments to the components array.

Parameters:

  • control_number (Integer) (defaults to: Eddy::Data.new_transaction_set_control_number(self.id))

    (Eddy::Data.new_transaction_set_control_number())



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/eddy/models/transaction_set.rb', line 61

def add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id))
  st = Eddy::Segments::ST.new(self.store)
  st.TransactionSetIdentifierCode = self.id
  st.TransactionSetControlNumber  = control_number

  se = Eddy::Segments::SE.new(self.store)
  se.NumberOfIncludedSegments    = self.all_components.length + 2
  se.TransactionSetControlNumber = control_number

  self.components.unshift(st)
  self.components.push(se)
end

#all_componentsArray<Eddy::Models::Segment>

Return all contained Segments in a single, flattened array.

Returns:



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/eddy/models/transaction_set.rb', line 87

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_groupString

Returns:

  • (String)


38
39
40
# File 'lib/eddy/models/transaction_set.rb', line 38

def functional_group
  return self.class::FUNCTIONAL_GROUP
end

#idString

Returns:

  • (String)


28
29
30
# File 'lib/eddy/models/transaction_set.rb', line 28

def id
  return self.class::ID
end

#nameString

Returns:

  • (String)


48
49
50
# File 'lib/eddy/models/transaction_set.rb', line 48

def name
  return self.class::NAME
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.

Parameters:

  • s_sep (String) (defaults to: self.store.segment_separator)

    (self.store.segment_separator)

Returns:

  • (String)


79
80
81
82
# File 'lib/eddy/models/transaction_set.rb', line 79

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