Class: Eancom::Edifact::QTY

Inherits:
Segment
  • Object
show all
Defined in:
lib/eancom/edifact/segments/qty.rb

Constant Summary collapse

TAG =
'QTY'.freeze
TYPE =
:body.freeze

Instance Attribute Summary

Attributes inherited from Segment

#tag

Instance Method Summary collapse

Methods inherited from Segment

#array, initialize_by_components, #is_body?, #is_footer?, #is_header?, #item_group_name, #starts_item?, #starts_message?, #structure, #tag?, #to_edi, #to_hash, #to_s, #validate_structure

Constructor Details

#initialize(tag: nil, quantity_type_code_qualifier:, quantity:, measurement_unit_code: nil) ⇒ QTY

Returns a new instance of QTY.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/eancom/edifact/segments/qty.rb', line 7

def initialize(
  tag: nil,
  quantity_type_code_qualifier:,
  quantity:,
  measurement_unit_code: nil
)
  @tag = tag
  @quantity_type_code_qualifier = quantity_type_code_qualifier
  @quantity = quantity
  @measurement_unit_code = measurement_unit_code

  super(tag: tag || TAG)
end

Instance Method Details

#group_nameObject



29
30
31
# File 'lib/eancom/edifact/segments/qty.rb', line 29

def group_name
  'quantities'
end

#segment_typeObject



33
34
35
# File 'lib/eancom/edifact/segments/qty.rb', line 33

def segment_type
  TYPE
end

#to_json_hashObject



21
22
23
24
25
26
27
# File 'lib/eancom/edifact/segments/qty.rb', line 21

def to_json_hash
  hash = { identifier => {} }
  hash[identifier].merge!({ quantity: @quantity }) if @quantity
  hash.merge!(measurement_unit_code: find_identifier(:measurement_unit_code)) if @measurement_unit_code
  hash.merge!(identifier: @identifier) if @identifier
  hash
end