Class: Eddy::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:



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

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

Instance Attribute Details

#componentsArray<Segment, Loop>

Returns:



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

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.



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

def store
  @store
end

Class Method Details

.functional_groupString

Returns:

  • (String)


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

def self.functional_group
  return self::FUNCTIONAL_GROUP
end

.idString

Returns:

  • (String)


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

def self.id
  return self::ID
end

.nameString

Returns:

  • (String)


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

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())



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

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::Segment>

Return all contained Segments in a single, flattened array.

Returns:



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

def all_components()
  comps = self.components.map do |c|
    if c.is_a?(Eddy::Loop::Base)
      c.all_contents()
    elsif c.is_a?(Eddy::Segment)
      c
    else
      raise Eddy::Errors::RenderError
    end
  end
  return comps.flatten
end

#functional_groupString

Returns:

  • (String)


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

def functional_group
  return self.class::FUNCTIONAL_GROUP
end

#idString

Returns:

  • (String)


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

def id
  return self.class::ID
end

#nameString

Returns:

  • (String)


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

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)


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

def render(s_sep = self.store.segment_separator)
  add_envelope()
  return self.all_components.map { |s| s.render(self.store.element_separator) }.join(s_sep)
end