Class: Eancom::Edifact::IMD

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

Constant Summary collapse

TAG =
'IMD'.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_location?, #starts_message?, #structure, #tag?, #to_edi, #to_hash, #to_s, #validate_structure

Constructor Details

#initialize(tag: nil, description_format_code:, item_characteristic_code: nil, code_list_identification_code: nil, code_list_responsible_agency_code: nil, item_description_code: nil, code_list_identification_code_1: '', code_list_responsible_agency_code_1: nil, item_description_1: nil, item_description_2: nil, language_name_code: nil, surface_or_layer_code: nil) ⇒ IMD

Returns a new instance of IMD.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eancom/edifact/segments/imd.rb', line 7

def initialize(
  tag: nil,
  description_format_code:,
  item_characteristic_code: nil,
  code_list_identification_code: nil,
  code_list_responsible_agency_code: nil,
  item_description_code: nil,
  code_list_identification_code_1: '',
  code_list_responsible_agency_code_1: nil,
  item_description_1: nil,
  item_description_2: nil,
  language_name_code: nil,
  surface_or_layer_code: nil
)
  @tag = tag
  @description_format_code = description_format_code
  @item_characteristic_code = item_characteristic_code
  @code_list_identification_code = code_list_identification_code
  @code_list_responsible_agency_code = code_list_responsible_agency_code
  @item_description_code = item_description_code
  @code_list_identification_code_1 = code_list_identification_code_1
  @code_list_responsible_agency_code_1 = code_list_responsible_agency_code_1
  @item_description_1 = item_description_1
  @item_description_2 = item_description_2
  @language_name_code = language_name_code
  @surface_or_layer_code = surface_or_layer_code

  super(tag: tag || TAG)
end

Instance Method Details

#group_nameObject



60
61
62
# File 'lib/eancom/edifact/segments/imd.rb', line 60

def group_name
  'item_descriptions'
end

#segment_typeObject



64
65
66
# File 'lib/eancom/edifact/segments/imd.rb', line 64

def segment_type
  TYPE
end

#to_json_hashObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/eancom/edifact/segments/imd.rb', line 37

def to_json_hash
  hash = {}
  hash.merge!(description_format_code: find_identifier(:description_format_code)) if @description_format_code
  hash.merge!(item_characteristic_code: find_identifier(:item_characteristic_code)) if @item_characteristic_code
  hash.merge!(code_list_identification_code: @code_list_identification_code) if @code_list_identification_code
  hash.merge!(code_list_responsible_agency_code: find_identifier(:code_list_responsible_agency_code)) if @code_list_responsible_agency_code
  if @item_description_code
    identifier = find_identifier(:item_description_code)
    if identifier
      hash.merge!(item_description_code: identifier)
    else
      hash.merge!(item_description_code: @item_description_code)
    end
  end
  hash.merge!(code_list_identification_code_1: @code_list_identification_code_1) if @code_list_identification_code_1
  hash.merge!(code_list_responsible_agency_code_1: find_identifier(:code_list_responsible_agency_code_1)) if @code_list_responsible_agency_code_1
  hash.merge!(item_description_1: @item_description_1) if @item_description_1
  hash.merge!(item_description_2: @item_description_2) if @item_description_2
  hash.merge!(language_name_code: @language_name_code) if @language_name_code
  hash.merge!(surface_or_layer_code: @surface_or_layer_code) if @surface_or_layer_code
  hash
end