Class: Eancom::Edifact::PIA

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

Constant Summary collapse

TAG =
'PIA'.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, product_identifier_code_qualifier:, item_identifier_1:, item_type_identification_code_1:, code_list_identification_code_1: nil, code_list_responsible_agency_code_1: nil, item_identifier_2: nil, item_type_identification_code_2: nil, code_list_identification_code_2: nil, code_list_responsible_agency_code_2: nil, item_identifier_3: nil, item_type_identification_code_3: nil, code_list_identification_code_3: nil, code_list_responsible_agency_code_3: nil, item_identifier_4: nil, item_type_identification_code_4: nil, code_list_identification_code_4: nil, code_list_responsible_agency_code_4: nil, item_identifier_5: nil, item_type_identification_code_5: nil, code_list_identification_code_5: nil, code_list_responsible_agency_code_5: nil) ⇒ PIA

Returns a new instance of PIA.



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/eancom/edifact/segments/pia.rb', line 7

def initialize(
  tag: nil,
  product_identifier_code_qualifier:,
  item_identifier_1:,
  item_type_identification_code_1:,
  code_list_identification_code_1: nil,
  code_list_responsible_agency_code_1: nil,
  item_identifier_2: nil,
  item_type_identification_code_2: nil,
  code_list_identification_code_2: nil,
  code_list_responsible_agency_code_2: nil,
  item_identifier_3: nil,
  item_type_identification_code_3: nil,
  code_list_identification_code_3: nil,
  code_list_responsible_agency_code_3: nil,
  item_identifier_4: nil,
  item_type_identification_code_4: nil,
  code_list_identification_code_4: nil,
  code_list_responsible_agency_code_4: nil,
  item_identifier_5: nil,
  item_type_identification_code_5: nil,
  code_list_identification_code_5: nil,
  code_list_responsible_agency_code_5: nil
)
  @tag = tag
  @product_identifier_code_qualifier = product_identifier_code_qualifier

  @item_identifier_1 = item_identifier_1
  @item_type_identification_code_1 = item_type_identification_code_1
  @code_list_identification_code_1 = code_list_identification_code_1
  @code_list_responsible_agency_code_1 = code_list_responsible_agency_code_1

  @item_identifier_2 = item_identifier_2
  @item_type_identification_code_2 = item_type_identification_code_2
  @code_list_identification_code_2 = code_list_identification_code_2
  @code_list_responsible_agency_code_2 = code_list_responsible_agency_code_2

  @item_identifier_3 = item_identifier_3
  @item_type_identification_code_3 = item_type_identification_code_3
  @code_list_identification_code_3 = code_list_identification_code_3
  @code_list_responsible_agency_code_3 = code_list_responsible_agency_code_3

  @item_identifier_4 = item_identifier_4
  @item_type_identification_code_4 = item_type_identification_code_4
  @code_list_identification_code_4 = code_list_identification_code_4
  @code_list_responsible_agency_code_4 = code_list_responsible_agency_code_4

  @item_identifier_5 = item_identifier_5
  @item_type_identification_code_5 = item_type_identification_code_5
  @code_list_identification_code_5 = code_list_identification_code_5
  @code_list_responsible_agency_code_5 = code_list_responsible_agency_code_5

  super(tag: tag || TAG)
end

Instance Method Details

#group_nameObject



91
92
93
# File 'lib/eancom/edifact/segments/pia.rb', line 91

def group_name
  'additional_product_id'
end

#segment_typeObject



95
96
97
# File 'lib/eancom/edifact/segments/pia.rb', line 95

def segment_type
  TYPE
end

#to_json_hashObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/eancom/edifact/segments/pia.rb', line 62

def to_json_hash
  hash = {}
  hash.merge!(product_identifier_code_qualifier: find_identifier(:product_identifier_code_qualifier)) if @product_identifier_code_qualifier
  hash.merge!(item_identifier_1: @item_identifier_1) if @item_identifier_1
  hash.merge!(item_type_identification_code_1: find_identifier(:item_type_identification_code_1)) if @item_type_identification_code_1
  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_identifier_2: @item_identifier_2) if @item_identifier_2
  hash.merge!(item_type_identification_code_2: find_identifier(:item_type_identification_code_2)) if @item_type_identification_code_2
  hash.merge!(code_list_identification_code_2: @code_list_identification_code_2) if @code_list_identification_code_2
  hash.merge!(code_list_responsible_agency_code_2: find_identifier(:code_list_responsible_agency_code_2)) if @code_list_responsible_agency_code_2
  hash.merge!(item_identifier_3: @item_identifier_3) if @item_identifier_3
  hash.merge!(item_type_identification_code_3: find_identifier(:item_type_identification_code_3)) if @item_type_identification_code_3
  hash.merge!(code_list_identification_code_3: @code_list_identification_code_3) if @code_list_identification_code_3
  hash.merge!(code_list_responsible_agency_code_3: find_identifier(:code_list_responsible_agency_code_3)) if @code_list_responsible_agency_code_3
  hash.merge!(item_identifier_4: @item_identifier_4) if @item_identifier_4
  hash.merge!(item_type_identification_code_4: find_identifier(:item_type_identification_code_4)) if @item_type_identification_code_4
  hash.merge!(code_list_identification_code_4: @code_list_identification_code_4) if @code_list_identification_code_4
  hash.merge!(code_list_responsible_agency_code_4: find_identifier(:code_list_responsible_agency_code_4)) if @code_list_responsible_agency_code_4
  hash.merge!(item_identifier_5: @item_identifier_5) if @item_identifier_5
  hash.merge!(item_type_identification_code_5: find_identifier(:item_type_identification_code_5)) if @item_type_identification_code_5
  hash.merge!(code_list_identification_code_5: @code_list_identification_code_5) if @code_list_identification_code_5
  hash.merge!(code_list_responsible_agency_code_5: find_identifier(:code_list_responsible_agency_code_5)) if @code_list_responsible_agency_code_5

  outer_hash = {}
  outer_hash[find_identifier(:product_identifier_code_qualifier)] = hash
  outer_hash
end