Class: DZero::Transmissions::Base

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Parser
Includes:
Concerns::SegmentsMethods, Concerns::Serializer
Defined in:
lib/dzero/transmissions/base.rb

Direct Known Subclasses

Request, Response

Constant Summary

Constants included from Concerns::SegmentsMethods

Concerns::SegmentsMethods::TRANSACTION_LEVEL_SEGMENTS, Concerns::SegmentsMethods::TRANSMISSION_LEVEL_SEGMENTS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Parser

parse

Methods included from Concerns::Serializer

#to_json

Methods included from Concerns::SegmentsMethods

#get_segment, included, #segments, #sort_segments

Constructor Details

#initialize(header: {}, transmission_group: Groups::TransmissionGroup.new, transaction_groups: [], segments: []) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dzero/transmissions/base.rb', line 18

def initialize(
  header: {},
  transmission_group: Groups::TransmissionGroup.new,
  transaction_groups: [],
  segments: []
)
  @header = header
  @transmission_group = transmission_group
  @transaction_groups = transaction_groups

  unless segments.empty?
    sort_segments(segments)
  end
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



33
34
35
# File 'lib/dzero/transmissions/base.rb', line 33

def header
  @header
end

#transaction_groupsObject (readonly)

Returns the value of attribute transaction_groups.



33
34
35
# File 'lib/dzero/transmissions/base.rb', line 33

def transaction_groups
  @transaction_groups
end

#transmission_groupObject (readonly)

Returns the value of attribute transmission_group.



33
34
35
# File 'lib/dzero/transmissions/base.rb', line 33

def transmission_group
  @transmission_group
end

Class Method Details

.header_schemaObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/dzero/transmissions/base.rb', line 13

def header_schema
  raise NotImplementedError
end

Instance Method Details

#to_sObject



35
36
37
38
39
40
41
# File 'lib/dzero/transmissions/base.rb', line 35

def to_s
  string = ::DZero::Utils::FixedWidth.to_fixed_width(header.slice(*self.class.header_schema.keys), self.class.header_schema)
  string += ::DZero::Constants::SEGMENT_SEPARATOR
  string += transmission_group.to_s
  string += transaction_groups.map(&:to_s).join
  string
end