Class: RBEDI::TransactionSet

Inherits:
Object
  • Object
show all
Includes:
Codes
Defined in:
lib/rbedi/transaction_set.rb

Constant Summary

Constants included from Codes

Codes::ELEMENT_SEPARATOR, Codes::INTERCHANGE_CONTROL_VERSION_NUMBER, Codes::SEGMENT_TERMINATOR, Codes::VERSION_CODE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction_set_control_number:, segments: [], transaction_set_identifier_code:) ⇒ TransactionSet

Returns a new instance of TransactionSet.



5
6
7
8
9
10
11
12
13
# File 'lib/rbedi/transaction_set.rb', line 5

def initialize(
  transaction_set_control_number:,
  segments: [],
  transaction_set_identifier_code:
)
  @transaction_set_control_number = "%04d" % transaction_set_control_number
  @transaction_set_identifier_code = transaction_set_identifier_code
  @segments = segments
end

Instance Attribute Details

#segmentsObject

Returns the value of attribute segments.



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

def segments
  @segments
end

#transaction_set_control_numberObject

Returns the value of attribute transaction_set_control_number.



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

def transaction_set_control_number
  @transaction_set_control_number
end

#transaction_set_identifier_codeObject

Returns the value of attribute transaction_set_identifier_code.



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

def transaction_set_identifier_code
  @transaction_set_identifier_code
end

Instance Method Details

#headerObject



21
22
23
24
25
26
27
28
# File 'lib/rbedi/transaction_set.rb', line 21

def header
  Segment.new(
    :transaction_set_header,
    transaction_set_identifier_code: @transaction_set_identifier_code,
    transaction_set_control_number: @transaction_set_control_number,
    implementation_convention_reference: Codes::VERSION_CODE
  )
end

#to_sObject



15
16
17
18
19
# File 'lib/rbedi/transaction_set.rb', line 15

def to_s
  header.to_s +
    @segments.map(&:to_s).join +
    trailer.to_s
end

#trailerObject



30
31
32
33
34
35
36
# File 'lib/rbedi/transaction_set.rb', line 30

def trailer
  Segment.new(
    :transaction_set_trailer,
    segments_count: @segments.length + 2,
    transaction_set_control_number: @transaction_set_control_number
  )
end