eancom 1.6.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -4
- data/.gitlab-ci.yml +11 -13
- data/.ruby-version +1 -1
- data/Gemfile +2 -4
- data/Gemfile.lock +21 -103
- data/README.md +46 -0
- data/definitions/desadv/d01b.rb +134 -87
- data/definitions/desadv/d96a.rb +145 -82
- data/definitions/invoic/d01b.rb +559 -0
- data/definitions/invoic/d96a.rb +389 -0
- data/definitions/invrpt/d01b.rb +134 -0
- data/definitions/invrpt/d96a.rb +125 -0
- data/definitions/orders/d01b.rb +182 -0
- data/definitions/orders/d96b.rb +198 -0
- data/definitions/ordrsp/d01b.rb +251 -0
- data/definitions/ordrsp/d96b.rb +226 -0
- data/definitions/pricat/d01b.rb +225 -0
- data/definitions/pricat/d96b.rb +207 -0
- data/definitions/retann/d01b.rb +172 -0
- data/definitions/retann/d96b.rb +221 -0
- data/definitions/segments/ajt.rb +47 -0
- data/definitions/segments/alc.rb +128 -36
- data/definitions/segments/bgm.rb +122 -2
- data/definitions/segments/cdi.rb +39 -0
- data/definitions/segments/cnt.rb +4 -0
- data/definitions/segments/cta.rb +89 -0
- data/definitions/segments/cux.rb +9 -2
- data/definitions/segments/dgs.rb +34 -0
- data/definitions/segments/doc.rb +45 -0
- data/definitions/segments/dtm.rb +75 -20
- data/definitions/segments/efi.rb +67 -0
- data/definitions/segments/eqd.rb +37 -0
- data/definitions/segments/ftx.rb +22 -8
- data/definitions/segments/gin.rb +113 -0
- data/definitions/segments/imd.rb +9 -13
- data/definitions/segments/inv.rb +94 -0
- data/definitions/segments/lin.rb +24 -4
- data/definitions/segments/loc.rb +52 -4
- data/definitions/segments/moa.rb +86 -2
- data/definitions/segments/nad.rb +69 -9
- data/definitions/segments/pac.rb +12 -0
- data/definitions/segments/pat.rb +171 -0
- data/definitions/segments/pcd.rb +9 -92
- data/definitions/segments/pci.rb +110 -0
- data/definitions/segments/pgi.rb +7 -3
- data/definitions/segments/pia.rb +21 -29
- data/definitions/segments/pri.rb +25 -13
- data/definitions/segments/qty.rb +208 -2
- data/definitions/segments/rff.rb +49 -13
- data/definitions/segments/rte.rb +52 -0
- data/definitions/segments/tax.rb +17 -10
- data/definitions/segments/tdt.rb +24 -0
- data/definitions/segments/tod.rb +64 -0
- data/definitions/segments/tru.rb +34 -0
- data/definitions/segments/una.rb +8 -8
- data/definitions/segments/unb.rb +4 -4
- data/definitions/segments/unh.rb +70 -5
- data/definitions/segments/uns.rb +2 -2
- data/definitions/segments/unt.rb +2 -2
- data/definitions/slsrpt/d01b.rb +132 -128
- data/definitions/slsrpt/d96a.rb +132 -129
- data/eancom.gemspec +5 -8
- data/lib/eancom/edifact/body.rb +37 -18
- data/lib/eancom/edifact/document.rb +20 -16
- data/lib/eancom/edifact/footer.rb +1 -0
- data/lib/eancom/edifact/item.rb +1 -1
- data/lib/eancom/edifact/message.rb +7 -39
- data/lib/eancom/edifact/segment.rb +9 -11
- data/lib/eancom/edifact/segments/ajt.rb +32 -0
- data/lib/eancom/edifact/segments/ali.rb +2 -4
- data/lib/eancom/edifact/segments/bgm.rb +4 -3
- data/lib/eancom/edifact/segments/cdi.rb +30 -0
- data/lib/eancom/edifact/segments/cnt.rb +8 -1
- data/lib/eancom/edifact/segments/cps.rb +4 -1
- data/lib/eancom/edifact/segments/cta.rb +30 -0
- data/lib/eancom/edifact/segments/cux.rb +1 -1
- data/lib/eancom/edifact/segments/dgs.rb +31 -0
- data/lib/eancom/edifact/segments/doc.rb +30 -0
- data/lib/eancom/edifact/segments/dtm.rb +10 -6
- data/lib/eancom/edifact/segments/efi.rb +38 -0
- data/lib/eancom/edifact/segments/eqd.rb +30 -0
- data/lib/eancom/edifact/segments/ftx.rb +2 -2
- data/lib/eancom/edifact/segments/gin.rb +45 -0
- data/lib/eancom/edifact/segments/imd.rb +1 -1
- data/lib/eancom/edifact/segments/inv.rb +43 -0
- data/lib/eancom/edifact/segments/lin.rb +7 -4
- data/lib/eancom/edifact/segments/loc.rb +8 -9
- data/lib/eancom/edifact/segments/mea.rb +1 -0
- data/lib/eancom/edifact/segments/moa.rb +3 -3
- data/lib/eancom/edifact/segments/nad.rb +11 -6
- data/lib/eancom/edifact/segments/pac.rb +3 -1
- data/lib/eancom/edifact/segments/pat.rb +37 -0
- data/lib/eancom/edifact/segments/pcd.rb +6 -17
- data/lib/eancom/edifact/segments/pci.rb +40 -0
- data/lib/eancom/edifact/segments/pia.rb +1 -0
- data/lib/eancom/edifact/segments/pri.rb +0 -1
- data/lib/eancom/edifact/segments/qty.rb +9 -5
- data/lib/eancom/edifact/segments/rff.rb +8 -2
- data/lib/eancom/edifact/segments/rte.rb +33 -0
- data/lib/eancom/edifact/segments/tax.rb +7 -1
- data/lib/eancom/edifact/segments/tdt.rb +4 -1
- data/lib/eancom/edifact/segments/tod.rb +33 -0
- data/lib/eancom/edifact/segments/tru.rb +31 -0
- data/lib/eancom/edifact/segments/una.rb +2 -1
- data/lib/eancom/edifact/segments/unb.rb +4 -5
- data/lib/eancom/edifact/segments/unh.rb +6 -4
- data/lib/eancom/edifact/segments/uns.rb +4 -1
- data/lib/eancom/edifact/structure.rb +0 -1
- data/lib/eancom/edifact.rb +15 -4
- data/lib/eancom/factory.rb +1 -1
- data/lib/eancom/parser/document.rb +3 -16
- data/lib/eancom/parser/segment.rb +9 -10
- data/lib/eancom/version.rb +1 -3
- data/lib/eancom.rb +3 -1
- data/pricat.json +1 -0
- metadata +45 -51
- data/.rubocop.yml +0 -2
- data/.tool-versions +0 -1
- data/definitions/segments/qvr.rb +0 -140
- data/lib/eancom/edifact/location.rb +0 -56
- data/lib/eancom/edifact/segments/qvr.rb +0 -50
data/definitions/slsrpt/d96a.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
Eancom::Definition.create(name: 'D96A', type: :slsrpt) do |document, config|
|
2
|
+
# Creates a template for an slsrpt d01b formatted edifact document
|
2
3
|
document.header do |header|
|
3
|
-
header.segment Eancom::Edifact::UNA.new
|
4
|
+
header.segment Eancom::Edifact::UNA.new
|
4
5
|
|
5
6
|
header.segment Eancom::Edifact::UNB.new(
|
6
|
-
syntax_identifier:
|
7
|
-
syntax_version_number:
|
7
|
+
syntax_identifier: 'UNOA',
|
8
|
+
syntax_version_number: '2',
|
8
9
|
interchange_sender_identification: config.header.interchange_sender_identification,
|
9
|
-
sender_identifiction_code_qualifier:
|
10
|
+
sender_identifiction_code_qualifier: '14',
|
10
11
|
interchange_recipient_identification: config.header.interchange_recipient_identification,
|
11
|
-
recipient_identifiction_code_qualifier:
|
12
|
+
recipient_identifiction_code_qualifier: '14',
|
12
13
|
date: config.header.date,
|
13
14
|
time: config.header.time,
|
14
|
-
interchange_control_reference: config.header.interchange_control_reference
|
15
|
+
interchange_control_reference: config.header.interchange_control_reference
|
15
16
|
)
|
16
17
|
|
17
18
|
header.segment Eancom::Edifact::UNH.new(
|
@@ -25,172 +26,174 @@ Eancom::Definition.create(name: 'D96A', type: :slsrpt) do |document, config|
|
|
25
26
|
end
|
26
27
|
|
27
28
|
document.body do |body|
|
28
|
-
|
29
29
|
# Messages
|
30
30
|
messages = config.body.messages
|
31
31
|
|
32
32
|
messages.each do |message|
|
33
|
-
|
34
33
|
body.segment Eancom::Edifact::BGM.new(
|
35
|
-
document_name_code:
|
36
|
-
document_identifier: message.document_identifier
|
34
|
+
document_name_code: message.document_name_code,
|
35
|
+
document_identifier: message.document_identifier
|
37
36
|
)
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
)
|
45
|
-
|
46
|
-
# Report Start Date
|
47
|
-
if date_time = message.report_start_date.date_time
|
38
|
+
date_time_messages = message.date_time_messages
|
39
|
+
date_time_messages.each_with_index do |dtm, index|
|
40
|
+
next unless index == 0
|
41
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
42
|
+
key = dtm.identifier.intern.to_sym
|
48
43
|
body.segment Eancom::Edifact::DTM.new(
|
49
|
-
type:
|
50
|
-
date_time: date_time,
|
44
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
45
|
+
date_time: dtm[key].date_time,
|
51
46
|
format: '102'
|
52
47
|
)
|
53
48
|
end
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
date_time_messages.each_with_index do |dtm, index|
|
51
|
+
next unless index == 1
|
52
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
53
|
+
key = dtm.identifier.intern.to_sym
|
54
|
+
body.segment Eancom::Edifact::DTM.new(
|
55
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
56
|
+
date_time: dtm[key].date_time,
|
57
|
+
format: '102'
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
date_time_messages.each_with_index do |dtm, index|
|
62
|
+
next unless index == 2
|
63
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
64
|
+
key = dtm.identifier.intern.to_sym
|
65
|
+
body.segment Eancom::Edifact::DTM.new(
|
66
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
67
|
+
date_time: dtm[key].date_time,
|
68
|
+
format: '102'
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
63
72
|
|
64
73
|
# Supplier
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
)
|
72
|
-
else
|
73
|
-
'9'
|
74
|
-
end
|
74
|
+
nads = message.nads
|
75
|
+
nads.each_with_index do |nad, index|
|
76
|
+
next unless index == 0
|
77
|
+
|
78
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
79
|
+
key = nad.identifier.intern.to_sym
|
75
80
|
body.segment Eancom::Edifact::NAD.new(
|
76
|
-
party_function_code_qualifier:
|
77
|
-
party_identifier:
|
78
|
-
|
81
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
82
|
+
party_identifier: nad[key].party_identifier,
|
83
|
+
code_list_responsible_agency_code_1: '9'
|
79
84
|
)
|
80
85
|
end
|
81
86
|
|
82
87
|
# Buyer
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
supplier.code_list_responsible_agancy_code_1
|
89
|
-
)
|
90
|
-
else
|
91
|
-
'9'
|
92
|
-
end
|
88
|
+
nads.each_with_index do |nad, index|
|
89
|
+
next unless index == 1
|
90
|
+
|
91
|
+
structure = Eancom.find_structure(tag: 'NAD')
|
92
|
+
key = nad.identifier.intern.to_sym
|
93
93
|
body.segment Eancom::Edifact::NAD.new(
|
94
|
-
party_function_code_qualifier:
|
95
|
-
party_identifier:
|
96
|
-
|
94
|
+
party_function_code_qualifier: structure.dictionary_lookup(:party_function_code_qualifier, nad.identifier),
|
95
|
+
party_identifier: nad[key].party_identifier,
|
96
|
+
code_list_responsible_agency_code_1: '9'
|
97
97
|
)
|
98
98
|
end
|
99
99
|
|
100
100
|
# Reference Currency
|
101
101
|
if currency = message.currency
|
102
|
+
structure = Eancom.find_structure(tag: 'CUX')
|
102
103
|
body.segment Eancom::Edifact::CUX.new(
|
103
104
|
currency_identification_code_1: currency.currency_identification_code_1,
|
104
|
-
currency_type_code_qualifier_1:
|
105
|
-
|
105
|
+
currency_type_code_qualifier_1: structure.dictionary_lookup(:currency_type_code_qualifier_1,
|
106
|
+
currency.currency_type_code_qualifier_1),
|
107
|
+
currency_usage_code_qualifier_1: structure.dictionary_lookup(:currency_usage_code_qualifier_1, currency.currency_usage_code_qualifier_1)
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Location
|
112
|
+
if location = message.location
|
113
|
+
structure = Eancom.find_structure(tag: 'LOC')
|
114
|
+
body.segment Eancom::Edifact::LOC.new(
|
115
|
+
code_list_identification_code: location.code_list_identification_code,
|
116
|
+
code_list_responsible_agency_code: structure.dictionary_lookup(:code_list_responsible_agency_code, location.code_list_responsible_agency_code),
|
117
|
+
location_function_qualifier: structure.dictionary_lookup(:location_function_qualifier, location.location_function_qualifier),
|
118
|
+
location_name_code: location.location_name_code
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
date_time_messages.each_with_index do |dtm, index|
|
123
|
+
next unless index == 3
|
124
|
+
structure = Eancom.find_structure(tag: 'DTM')
|
125
|
+
key = dtm.identifier.intern.to_sym
|
126
|
+
body.segment Eancom::Edifact::DTM.new(
|
127
|
+
type: structure.dictionary_lookup(:type, dtm.identifier),
|
128
|
+
date_time: dtm[key].date_time,
|
129
|
+
format: '203'
|
106
130
|
)
|
107
131
|
end
|
108
132
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
133
|
+
# Items
|
134
|
+
total_quantity = 0
|
135
|
+
|
136
|
+
items = message.items
|
137
|
+
|
138
|
+
items.each_with_index do |item, index|
|
139
|
+
total_quantity += item.quantity.to_i
|
140
|
+
|
141
|
+
structure = Eancom.find_structure(tag: 'LIN')
|
142
|
+
body.segment Eancom::Edifact::LIN.new(
|
143
|
+
line_item_identifier_1: (index + 1).to_s,
|
144
|
+
item_identifier: item.ean,
|
145
|
+
item_type_identification_code: structure.dictionary_lookup(:item_type_identification_code, item.item_type_identification_code)
|
146
|
+
)
|
147
|
+
|
148
|
+
references = item.references
|
149
|
+
references.each_with_index do |rff, index|
|
150
|
+
structure = Eancom.find_structure(tag: 'RFF')
|
151
|
+
key = rff.identifier.intern.to_sym
|
152
|
+
body.segment Eancom::Edifact::RFF.new(
|
153
|
+
reference_code_qualifier: structure.dictionary_lookup(:reference_code_qualifier, rff.identifier),
|
154
|
+
reference_identifier: rff[key].reference_identifier
|
129
155
|
)
|
130
156
|
end
|
131
157
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
158
|
+
prices = item.prices
|
159
|
+
prices.each do |price|
|
160
|
+
next unless price = price.price
|
161
|
+
|
162
|
+
structure = Eancom.find_structure(tag: 'PRI')
|
163
|
+
body.segment Eancom::Edifact::PRI.new(
|
164
|
+
price_amount: price.price_amount,
|
165
|
+
price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
|
166
|
+
price_specification_code: structure.dictionary_lookup(:price_specification_code,
|
167
|
+
price.price_specification_code),
|
168
|
+
price_type_code: price.price_type_code
|
138
169
|
)
|
139
170
|
end
|
140
171
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
body.segment Eancom::Edifact::
|
146
|
-
|
147
|
-
|
148
|
-
|
172
|
+
qty = item.quantities
|
173
|
+
qty.each_with_index do |qty, index|
|
174
|
+
structure = Eancom.find_structure(tag: 'QTY')
|
175
|
+
key = qty.identifier.intern.to_sym
|
176
|
+
body.segment Eancom::Edifact::QTY.new(
|
177
|
+
quantity_type_code_qualifier: structure.dictionary_lookup(:quantity_type_code_qualifier, qty.identifier),
|
178
|
+
quantity: qty[key].quantity,
|
179
|
+
measurement_unit_code: structure.dictionary_lookup(:measurement_unit_code, qty.measurement_unit_code)
|
149
180
|
)
|
150
|
-
|
151
|
-
if transaction_reference_number = item.transaction_reference_number
|
152
|
-
body.segment Eancom::Edifact::RFF.new(
|
153
|
-
reference_code_qualifier: 'TN',
|
154
|
-
reference_identifier: transaction_reference_number.reference_identifier
|
155
|
-
)
|
156
|
-
end
|
157
|
-
|
158
|
-
prices = item.prices
|
159
|
-
prices.each do |price|
|
160
|
-
if price = price.price
|
161
|
-
structure = Eancom.find_structure(tag: 'PRI')
|
162
|
-
body.segment Eancom::Edifact::PRI.new(
|
163
|
-
price_amount: price.price_amount,
|
164
|
-
price_code_qualifier: structure.dictionary_lookup(:price_code_qualifier, price.price_code_qualifier),
|
165
|
-
price_specification_code: structure.dictionary_lookup(:price_specification_code, price.price_specification_code),
|
166
|
-
price_type_code: price.price_type_code
|
167
|
-
)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# Quantity
|
172
|
-
if minimum_production_batch = item.minimum_production_batch
|
173
|
-
body.segment Eancom::Edifact::QTY.new(
|
174
|
-
quantity_type_code_qualifier: '160',
|
175
|
-
quantity: minimum_production_batch.quantity,
|
176
|
-
measurement_unit_code: 'PCE'
|
177
|
-
)
|
178
|
-
end
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
182
|
-
|
183
184
|
body.segment Eancom::Edifact::UNT.new(
|
184
|
-
number_of_segments_in_message:
|
185
|
-
message_reference_number: config.header.message_reference_number
|
185
|
+
number_of_segments_in_message: (document.total_segments + 2).to_s,
|
186
|
+
message_reference_number: config.header.message_reference_number
|
186
187
|
)
|
187
188
|
end
|
189
|
+
end
|
188
190
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
191
|
+
document.footer do |footer|
|
192
|
+
messages = config.body.messages
|
193
|
+
|
194
|
+
footer.segment Eancom::Edifact::UNZ.new(
|
195
|
+
interchange_control_count: messages.size.to_s,
|
196
|
+
interchange_control_reference: config.header.interchange_control_reference.to_s
|
197
|
+
)
|
195
198
|
end
|
196
199
|
end
|
data/eancom.gemspec
CHANGED
@@ -23,12 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency 'rubocop'
|
32
|
-
spec.add_development_dependency 'simplecov'
|
33
|
-
spec.add_development_dependency 'timecop'
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "pry-remote"
|
28
|
+
spec.add_development_dependency "pry-nav"
|
29
|
+
spec.add_development_dependency "simplecov"
|
30
|
+
spec.add_development_dependency "timecop"
|
34
31
|
end
|
data/lib/eancom/edifact/body.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Eancom
|
4
2
|
module Edifact
|
5
3
|
class Body < DocumentElement
|
6
|
-
|
4
|
+
|
5
|
+
attr_accessor :hash, :items, :messages
|
7
6
|
|
8
7
|
def initialize
|
9
8
|
super
|
@@ -12,32 +11,52 @@ module Eancom
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def to_json_hash
|
15
|
-
@
|
14
|
+
@segments.each do |segment|
|
15
|
+
start_message(segment) if segment.starts_message?
|
16
|
+
start_item(segment) if segment.starts_item?
|
17
|
+
if @item
|
18
|
+
@item << segment
|
19
|
+
else
|
20
|
+
@message << segment
|
21
|
+
end
|
22
|
+
end
|
23
|
+
@message.add_item(@item.to_json_hash)
|
24
|
+
@messages << @message.to_json_hash
|
25
|
+
hash.merge!({ messages: messages })
|
26
|
+
{ body: hash }
|
16
27
|
end
|
17
28
|
|
18
|
-
def start_message
|
29
|
+
def start_message(segment)
|
19
30
|
if @message
|
20
31
|
@messages << @message.to_json_hash
|
32
|
+
if @item && !@item.empty?
|
33
|
+
@message.add_item(@item.to_json_hash)
|
34
|
+
end
|
35
|
+
@item = nil
|
21
36
|
end
|
22
|
-
@message = Eancom::Edifact::Message.new
|
37
|
+
@message = Eancom::Edifact::Message.new()
|
23
38
|
end
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
40
|
+
def start_item(segment)
|
41
|
+
if @item && !@item.empty?
|
42
|
+
@message.add_item(@item.to_json_hash)
|
43
|
+
end
|
44
|
+
@item = Eancom::Edifact::Item.new()
|
29
45
|
end
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
47
|
+
private
|
48
|
+
|
49
|
+
def merge(hash, segment)
|
50
|
+
if name = group_name(segment)
|
51
|
+
hash[name] = [] if hash[name].nil?
|
52
|
+
hash[name] << segment.to_json_hash
|
53
|
+
else
|
54
|
+
hash.merge!(segment.to_json_hash)
|
35
55
|
end
|
36
|
-
|
56
|
+
end
|
37
57
|
|
38
|
-
|
39
|
-
|
40
|
-
}
|
58
|
+
def group_name(segment)
|
59
|
+
return segment.group_name
|
41
60
|
end
|
42
61
|
end
|
43
62
|
end
|
@@ -1,25 +1,24 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Eancom
|
4
2
|
module Edifact
|
5
3
|
class Document
|
4
|
+
|
6
5
|
attr_accessor :header_element, :body_element, :footer_element
|
7
6
|
|
8
7
|
def initialize
|
9
|
-
@header_element = Header.new
|
10
|
-
@body_element = Body.new
|
11
|
-
@footer_element = Footer.new
|
8
|
+
@header_element = Header.new()
|
9
|
+
@body_element = Body.new()
|
10
|
+
@footer_element = Footer.new()
|
12
11
|
end
|
13
12
|
|
14
|
-
def header
|
13
|
+
def header(&block)
|
15
14
|
yield(@header_element)
|
16
15
|
end
|
17
16
|
|
18
|
-
def body
|
17
|
+
def body(&block)
|
19
18
|
yield(@body_element)
|
20
19
|
end
|
21
20
|
|
22
|
-
def footer
|
21
|
+
def footer(&block)
|
23
22
|
yield(@footer_element)
|
24
23
|
end
|
25
24
|
|
@@ -35,6 +34,7 @@ module Eancom
|
|
35
34
|
@footer_element.segment(segment)
|
36
35
|
end
|
37
36
|
|
37
|
+
# Should header and footer segments be added to total_segments?
|
38
38
|
def total_segments
|
39
39
|
total = 0
|
40
40
|
total += @body_element.segments.count
|
@@ -42,14 +42,18 @@ module Eancom
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def to_s(debug: false)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
stream = ''
|
46
|
+
stream << @header_element.to_s(debug: debug)
|
47
|
+
stream << @body_element.to_s(debug: debug)
|
48
|
+
stream << @footer_element.to_s(debug: debug)
|
49
|
+
stream
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_json
|
53
|
+
hash = {}
|
54
|
+
hash.merge! @header_element.to_json_hash
|
55
|
+
hash.merge! @body_element.to_json_hash
|
56
|
+
hash.to_json
|
53
57
|
end
|
54
58
|
end
|
55
59
|
end
|
data/lib/eancom/edifact/item.rb
CHANGED
@@ -1,33 +1,20 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Eancom
|
4
2
|
module Edifact
|
5
3
|
class Message
|
6
|
-
attr_accessor :locations, :items, :hash
|
7
4
|
|
8
|
-
|
9
|
-
|
5
|
+
attr_accessor :items, :hash
|
6
|
+
|
7
|
+
def initialize()
|
10
8
|
@items = []
|
11
9
|
@hash = {}
|
12
10
|
end
|
13
11
|
|
14
|
-
def add_location(location)
|
15
|
-
@locations << location
|
16
|
-
end
|
17
|
-
|
18
12
|
def add_item(item)
|
19
13
|
@items << item
|
20
14
|
end
|
21
15
|
|
22
|
-
def <<(segment)
|
23
|
-
|
24
|
-
start_item if segment.starts_item?
|
25
|
-
|
26
|
-
if @location
|
27
|
-
@location << segment
|
28
|
-
elsif @item
|
29
|
-
@item << segment
|
30
|
-
elsif name = group_name(segment)
|
16
|
+
def << (segment)
|
17
|
+
if name = group_name(segment)
|
31
18
|
@hash[name] = [] if @hash[name].nil?
|
32
19
|
@hash[name] << segment.to_json_hash
|
33
20
|
else
|
@@ -36,16 +23,10 @@ module Eancom
|
|
36
23
|
end
|
37
24
|
|
38
25
|
def to_json_hash
|
39
|
-
if @location && !@location.empty?
|
40
|
-
add_location(@location.to_json_hash)
|
41
|
-
end
|
42
|
-
if @item && !@item.empty?
|
43
|
-
add_item(@item.to_json_hash)
|
44
|
-
end
|
45
26
|
message_hash = {}
|
27
|
+
items_hash = { items: @items }
|
46
28
|
message_hash.merge!(@hash)
|
47
|
-
message_hash.merge!(
|
48
|
-
message_hash.merge!({ items: @items }) if !@items.empty?
|
29
|
+
message_hash.merge!(items_hash)
|
49
30
|
message_hash
|
50
31
|
end
|
51
32
|
|
@@ -55,19 +36,6 @@ module Eancom
|
|
55
36
|
segment.group_name
|
56
37
|
end
|
57
38
|
|
58
|
-
def start_location
|
59
|
-
if @location && !@location.empty?
|
60
|
-
add_location(@location.to_json_hash)
|
61
|
-
end
|
62
|
-
@location = Eancom::Edifact::Location.new
|
63
|
-
end
|
64
|
-
|
65
|
-
def start_item
|
66
|
-
if @item && !@item.empty?
|
67
|
-
add_item(@item.to_json_hash)
|
68
|
-
end
|
69
|
-
@item = Eancom::Edifact::Item.new
|
70
|
-
end
|
71
39
|
end
|
72
40
|
end
|
73
41
|
end
|
@@ -11,18 +11,21 @@ module Eancom
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.initialize_by_components(structure, array)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
begin
|
15
|
+
new(**structure.build_hash(array))
|
16
|
+
rescue StandardError => e
|
17
|
+
raise SegmentParserError.new(
|
18
|
+
"'Parser Error in structure #{structure.tag} with array #{array}.\n \
|
19
|
+
'Inside Structure: \n \ '#{structure.to_s}.\n \
|
18
20
|
'Error:\n \
|
19
21
|
'#{e}"
|
22
|
+
)
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
def validate_structure
|
23
27
|
attributes.each do |key, value|
|
24
28
|
next if value.nil?
|
25
|
-
|
26
29
|
structure.validate!(key, value)
|
27
30
|
end
|
28
31
|
end
|
@@ -36,10 +39,9 @@ module Eancom
|
|
36
39
|
end
|
37
40
|
|
38
41
|
def to_s
|
39
|
-
string = array.map do |e|
|
42
|
+
string = array.map do |e|
|
40
43
|
e = e.compact
|
41
44
|
next if e.empty?
|
42
|
-
|
43
45
|
[e.join(component_delimiter)]
|
44
46
|
end.join(data_delimiter)
|
45
47
|
clean_end_string(string)
|
@@ -83,10 +85,6 @@ module Eancom
|
|
83
85
|
false
|
84
86
|
end
|
85
87
|
|
86
|
-
def starts_location?
|
87
|
-
false
|
88
|
-
end
|
89
|
-
|
90
88
|
def starts_item?
|
91
89
|
false
|
92
90
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Eancom
|
2
|
+
module Edifact
|
3
|
+
class AJT < Segment
|
4
|
+
TAG = 'AJT'.freeze
|
5
|
+
TYPE = :body.freeze
|
6
|
+
|
7
|
+
attr_reader :segment_type
|
8
|
+
|
9
|
+
def initialize(
|
10
|
+
tag: nil,
|
11
|
+
adjustment_reason_description:
|
12
|
+
)
|
13
|
+
@tag = tag
|
14
|
+
@adjustment_reason_description = adjustment_reason_description
|
15
|
+
|
16
|
+
super(tag: tag || TAG)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_json_hash
|
20
|
+
hash = {}
|
21
|
+
if @adjustment_reason_description
|
22
|
+
hash.merge!(adjustment_reason_description: find_identifier(:adjustment_reason_description))
|
23
|
+
end
|
24
|
+
hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def segment_type
|
28
|
+
TYPE
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|