eancom 1.6.0 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10b8633addd1b19df008fcfbf0b33b75c2639cac939e2f2923d6518515c1e670
4
- data.tar.gz: 26a096e4e9afa9c39a0e2184dc2bd60fdf7f2f95140e70dfc19a31d59262cd27
3
+ metadata.gz: 8b5fc9413e1aae3d7677f8e3ae1a779ef9127d4d0432301534022d9b121d35b5
4
+ data.tar.gz: b29cc881d48fa8544cbb6e3779144db51ffbd88d5fe47dbf56bb7f38b9f4c6dd
5
5
  SHA512:
6
- metadata.gz: 34f0152b2721cf4effa65f159642077d52a1e79653e22461a9deb558894c628687775265c1f0b1ced37dfc1a41e87b47af0e6239b53325bee11190845221dd26
7
- data.tar.gz: 52974b80bc2d5bfb9b429c58f2ac01e3c1029e655c8cce924e7115c5ed4af483b56727ec18292871509f2961134683c1f7408e994fbcb7b811360820b1d1461a
6
+ metadata.gz: 3caae6575a4b5276ff6914e6f59688a4237077bbc8ca4227d29a1f527788526c5b9d850d37ef22a8f9e6032e8a1f15f7c88d32be4e85fa3d8e13b464c101effb
7
+ data.tar.gz: 29e2a100a09c4b15dc9e566742306548547688c2ceabd0696fb6ca2247b7a6b37e051f2eeeb894afecedff58579f4c0bc832a42393cb57b4cdb43b86787b0edb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eancom (1.5.6)
4
+ eancom (1.6.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,155 @@
1
+ tag = 'PCD'
2
+ Eancom.register_segment(tag: tag, klass: Eancom::Edifact::PCD)
3
+
4
+ structure = Eancom::Edifact::Structure.new(tag: tag)
5
+ #==============================================================================
6
+ # Tag #
7
+ #==============================================================================
8
+ tag = Eancom::Edifact::Composite.new
9
+ data = Eancom::Edifact::Data.new(
10
+ type: String,
11
+ length: 3,
12
+ dictionary: nil,
13
+ description: "Message Header",
14
+ required: true
15
+ )
16
+ tag.add(:tag, data)
17
+
18
+ structure << tag
19
+ #==============================================================================
20
+ # Product group type code #
21
+ #==============================================================================
22
+ percentage_details = Eancom::Edifact::Composite.new
23
+
24
+ data = Eancom::Edifact::Data.new(
25
+ type: String,
26
+ length: 1..3,
27
+ dictionary: {
28
+ '1' => {
29
+ description: 'Allowance',
30
+ identifier: 'allowance'
31
+ },
32
+ '2' => {
33
+ description: 'Charge',
34
+ identifier: 'charge'
35
+ },
36
+ '3' => {
37
+ description: 'Allowance or Charge',
38
+ identifier: 'allowance_or_charge'
39
+ },
40
+ '7' => {
41
+ description: 'Percentage of invoice',
42
+ identifier: 'percentage_of_invoice'
43
+ },
44
+ '9' => {
45
+ description: 'Adjustment',
46
+ identifier: 'adjustment'
47
+ },
48
+ '12' => {
49
+ description: 'Discount',
50
+ identifier: 'discount'
51
+ },
52
+ '15' => {
53
+ description: 'Penalty percentage',
54
+ identifier: 'penalty_percentage'
55
+ },
56
+ '16' => {
57
+ description: 'Interest percentage',
58
+ identifier: 'interest_percentage'
59
+ },
60
+ '18' => {
61
+ description: 'Percentage credit note',
62
+ identifier: 'percentage_credit_note'
63
+ },
64
+ '19' => {
65
+ description: 'Percentage debit note',
66
+ identifier: 'percentage_debit_note'
67
+ },
68
+ '68' => {
69
+ description: 'Percentage of due amount',
70
+ identifier: 'percentage_of_due_amount'
71
+ },
72
+ '159' => {
73
+ description: 'Nestable percentage',
74
+ identifier: 'nestable_percentage'
75
+ },
76
+ '161' => {
77
+ description: 'Transport weight completed',
78
+ identifier: 'transport_weight_completed'
79
+ },
80
+ '162' => {
81
+ description: 'Transport volume completed',
82
+ identifier: 'transport_volume_completed'
83
+ },
84
+ '163' => {
85
+ description: 'Percentage of order',
86
+ identifier: 'percentage_of_order'
87
+ },
88
+ },
89
+ description: 'Percentage type code qualifier',
90
+ required: true
91
+ )
92
+ percentage_details.add(:percentage_type_code_qualifier, data)
93
+
94
+ data = Eancom::Edifact::Data.new(
95
+ type: Integer,
96
+ length: 0..10,
97
+ dictionary: nil,
98
+ description: 'Percentage',
99
+ required: true
100
+ )
101
+ percentage_details.add(:percentage, data)
102
+
103
+ data = Eancom::Edifact::Data.new(
104
+ type: String,
105
+ length: 0..3,
106
+ dictionary: {
107
+ '1' => {
108
+ description: 'Per unit',
109
+ identifier: 'per_unit'
110
+ },
111
+ '13' => {
112
+ description: 'Invoice value',
113
+ identifier: 'invoice_value'
114
+ },
115
+ },
116
+ description: 'Percentage',
117
+ required: true
118
+ )
119
+ percentage_details.add(:percentage_basis_identification_code, data)
120
+
121
+ data = Eancom::Edifact::Data.new(
122
+ type: String,
123
+ length: 0..17,
124
+ dictionary: nil,
125
+ description: 'Code list identification code',
126
+ required: false
127
+ )
128
+ percentage_details.add(:code_list_idenfitifaction_code, data)
129
+
130
+ data = Eancom::Edifact::Data.new(
131
+ type: String,
132
+ length: 0..3,
133
+ dictionary: {
134
+ '9' => {
135
+ description: 'GS1',
136
+ identifier: 'gsi',
137
+ },
138
+ '91' => {
139
+ description: 'Assigned by supplier or suppliers agent',
140
+ identifier: 'assigned_by_supplier_or_suppliers_agent'
141
+ },
142
+ '92' => {
143
+ description: 'Assigned by buyer or buyers agent',
144
+ identifier: 'assigned_by_buyer_or_buyers_agent'
145
+ }
146
+ },
147
+ description: 'Code list responsible agancy code',
148
+ required: false
149
+ )
150
+ percentage_details.add(:code_list_responsibility_agency_code, data)
151
+
152
+ structure << percentage_details
153
+
154
+ #==============================================================================
155
+ Eancom.register_structure(tag: 'PCD', structure: structure)
@@ -142,7 +142,7 @@ data = Eancom::Edifact::Data.new(
142
142
  )
143
143
  product_group.add(:product_group_name, data)
144
144
 
145
-
146
145
  structure << product_group
146
+
147
147
  #==============================================================================
148
148
  Eancom.register_structure(tag: 'PGI', structure: structure)
@@ -0,0 +1,140 @@
1
+ # frozen_string_literal: true
2
+
3
+ tag = 'QVR'
4
+ Eancom.register_segment(tag: tag, klass: Eancom::Edifact::QVR)
5
+
6
+ structure = Eancom::Edifact::Structure.new(tag: tag)
7
+ #==============================================================================
8
+ # Tag #
9
+ #==============================================================================
10
+ tag = Eancom::Edifact::Composite.new
11
+ data = Eancom::Edifact::Data.new(
12
+ type: String,
13
+ length: 3,
14
+ dictionary: nil,
15
+ description: "Message Header",
16
+ required: true
17
+ )
18
+ tag.add(:tag, data)
19
+
20
+ structure << tag
21
+ #==============================================================================
22
+ # Quantity difference information
23
+ #==============================================================================
24
+ quantity_difference_information = Eancom::Edifact::Composite.new
25
+
26
+ data = Eancom::Edifact::Data.new(
27
+ type: Integer,
28
+ length: 1..15,
29
+ dictionary: nil,
30
+ description: "Specify the actual variance amount here.",
31
+ required: true
32
+ )
33
+ quantity_difference_information.add(:quantity_variance_value, data)
34
+
35
+ data = Eancom::Edifact::Data.new(
36
+ type: String,
37
+ length: 1..3,
38
+ dictionary: {
39
+ '21' => {
40
+ description: 'Ordered quantity',
41
+ identifier: 'ordered_quantity'
42
+ },
43
+ '66' => {
44
+ description: 'Committed quantity',
45
+ identifier: 'committed_quantity'
46
+ }
47
+ },
48
+ description: "Quantity type code qualifier",
49
+ required: true
50
+ )
51
+ quantity_difference_information.add(:quantity_type_code_qualifier, data)
52
+
53
+ structure << quantity_difference_information
54
+ #==============================================================================
55
+ # Discrepancy nature identification code
56
+ #==============================================================================
57
+ discrepancy_nature_identification_code = Eancom::Edifact::Composite.new
58
+
59
+ data = Eancom::Edifact::Data.new(
60
+ type: String,
61
+ length: 0..3,
62
+ dictionary: {
63
+ 'BP' => {
64
+ description: 'Shipment partial - back order to follow',
65
+ identifier: 'shipment_partial_back_order_to_follow',
66
+ },
67
+ 'CP' => {
68
+ description: 'Shipment partial - considered complete, no backorder',
69
+ identifier: 'shipment_partial_considered_complete_no_backorder',
70
+ },
71
+ },
72
+ description: "",
73
+ required: true
74
+ )
75
+ discrepancy_nature_identification_code.add(:discrepancy_nature_identification_code, data)
76
+
77
+ structure << discrepancy_nature_identification_code
78
+ #==============================================================================
79
+ # Reason for change
80
+ #==============================================================================
81
+ reason_for_change = Eancom::Edifact::Composite.new
82
+
83
+ data = Eancom::Edifact::Data.new(
84
+ type: String,
85
+ length: 1..3,
86
+ dictionary: {
87
+ 'WR' => {
88
+ description: 'Temporarily unavailable',
89
+ identifier: 'temporarily_unavailable',
90
+ },
91
+ },
92
+ description: "Change reason description code",
93
+ required: false
94
+ )
95
+ reason_for_change.add(:change_reason_description_code, data)
96
+
97
+ data = Eancom::Edifact::Data.new(
98
+ type: String,
99
+ length: 0..17,
100
+ dictionary: nil,
101
+ description: 'Code list identification code',
102
+ required: false
103
+ )
104
+ reason_for_change.add(:code_list_idenfitifaction_code, data)
105
+
106
+ data = Eancom::Edifact::Data.new(
107
+ type: String,
108
+ length: 0..3,
109
+ dictionary: {
110
+ '9' => {
111
+ description: 'GS1',
112
+ identifier: 'gsi',
113
+ },
114
+ '91' => {
115
+ description: 'Assigned by supplier or suppliers agent',
116
+ identifier: 'assigned_by_supplier_or_suppliers_agent'
117
+ },
118
+ '92' => {
119
+ description: 'Assigned by buyer or buyers agent',
120
+ identifier: 'assigned_by_buyer_or_buyers_agent'
121
+ }
122
+ },
123
+ description: 'Code list responsible agancy code',
124
+ required: false
125
+ )
126
+ reason_for_change.add(:code_list_responsibility_agency_code, data)
127
+
128
+ data = Eancom::Edifact::Data.new(
129
+ type: String,
130
+ length: 1..35,
131
+ dictionary: nil,
132
+ description: "Change reason description",
133
+ required: false
134
+ )
135
+ reason_for_change.add(:change_reason_description, data)
136
+
137
+ structure << reason_for_change
138
+
139
+ #==============================================================================
140
+ Eancom.register_structure(tag: 'QVR', structure: structure)
@@ -80,6 +80,6 @@ data = Eancom::Edifact::Data.new(
80
80
  composite.add(:una6, data)
81
81
  structure << composite
82
82
 
83
- Eancom.register_structure(tag: tag, structure: structure)
83
+ Eancom.register_structure(tag: 'UNA', structure: structure)
84
84
 
85
85
 
@@ -33,7 +33,7 @@ module Eancom
33
33
  start_message if segment.starts_message?
34
34
  @message << segment
35
35
  end
36
- messages << @message.to_json_hash
36
+ messages << @message.to_json_hash if @message
37
37
 
38
38
  {
39
39
  body: hash.merge({ messages: messages })
@@ -0,0 +1,44 @@
1
+ module Eancom
2
+ module Edifact
3
+ class PCD < Segment
4
+ TAG = 'PCD'.freeze
5
+ TYPE = :body.freeze
6
+
7
+ attr_reader :segment_type
8
+
9
+ def initialize(
10
+ tag: nil,
11
+ percentage_type_code_qualifier:,
12
+ percentage:,
13
+ code_list_identification_code: nil,
14
+ code_list_responsibility_agency_code: nil
15
+ )
16
+ @tag = tag
17
+ @percentage_type_code_qualifier = percentage_type_code_qualifier
18
+ @percentage = percentage
19
+ @code_list_identification_code = code_list_identification_code
20
+ @code_list_responsibility_agency_code = code_list_responsibility_agency_code
21
+
22
+ super(tag: tag || TAG)
23
+ end
24
+
25
+ def to_json_hash
26
+ hash = {
27
+ 'percentage_type_code_qualifier': percentage_type,
28
+ 'percentage': percentage
29
+ }
30
+ end
31
+
32
+ def segment_type
33
+ TYPE
34
+ end
35
+
36
+ private
37
+
38
+ def percentage_type
39
+ @percentage_type ||= find_identifier(:percentage_type_code_qualifier)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Eancom
4
+ module Edifact
5
+ class QVR < Segment
6
+ TAG = 'QVR'
7
+ TYPE = :body
8
+
9
+ def initialize(
10
+ tag: nil,
11
+ quantity_variance_value:,
12
+ quantity_type_code_qualifier:,
13
+ discrepancy_nature_identification_code: nil,
14
+ change_reason_description_code: nil,
15
+ code_list_identification_code: nil,
16
+ code_list_responsible_agency_code: nil,
17
+ change_reason_description: nil
18
+ )
19
+ @tag = tag
20
+
21
+ @quantity_variance_value = quantity_variance_value
22
+ @quantity_type_code_qualifier = quantity_type_code_qualifier
23
+ @discrepancy_nature_identification_code = discrepancy_nature_identification_code
24
+ @change_reason_description_code = change_reason_description_code
25
+ @code_list_identification_code = code_list_identification_code
26
+ @code_list_responsible_agency_code = code_list_responsible_agency_code
27
+ @change_reason_description = change_reason_description
28
+
29
+ super(tag: tag || TAG)
30
+ end
31
+
32
+ def to_json_hash
33
+ hash = {}
34
+ hash.merge!(quantity_variance_value: quantity_variance_value)
35
+ hash.merge!(quantity_type_code_qualifier: find_identifier(:quantity_type_code_qualifier))
36
+ hash.merge!(discrepancy_nature_identification_code: find_identifier(:discrepancy_nature_identification_code)) if @discrepancy_nature_identification_code
37
+ hash.merge!(change_reason_description: @change_reason_description) if @change_reason_description
38
+ hash
39
+ end
40
+
41
+ def group_name
42
+ 'quantity_variances'
43
+ end
44
+
45
+ def segment_type
46
+ TYPE
47
+ end
48
+ end
49
+ end
50
+ end
@@ -39,9 +39,11 @@ require 'eancom/edifact/segments/moa'
39
39
  require 'eancom/edifact/segments/nad'
40
40
  require 'eancom/edifact/segments/pac'
41
41
  require 'eancom/edifact/segments/pgi'
42
+ require 'eancom/edifact/segments/pcd'
42
43
  require 'eancom/edifact/segments/pia'
43
44
  require 'eancom/edifact/segments/pri'
44
45
  require 'eancom/edifact/segments/qty'
46
+ require 'eancom/edifact/segments/qvr'
45
47
  require 'eancom/edifact/segments/rff'
46
48
  require 'eancom/edifact/segments/tax'
47
49
  require 'eancom/edifact/segments/tdt'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Eancom
2
4
  module Parser
3
5
  class Document
@@ -10,9 +12,14 @@ module Eancom
10
12
  @document = Eancom::Edifact::Document.new
11
13
  end
12
14
 
13
- def parse
15
+ def parse(header_only: false)
14
16
  content.split(segment_delimiter).each do |segment_string|
15
17
  segment = Parser::Segment.new(segment_string)
18
+
19
+ if header_only && segment.segment_class::TYPE != :header
20
+ next
21
+ end
22
+
16
23
  segment = segment.parse
17
24
  add(segment)
18
25
  end
@@ -29,7 +36,7 @@ module Eancom
29
36
  elsif segment.is_footer?
30
37
  @document.add_to_footer(segment)
31
38
  else
32
- raise SegmentTypeNotDefined.new
39
+ raise SegmentTypeNotDefined
33
40
  end
34
41
  end
35
42
 
@@ -53,16 +60,14 @@ module Eancom
53
60
  end
54
61
 
55
62
  def convert(string)
56
- string = string.encode(
63
+ string.encode(
57
64
  'UTF-8',
58
65
  'binary',
59
66
  invalid: :replace,
60
67
  undef: :replace,
61
68
  replace: ''
62
69
  )
63
- string
64
70
  end
65
-
66
71
  end
67
72
  end
68
73
  end
@@ -2,11 +2,13 @@ module Eancom
2
2
  module Parser
3
3
  class Segment
4
4
 
5
- attr_accessor :tag, :components, :string
5
+ attr_accessor :tag, :string, :components, :segment_class
6
6
 
7
7
  def initialize(string)
8
8
  @string = string
9
9
  @components = []
10
+ @tag = una? ? 'UNA' : string.split(data_delimiter)[0]
11
+ @segment_class = find_segment_class
10
12
  end
11
13
 
12
14
  def parse
@@ -19,13 +21,13 @@ module Eancom
19
21
  private
20
22
 
21
23
  def parse_component
22
- if string =~ /^UNA/
23
- parse_una
24
- else
24
+ if una?
25
+ parse_una
26
+ else
25
27
  string.split(data_delimiter).each do |data|
26
28
  components << parse_data(data)
27
29
  end
28
- end
30
+ end
29
31
  end
30
32
 
31
33
  def parse_data(data)
@@ -46,10 +48,6 @@ module Eancom
46
48
  components << [DELIMITERS[:segment]]
47
49
  end
48
50
 
49
- def tag
50
- components.first.first
51
- end
52
-
53
51
  def find_segment_class
54
52
  Eancom.find_segment(tag: tag)
55
53
  end
@@ -66,6 +64,9 @@ module Eancom
66
64
  DELIMITERS[:component]
67
65
  end
68
66
 
67
+ def una?
68
+ string =~ /^UNA/
69
+ end
69
70
  end
70
71
  end
71
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eancom
4
- VERSION = '1.6.0'
4
+ VERSION = '1.6.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eancom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fadendaten GmbH
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-15 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -163,10 +163,12 @@ files:
163
163
  - definitions/segments/moa.rb
164
164
  - definitions/segments/nad.rb
165
165
  - definitions/segments/pac.rb
166
+ - definitions/segments/pcd.rb
166
167
  - definitions/segments/pgi.rb
167
168
  - definitions/segments/pia.rb
168
169
  - definitions/segments/pri.rb
169
170
  - definitions/segments/qty.rb
171
+ - definitions/segments/qvr.rb
170
172
  - definitions/segments/rff.rb
171
173
  - definitions/segments/tax.rb
172
174
  - definitions/segments/tdt.rb
@@ -210,10 +212,12 @@ files:
210
212
  - lib/eancom/edifact/segments/moa.rb
211
213
  - lib/eancom/edifact/segments/nad.rb
212
214
  - lib/eancom/edifact/segments/pac.rb
215
+ - lib/eancom/edifact/segments/pcd.rb
213
216
  - lib/eancom/edifact/segments/pgi.rb
214
217
  - lib/eancom/edifact/segments/pia.rb
215
218
  - lib/eancom/edifact/segments/pri.rb
216
219
  - lib/eancom/edifact/segments/qty.rb
220
+ - lib/eancom/edifact/segments/qvr.rb
217
221
  - lib/eancom/edifact/segments/rff.rb
218
222
  - lib/eancom/edifact/segments/tax.rb
219
223
  - lib/eancom/edifact/segments/tdt.rb