eddy 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +23 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/definitions/elements/generated/1005.hierarchical_structure_code.rb +1 -1
- data/lib/definitions/elements/generated/1019.invoice_type_code.rb +1 -1
- data/lib/definitions/elements/generated/103.packaging_code.rb +1 -1
- data/lib/definitions/elements/generated/1166.contract_type_code.rb +1 -1
- data/lib/definitions/elements/generated/1232.purchase_category.rb +1 -1
- data/lib/definitions/elements/generated/127.reference_identification.rb +1 -1
- data/lib/definitions/elements/generated/128.reference_identification_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/1300.service_promotion_allowance_or_charge_code.rb +1 -1
- data/lib/definitions/elements/generated/1301.agency_service_promotion_allowance_or_charge_code.rb +1 -1
- data/lib/definitions/elements/generated/133.routing_sequence_code.rb +1 -1
- data/lib/definitions/elements/generated/166.address_information.rb +1 -1
- data/lib/definitions/elements/generated/183.volume.rb +1 -1
- data/lib/definitions/elements/generated/187.weight_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/19.city_name.rb +1 -1
- data/lib/definitions/elements/generated/206.equipment_initial.rb +1 -1
- data/lib/definitions/elements/generated/207.equipment_number.rb +1 -1
- data/lib/definitions/elements/generated/212.unit_price.rb +1 -1
- data/lib/definitions/elements/generated/22.commodity_code.rb +1 -1
- data/lib/definitions/elements/generated/23.commodity_code_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/234.product_service_id.rb +1 -1
- data/lib/definitions/elements/generated/235.product_service_id_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/236.price_identifier_code.rb +1 -1
- data/lib/definitions/elements/generated/248.allowance_or_charge_indicator.rb +1 -1
- data/lib/definitions/elements/generated/26.country_code.rb +1 -1
- data/lib/definitions/elements/generated/284.service_level_code.rb +1 -1
- data/lib/definitions/elements/generated/324.purchase_order_number.rb +1 -1
- data/lib/definitions/elements/generated/326.request_reference_number.rb +1 -1
- data/lib/definitions/elements/generated/327.change_order_sequence_number.rb +1 -1
- data/lib/definitions/elements/generated/328.release_number.rb +1 -1
- data/lib/definitions/elements/generated/330.quantity_ordered.rb +1 -1
- data/lib/definitions/elements/generated/347.hash_total.rb +1 -1
- data/lib/definitions/elements/generated/349.item_description_type.rb +1 -1
- data/lib/definitions/elements/generated/352.description.rb +1 -1
- data/lib/definitions/elements/generated/353.transaction_set_purpose_code.rb +1 -1
- data/lib/definitions/elements/generated/354.number_of_line_items.rb +1 -1
- data/lib/definitions/elements/generated/355.unit_or_basis_for_measurement_code.rb +1 -1
- data/lib/definitions/elements/generated/358.quantity_invoiced.rb +1 -1
- data/lib/definitions/elements/generated/367.contract_number.rb +1 -1
- data/lib/definitions/elements/generated/368.shipment_order_status_code.rb +1 -1
- data/lib/definitions/elements/generated/374.date_time_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/380.quantity.rb +1 -1
- data/lib/definitions/elements/generated/382.number_of_units_shipped.rb +1 -1
- data/lib/definitions/elements/generated/387.routing.rb +1 -1
- data/lib/definitions/elements/generated/396.shipment_identification.rb +1 -1
- data/lib/definitions/elements/generated/559.agency_qualifier_code.rb +1 -1
- data/lib/definitions/elements/generated/587.acknowledgment_type.rb +1 -1
- data/lib/definitions/elements/generated/610.amount.rb +1 -1
- data/lib/definitions/elements/generated/639.basis_of_unit_price_code.rb +1 -1
- data/lib/definitions/elements/generated/640.transaction_type_code.rb +1 -1
- data/lib/definitions/elements/generated/646.quantity_shipped_to_date.rb +1 -1
- data/lib/definitions/elements/generated/648.price_multiplier_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/649.multiplier.rb +1 -1
- data/lib/definitions/elements/generated/66.identification_code_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/662.relationship_code.rb +1 -1
- data/lib/definitions/elements/generated/668.line_item_status_code.rb +1 -1
- data/lib/definitions/elements/generated/67.identification_code.rb +1 -1
- data/lib/definitions/elements/generated/687.class_of_trade_code.rb +1 -1
- data/lib/definitions/elements/generated/750.product_process_characteristic_code.rb +1 -1
- data/lib/definitions/elements/generated/751.product_description_code.rb +1 -1
- data/lib/definitions/elements/generated/76.invoice_number.rb +1 -1
- data/lib/definitions/elements/generated/782.monetary_amount.rb +1 -1
- data/lib/definitions/elements/generated/786.security_level_code.rb +1 -1
- data/lib/definitions/elements/generated/79.lading_description.rb +1 -1
- data/lib/definitions/elements/generated/80.lading_quantity.rb +1 -1
- data/lib/definitions/elements/generated/87.marks_and_numbers.rb +1 -1
- data/lib/definitions/elements/generated/88.marks_and_numbers_qualifier.rb +1 -1
- data/lib/definitions/elements/generated/91.transportation_method_type_code.rb +1 -1
- data/lib/definitions/elements/generated/92.purchase_order_type_code.rb +1 -1
- data/lib/definitions/elements/generated/98.entity_identifier_code.rb +1 -1
- data/lib/definitions/elements/manual/116.postal_code.rb +1 -1
- data/lib/definitions/elements/manual/124.application_receivers_code.rb +1 -1
- data/lib/definitions/elements/manual/140.standard_carrier_alpha_code.rb +1 -1
- data/lib/definitions/elements/manual/142.application_senders_code.rb +1 -1
- data/lib/definitions/elements/manual/143.transaction_set_identifier_code.rb +1 -1
- data/lib/definitions/elements/manual/156.state_or_province_code.rb +1 -1
- data/lib/definitions/elements/manual/28.group_control_number.rb +1 -1
- data/lib/definitions/elements/manual/329.transactional_set_control_number.rb +2 -2
- data/lib/definitions/elements/manual/337.time.rb +1 -1
- data/lib/definitions/elements/manual/350.assigned_identification.rb +1 -1
- data/lib/definitions/elements/manual/373.date.rb +1 -1
- data/lib/definitions/elements/manual/455.responsible_agency_code.rb +1 -1
- data/lib/definitions/elements/manual/479.functional_identifier_code.rb +1 -1
- data/lib/definitions/elements/manual/480.version_release_industry_identifier_code.rb +1 -1
- data/lib/definitions/elements/manual/784.length_of_binary_data.rb +1 -1
- data/lib/definitions/elements/manual/785.binary_data.rb +1 -1
- data/lib/definitions/elements/manual/96.number_of_included_segments.rb +1 -1
- data/lib/definitions/elements/manual/97.number_of_transaction_sets_included.rb +1 -1
- data/lib/definitions/elements/manual/hl/628.hierarchical_id_number.rb +1 -1
- data/lib/definitions/elements/manual/hl/734.hierarchical_parent_id_number.rb +1 -1
- data/lib/definitions/elements/manual/hl/735.hierarchical_level_code.rb +1 -1
- data/lib/definitions/elements/manual/hl/736.hierarchical_child_code.rb +1 -1
- data/lib/definitions/elements/manual/i/I01.authorization_information_qualifier.rb +1 -1
- data/lib/definitions/elements/manual/i/I02.authorization_information.rb +1 -1
- data/lib/definitions/elements/manual/i/I03.security_information_qualifier.rb +1 -1
- data/lib/definitions/elements/manual/i/I04.security_information.rb +1 -1
- data/lib/definitions/elements/manual/i/I05.interchange_id_qualifier.rb +1 -1
- data/lib/definitions/elements/manual/i/I06.interchange_sender_id.rb +1 -1
- data/lib/definitions/elements/manual/i/I07.interchange_receiver_id.rb +1 -1
- data/lib/definitions/elements/manual/i/I08.interchange_date.rb +1 -1
- data/lib/definitions/elements/manual/i/I09.interchange_time.rb +1 -1
- data/lib/definitions/elements/manual/i/I10.interchange_control_standards_identifier.rb +1 -1
- data/lib/definitions/elements/manual/i/I11.interchange_control_version_number.rb +1 -1
- data/lib/definitions/elements/manual/i/I12.interchange_control_number.rb +1 -1
- data/lib/definitions/elements/manual/i/I13.acknowledgment_requested.rb +1 -1
- data/lib/definitions/elements/manual/i/I14.usage_indicator.rb +1 -1
- data/lib/definitions/elements/manual/i/I15.component_element_separator.rb +1 -1
- data/lib/definitions/elements/manual/i/I16.number_of_included_functional_groups.rb +1 -1
- data/lib/definitions/elements/manual/misc/81.weight.rb +1 -1
- data/lib/definitions/elements/manual/misc/93.name.rb +1 -1
- data/lib/definitions/segments/generated/ack.rb +1 -1
- data/lib/definitions/segments/generated/bak.rb +1 -1
- data/lib/definitions/segments/generated/beg.rb +1 -1
- data/lib/definitions/segments/generated/big.rb +1 -1
- data/lib/definitions/segments/generated/bsn.rb +1 -1
- data/lib/definitions/segments/generated/cad.rb +1 -1
- data/lib/definitions/segments/generated/ctp.rb +1 -1
- data/lib/definitions/segments/generated/ctt.rb +1 -1
- data/lib/definitions/segments/generated/dtm.rb +1 -1
- data/lib/definitions/segments/generated/it1.rb +1 -1
- data/lib/definitions/segments/generated/lin.rb +1 -1
- data/lib/definitions/segments/generated/man.rb +1 -1
- data/lib/definitions/segments/generated/n1.rb +1 -1
- data/lib/definitions/segments/generated/n3.rb +1 -1
- data/lib/definitions/segments/generated/n4.rb +1 -1
- data/lib/definitions/segments/generated/pid.rb +1 -1
- data/lib/definitions/segments/generated/po1.rb +1 -1
- data/lib/definitions/segments/generated/prf.rb +1 -1
- data/lib/definitions/segments/generated/ref.rb +1 -1
- data/lib/definitions/segments/generated/sac.rb +1 -1
- data/lib/definitions/segments/generated/sln.rb +1 -1
- data/lib/definitions/segments/generated/sn1.rb +1 -1
- data/lib/definitions/segments/generated/td1.rb +1 -1
- data/lib/definitions/segments/generated/td5.rb +1 -1
- data/lib/definitions/segments/generated/tds.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/ge.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/gs.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/iea.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/isa.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/se.rb +1 -1
- data/lib/definitions/segments/manual/envelopes/st.rb +1 -1
- data/lib/definitions/segments/manual/hl.rb +1 -1
- data/lib/definitions/segments/manual/n2.rb +1 -1
- data/lib/definitions/transaction_sets/manual/810/810.rb +19 -24
- data/lib/definitions/transaction_sets/manual/810/loops/it1.rb +92 -0
- data/lib/definitions/transaction_sets/manual/810/loops/n1.rb +72 -0
- data/lib/definitions/transaction_sets/manual/810/loops/pid.rb +45 -0
- data/lib/definitions/transaction_sets/manual/810/loops/sac.rb +45 -0
- data/lib/definitions/transaction_sets/manual/850/850.rb +12 -14
- data/lib/definitions/transaction_sets/manual/850/loops/n1.rb +74 -0
- data/lib/definitions/transaction_sets/manual/850/loops/po1.rb +51 -0
- data/lib/definitions/transaction_sets/manual/855/855.rb +11 -15
- data/lib/definitions/transaction_sets/manual/855/loops/ack.rb +45 -0
- data/lib/definitions/transaction_sets/manual/855/loops/n1.rb +72 -0
- data/lib/definitions/transaction_sets/manual/855/loops/pid.rb +45 -0
- data/lib/definitions/transaction_sets/manual/855/loops/po1.rb +80 -0
- data/lib/definitions/transaction_sets/manual/856/856.rb +8 -16
- data/lib/definitions/transaction_sets/manual/856/loops/hl_item.rb +87 -0
- data/lib/definitions/transaction_sets/manual/856/loops/hl_order.rb +59 -0
- data/lib/definitions/transaction_sets/manual/856/loops/hl_shipment.rb +159 -0
- data/lib/definitions/transaction_sets/manual/856/loops/hl_tare.rb +59 -0
- data/lib/definitions/transaction_sets/manual/856/loops/n1.rb +71 -0
- data/lib/definitions/transaction_sets/manual/856/loops/sln.rb +44 -0
- data/lib/eddy/build/elements/element.rb +5 -5
- data/lib/eddy/build/elements/elements.rb +3 -3
- data/lib/eddy/build/elements/id.rb +1 -1
- data/lib/eddy/build/elements/n.rb +1 -1
- data/lib/eddy/build/loop/base.rb +49 -0
- data/lib/eddy/build/loop/render.rb +18 -0
- data/lib/eddy/build/loop/repeat.rb +86 -0
- data/lib/eddy/build/segment_builder.rb +14 -9
- data/lib/eddy/build/transaction_set_builder.rb +60 -93
- data/lib/eddy/build.rb +3 -1
- data/lib/eddy/errors.rb +16 -15
- data/lib/eddy/models/element/an.rb +45 -43
- data/lib/eddy/models/element/b.rb +45 -43
- data/lib/eddy/models/element/base.rb +102 -100
- data/lib/eddy/models/element/composite.rb +5 -3
- data/lib/eddy/models/element/dt.rb +82 -80
- data/lib/eddy/models/element/id.rb +47 -45
- data/lib/eddy/models/element/n.rb +79 -77
- data/lib/eddy/models/element/r.rb +70 -68
- data/lib/eddy/models/element/tm.rb +95 -93
- data/lib/eddy/models/element.rb +4 -2
- data/lib/eddy/models/functional_group.rb +29 -27
- data/lib/eddy/models/interchange.rb +49 -47
- data/lib/eddy/models/loop/base.rb +62 -63
- data/lib/eddy/models/loop/repeat.rb +43 -31
- data/lib/eddy/models/segment.rb +30 -28
- data/lib/eddy/models/transaction_set.rb +82 -80
- data/lib/eddy/models.rb +1 -1
- data/lib/eddy/{schema/element_summary.rb → summary/element.rb} +3 -3
- data/lib/eddy/{schema/loop_summary.rb → summary/loop.rb} +53 -16
- data/lib/eddy/{schema/segment_summary.rb → summary/segment.rb} +14 -6
- data/lib/eddy/{schema/transaction_set_summary.rb → summary/transaction_set.rb} +14 -13
- data/lib/eddy/{schema → summary}/validate.rb +1 -1
- data/lib/eddy/summary.rb +10 -0
- data/lib/eddy/util.rb +5 -5
- data/lib/eddy/version.rb +1 -1
- data/lib/eddy.rb +1 -7
- data/todo.txt +3 -5
- metadata +28 -13
- data/lib/definitions/transaction_sets/manual/810/loops.rb +0 -109
- data/lib/definitions/transaction_sets/manual/850/loops.rb +0 -58
- data/lib/definitions/transaction_sets/manual/855/loops.rb +0 -104
- data/lib/definitions/transaction_sets/manual/856/loops.rb +0 -155
- data/lib/eddy/build/loop_builder.rb +0 -93
|
@@ -6,7 +6,7 @@ module Eddy
|
|
|
6
6
|
# Generate Ruby code from JSON/YAML EDI definitions.
|
|
7
7
|
class SegmentBuilder
|
|
8
8
|
|
|
9
|
-
# @return [Eddy::
|
|
9
|
+
# @return [Eddy::Summary::Segment]
|
|
10
10
|
attr_accessor :summary
|
|
11
11
|
# @return [String] (nil)
|
|
12
12
|
attr_accessor :folder
|
|
@@ -24,18 +24,18 @@ module Eddy
|
|
|
24
24
|
# @param (see #initialize)
|
|
25
25
|
# @return [Eddy::Build::SegmentBuilder]
|
|
26
26
|
def self.from_file(path, **kwargs)
|
|
27
|
-
raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::
|
|
27
|
+
raise Eddy::Errors::Error, "Invalid segment definition" unless Eddy::Summary.valid_segment_data?(path)
|
|
28
28
|
data = Eddy::Util.read_json_or_yaml(path)
|
|
29
29
|
sb = Eddy::Build::SegmentBuilder.new(**kwargs)
|
|
30
|
-
sb.summary = Eddy::
|
|
30
|
+
sb.summary = Eddy::Summary::Segment.create(data)
|
|
31
31
|
return sb
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
# @param summary [Eddy::
|
|
34
|
+
# @param summary [Eddy::Summary::Segment]
|
|
35
35
|
# @param (see #initialize)
|
|
36
36
|
# @return [Eddy::Build::SegmentBuilder]
|
|
37
37
|
def self.from_summary(summary, **kwargs)
|
|
38
|
-
sb =
|
|
38
|
+
sb = new(**kwargs)
|
|
39
39
|
sb.summary = summary
|
|
40
40
|
return sb
|
|
41
41
|
end
|
|
@@ -54,12 +54,17 @@ module Eddy
|
|
|
54
54
|
return result
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# @return [String]
|
|
58
|
+
def render()
|
|
59
|
+
return self.ginny_class.render()
|
|
60
|
+
end
|
|
61
|
+
|
|
57
62
|
# @return [Ginny::Class]
|
|
58
63
|
def ginny_class()
|
|
59
64
|
return Ginny::Class.create({
|
|
60
65
|
classify_name: false,
|
|
61
66
|
modules: ["Eddy", "Segments"],
|
|
62
|
-
parent: "Eddy::Segment",
|
|
67
|
+
parent: "Eddy::Models::Segment",
|
|
63
68
|
name: summary.id,
|
|
64
69
|
description: summary.doc_comment(header: true),
|
|
65
70
|
body: <<~STR,
|
|
@@ -116,8 +121,8 @@ module Eddy
|
|
|
116
121
|
return defs.join("\n\n")
|
|
117
122
|
end
|
|
118
123
|
|
|
119
|
-
# @param el [Eddy::
|
|
120
|
-
# @param header [Symbol] (see Eddy::
|
|
124
|
+
# @param el [Eddy::Summary::Element]
|
|
125
|
+
# @param header [Symbol] (see Eddy::Summary::Element#doc_comment)
|
|
121
126
|
# @return [String]
|
|
122
127
|
def self.element_accessor_v1(el, header: :summary)
|
|
123
128
|
return <<~RB.strip
|
|
@@ -131,7 +136,7 @@ module Eddy
|
|
|
131
136
|
RB
|
|
132
137
|
end
|
|
133
138
|
|
|
134
|
-
# @param el [Eddy::
|
|
139
|
+
# @param el [Eddy::Summary::Element]
|
|
135
140
|
# @param dupes [Hash]
|
|
136
141
|
# @param header [Boolean] (false)
|
|
137
142
|
# @return [String]
|
|
@@ -1,82 +1,82 @@
|
|
|
1
1
|
require "ginny"
|
|
2
|
+
require "forwardable"
|
|
2
3
|
|
|
3
4
|
module Eddy
|
|
4
5
|
module Build
|
|
5
6
|
# Generate Ruby code from JSON/YAML EDI definitions.
|
|
6
|
-
#
|
|
7
|
-
# - Validate definition file
|
|
8
|
-
# - Create Summary
|
|
9
|
-
# - For Segments, check that we have a default definition for each.
|
|
10
|
-
# - Generate segments?
|
|
11
|
-
# - For Elements, check that we have a default definition for each.
|
|
12
|
-
# - Apply any input over default element attributes.
|
|
13
7
|
class TransactionSetBuilder
|
|
8
|
+
extend Forwardable
|
|
14
9
|
|
|
15
|
-
# @return [Eddy::
|
|
10
|
+
# @return [Eddy::Summary::TransactionSet]
|
|
16
11
|
attr_accessor :summary
|
|
17
|
-
# @return [String] (nil)
|
|
18
|
-
attr_accessor :folder
|
|
19
|
-
# @return [Boolean] (false)
|
|
20
|
-
attr_accessor :headers
|
|
21
12
|
|
|
13
|
+
# @param summary [Eddy::Summary::TransactionSet]
|
|
22
14
|
# @param folder [String] (nil)
|
|
23
|
-
# @param headers [Boolean] (false)
|
|
24
15
|
# @return [void]
|
|
25
|
-
def initialize(folder: nil
|
|
26
|
-
self.
|
|
27
|
-
|
|
16
|
+
def initialize(summary, folder: nil)
|
|
17
|
+
self.summary = summary
|
|
18
|
+
@folder = folder
|
|
28
19
|
end
|
|
29
20
|
|
|
21
|
+
def_delegators(
|
|
22
|
+
:@summary,
|
|
23
|
+
:id,
|
|
24
|
+
:name,
|
|
25
|
+
:normalized_name,
|
|
26
|
+
:functional_group,
|
|
27
|
+
)
|
|
28
|
+
|
|
30
29
|
# @param path [String] Path to a JSON or YAML file containing a valid Transaction Set definition.
|
|
31
30
|
# @param (see #initialize)
|
|
32
31
|
# @return [Eddy::Build::TransactionSetBuilder]
|
|
33
32
|
def self.from_file(path, **kwargs)
|
|
34
|
-
raise Eddy::Errors::Error, "Invalid transaction set definition" unless Eddy::
|
|
33
|
+
raise Eddy::Errors::Error, "Invalid transaction set definition" unless Eddy::Summary.valid_transaction_set_data?(path)
|
|
35
34
|
data = Eddy::Util.read_json_or_yaml(path)
|
|
36
|
-
|
|
37
|
-
builder.summary = Eddy::Schema::TransactionSetSummary.create(data)
|
|
38
|
-
return builder
|
|
35
|
+
return new(Eddy::Summary::TransactionSet.create(data), **kwargs)
|
|
39
36
|
end
|
|
40
37
|
|
|
41
|
-
# @
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return builder
|
|
38
|
+
# @return [String]
|
|
39
|
+
def folder()
|
|
40
|
+
root_path = @folder || File.join(Eddy::Util.root_dir, "build", "transaction_sets")
|
|
41
|
+
path = File.join(root_path, self.id.to_s)
|
|
42
|
+
FileUtils.mkdir_p(path)
|
|
43
|
+
return path
|
|
48
44
|
end
|
|
49
45
|
|
|
50
46
|
# @return [String]
|
|
51
47
|
def build()
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
FileUtils.mkdir_p(path)
|
|
55
|
-
File.open(File.join(path, "loops.rb"), "a") { |f| f.write(self.render_loops) }
|
|
56
|
-
return self.ginny_class.generate(path)
|
|
48
|
+
self.build_loops()
|
|
49
|
+
return self.ginny_class.generate(self.folder, file: "#{self.id}.rb")
|
|
57
50
|
end
|
|
58
51
|
|
|
59
52
|
# @return [String]
|
|
60
|
-
def
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
def render()
|
|
54
|
+
return self.ginny_class.render()
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# @return [String]
|
|
58
|
+
def build_loops()
|
|
59
|
+
FileUtils.mkdir_p(File.join(self.folder, "loops"))
|
|
60
|
+
self.summary.unique_loops.each do |looop|
|
|
61
|
+
File.open(File.join(self.folder, "loops", "#{looop.normalized_name}.rb"), "a") do |f|
|
|
62
|
+
f.write(Eddy::Build::Loop.render(looop, self.normalized_name) + "\n")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
# @return [Ginny::Class]
|
|
68
68
|
def ginny_class()
|
|
69
69
|
return Ginny::Class.create({
|
|
70
70
|
classify_name: false,
|
|
71
|
-
modules: ["Eddy", "TransactionSets", self.
|
|
72
|
-
parent: "Eddy::TransactionSet",
|
|
73
|
-
name: self.
|
|
71
|
+
modules: ["Eddy", "TransactionSets", self.normalized_name],
|
|
72
|
+
parent: "Eddy::Models::TransactionSet",
|
|
73
|
+
name: self.normalized_name,
|
|
74
74
|
description: self.summary.doc_comment(header: true),
|
|
75
75
|
body: <<~STR,
|
|
76
76
|
|
|
77
|
-
ID = "#{self.
|
|
78
|
-
NAME = "#{self.
|
|
79
|
-
FUNCTIONAL_GROUP = "#{self.
|
|
77
|
+
ID = "#{self.id}".freeze
|
|
78
|
+
NAME = "#{self.name}".freeze
|
|
79
|
+
FUNCTIONAL_GROUP = "#{self.functional_group}".freeze
|
|
80
80
|
|
|
81
81
|
#{self.constructor()}
|
|
82
82
|
|
|
@@ -105,15 +105,10 @@ module Eddy
|
|
|
105
105
|
def declarations()
|
|
106
106
|
decs = ""
|
|
107
107
|
self.summary.components.each do |comp|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
if comp.is_a?(Eddy::Summary::Loop) && comp.repeat_limit > 1
|
|
109
|
+
decs << "@#{comp.var_name} = Eddy::TransactionSets::#{self.normalized_name}::Loops::#{comp.id.upcase}::Base.new(store)\n"
|
|
110
|
+
else
|
|
110
111
|
decs << "@#{comp.id.downcase} = Eddy::Segments::#{comp.id.upcase}.new(store)\n"
|
|
111
|
-
when Eddy::Schema::LoopSummary
|
|
112
|
-
if comp.repeat == 1
|
|
113
|
-
decs << "@#{comp.id.downcase} = Eddy::Segments::#{comp.id.upcase}.new(store)\n"
|
|
114
|
-
else
|
|
115
|
-
decs << "@l_#{comp.id.downcase} = Eddy::TransactionSets::#{self.summary.normalized_name}::Loops::#{comp.id.upcase}.new(store)\n"
|
|
116
|
-
end
|
|
117
112
|
end
|
|
118
113
|
end
|
|
119
114
|
return decs
|
|
@@ -124,15 +119,10 @@ module Eddy
|
|
|
124
119
|
super_call = "super(\n"
|
|
125
120
|
super_call << " store,\n"
|
|
126
121
|
self.summary.components.each do |comp|
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
if comp.is_a?(Eddy::Summary::Loop) && comp.repeat_limit > 1
|
|
123
|
+
super_call << " @#{comp.var_name},\n"
|
|
124
|
+
else
|
|
129
125
|
super_call << " @#{comp.id.downcase},\n"
|
|
130
|
-
when Eddy::Schema::LoopSummary
|
|
131
|
-
if comp.repeat == 1
|
|
132
|
-
super_call << " @#{comp.id.downcase},\n"
|
|
133
|
-
else
|
|
134
|
-
super_call << " @l_#{comp.id.downcase},\n"
|
|
135
|
-
end
|
|
136
126
|
end
|
|
137
127
|
end
|
|
138
128
|
super_call << ")"
|
|
@@ -144,15 +134,10 @@ module Eddy
|
|
|
144
134
|
# @return [String]
|
|
145
135
|
def accessors()
|
|
146
136
|
defs = self.summary.components.map do |comp|
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
if comp.is_a?(Eddy::Summary::Loop) && comp.repeat_limit > 1
|
|
138
|
+
Eddy::Build::TransactionSetBuilder.loop_accessor(comp, self.normalized_name)
|
|
139
|
+
else
|
|
149
140
|
Eddy::Build::TransactionSetBuilder.segment_accessor(comp.id)
|
|
150
|
-
when Eddy::Schema::LoopSummary
|
|
151
|
-
if comp.repeat == 1
|
|
152
|
-
Eddy::Build::TransactionSetBuilder.segment_accessor(comp.id)
|
|
153
|
-
else
|
|
154
|
-
Eddy::Build::TransactionSetBuilder.loop_accessor(comp, self.summary.normalized_name)
|
|
155
|
-
end
|
|
156
141
|
end
|
|
157
142
|
end
|
|
158
143
|
return defs.join("\n\n")
|
|
@@ -166,7 +151,7 @@ module Eddy
|
|
|
166
151
|
return <<~RB.strip
|
|
167
152
|
# (see Eddy::Segments::#{upper})
|
|
168
153
|
#
|
|
169
|
-
# @yieldparam [Eddy::Segments::#{upper}]
|
|
154
|
+
# @yieldparam [Eddy::Segments::#{upper}]
|
|
170
155
|
# @return [Eddy::Segments::#{upper}]
|
|
171
156
|
def #{upper}()
|
|
172
157
|
yield(@#{lower}) if block_given?
|
|
@@ -175,20 +160,18 @@ module Eddy
|
|
|
175
160
|
RB
|
|
176
161
|
end
|
|
177
162
|
|
|
178
|
-
# @param summary [Eddy::
|
|
179
|
-
# @param
|
|
163
|
+
# @param summary [Eddy::Summary::Loop]
|
|
164
|
+
# @param t_set_id [String]
|
|
180
165
|
# @return [String]
|
|
181
|
-
def self.loop_accessor(summary,
|
|
182
|
-
upper = summary.id.upcase
|
|
183
|
-
lower = summary.id.downcase
|
|
166
|
+
def self.loop_accessor(summary, t_set_id)
|
|
184
167
|
return <<~RB.strip
|
|
185
|
-
# (see Eddy::TransactionSets::#{
|
|
168
|
+
# (see Eddy::TransactionSets::#{t_set_id}::Loops::#{summary.id.upcase}::Base)
|
|
186
169
|
#
|
|
187
|
-
#{
|
|
170
|
+
# @yieldparam [Eddy::TransactionSets::#{t_set_id}::Loops::#{summary.id.upcase}::Repeat]
|
|
188
171
|
# @return [void]
|
|
189
|
-
def
|
|
172
|
+
def #{summary.var_name.upcase}(&block)
|
|
190
173
|
if block_given?
|
|
191
|
-
|
|
174
|
+
@#{summary.var_name}.repeat(&block)
|
|
192
175
|
else
|
|
193
176
|
raise Eddy::Errors::Error, \"No block given in loop iteration\"
|
|
194
177
|
end
|
|
@@ -197,22 +180,6 @@ module Eddy
|
|
|
197
180
|
RB
|
|
198
181
|
end
|
|
199
182
|
|
|
200
|
-
# @param summary [Eddy::Schema::LoopSummary]
|
|
201
|
-
# @param t_set_name [String]
|
|
202
|
-
# @return [String]
|
|
203
|
-
def self.loop_components(summary, t_set_name)
|
|
204
|
-
comps = []
|
|
205
|
-
summary.components.each do |comp|
|
|
206
|
-
case comp
|
|
207
|
-
when Eddy::Schema::SegmentSummary
|
|
208
|
-
comps << "# @yieldparam [Eddy::Segments::#{comp.id.upcase}] #{comp.id.downcase}"
|
|
209
|
-
when Eddy::Schema::LoopSummary
|
|
210
|
-
comps << "# @yieldparam [Eddy::TransactionSets::#{t_set_name}::Loops::#{comp.id.upcase}] l_#{comp.id.downcase}"
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
return comps.join("\n")
|
|
214
|
-
end
|
|
215
|
-
|
|
216
183
|
end
|
|
217
184
|
end
|
|
218
185
|
end
|
data/lib/eddy/build.rb
CHANGED
|
@@ -2,7 +2,9 @@ require "fileutils"
|
|
|
2
2
|
|
|
3
3
|
require "eddy/build/elements/elements"
|
|
4
4
|
require "eddy/build/segment_builder"
|
|
5
|
-
require "eddy/build/
|
|
5
|
+
require "eddy/build/loop/base"
|
|
6
|
+
require "eddy/build/loop/repeat"
|
|
7
|
+
require "eddy/build/loop/render"
|
|
6
8
|
require "eddy/build/transaction_set_builder"
|
|
7
9
|
|
|
8
10
|
module Eddy
|
data/lib/eddy/errors.rb
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
module Eddy
|
|
2
|
+
# Exceptions raised by Eddy.
|
|
2
3
|
module Errors
|
|
3
4
|
# Exceptions raised by Eddy inherit from Error.
|
|
4
5
|
class Error < StandardError; end
|
|
5
6
|
|
|
6
7
|
# @!group Element Validation Errors
|
|
7
8
|
|
|
8
|
-
# Exception raised by descendents of {Eddy::Element::Base}.
|
|
9
|
+
# Exception raised by descendents of {Eddy::Models::Element::Base}.
|
|
9
10
|
class ElementValidationError < Error
|
|
10
|
-
# @return [Eddy::Element::Base] Element instance that raised the exception.
|
|
11
|
+
# @return [Eddy::Models::Element::Base] Element instance that raised the exception.
|
|
11
12
|
attr_accessor :element
|
|
12
13
|
# Argument that caused the exception when passed to `value=`. (if applicable)
|
|
13
14
|
# @return [Object]
|
|
14
15
|
attr_accessor :arg
|
|
15
16
|
|
|
16
17
|
# @param msg [String] ("")
|
|
17
|
-
# @param element [Eddy::Element::Base] (nil) Element instance that raised the exception.
|
|
18
|
+
# @param element [Eddy::Models::Element::Base] (nil) Element instance that raised the exception.
|
|
18
19
|
# @return [void]
|
|
19
20
|
def initialize(msg = "", element: nil)
|
|
20
21
|
self.element = element unless element.nil?
|
|
@@ -39,7 +40,7 @@ module Eddy
|
|
|
39
40
|
|
|
40
41
|
# Exception raised when `value` has been called before `value=` and no default value is set.
|
|
41
42
|
class ElementNilValueError < ElementValidationError
|
|
42
|
-
# @param element [Eddy::Element::Base] Element instance that raised the exception.
|
|
43
|
+
# @param element [Eddy::Models::Element::Base] Element instance that raised the exception.
|
|
43
44
|
# @param msg [String] (nil)
|
|
44
45
|
# @return [void]
|
|
45
46
|
def initialize(msg = "", element:)
|
|
@@ -51,9 +52,9 @@ module Eddy
|
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
# Exception raised when an invalid argument is passed to the `value=` method of an {Eddy::Element::Base} class.
|
|
55
|
+
# Exception raised when an invalid argument is passed to the `value=` method of an {Eddy::Models::Element::Base} class.
|
|
55
56
|
class TypeValidationError < ElementValidationError
|
|
56
|
-
# @param element [Eddy::Element::Base] Element instance that raised the exception.
|
|
57
|
+
# @param element [Eddy::Models::Element::Base] Element instance that raised the exception.
|
|
57
58
|
# @param arg [Object] Passed argument that caused the exception.
|
|
58
59
|
# @param msg [String] ("")
|
|
59
60
|
# @return [void]
|
|
@@ -66,24 +67,24 @@ module Eddy
|
|
|
66
67
|
super(msg)
|
|
67
68
|
end
|
|
68
69
|
|
|
69
|
-
# @param el [Eddy::Element::Base] Element instance that raised the exception.
|
|
70
|
+
# @param el [Eddy::Models::Element::Base] Element instance that raised the exception.
|
|
70
71
|
# @return [String]
|
|
71
72
|
def wanted_type(el)
|
|
72
73
|
return case el
|
|
73
|
-
when Eddy::Element::AN then "String"
|
|
74
|
-
when Eddy::Element::B then "String"
|
|
75
|
-
when Eddy::Element::DT then "Time"
|
|
76
|
-
when Eddy::Element::TM then "Time"
|
|
77
|
-
when Eddy::Element::N then "Float or Integer"
|
|
78
|
-
when Eddy::Element::R then "Float or Integer"
|
|
74
|
+
when Eddy::Models::Element::AN then "String"
|
|
75
|
+
when Eddy::Models::Element::B then "String"
|
|
76
|
+
when Eddy::Models::Element::DT then "Time"
|
|
77
|
+
when Eddy::Models::Element::TM then "Time"
|
|
78
|
+
when Eddy::Models::Element::N then "Float or Integer"
|
|
79
|
+
when Eddy::Models::Element::R then "Float or Integer"
|
|
79
80
|
end
|
|
80
81
|
end
|
|
81
82
|
end
|
|
82
83
|
|
|
83
|
-
# Exception raised when an invalid argument is passed to the `value=` method of an {Eddy::Element::Base} class.
|
|
84
|
+
# Exception raised when an invalid argument is passed to the `value=` method of an {Eddy::Models::Element::Base} class.
|
|
84
85
|
class LengthValidationError < ElementValidationError
|
|
85
86
|
|
|
86
|
-
# @param element [Eddy::Element::Base] Element instance that raised the exception.
|
|
87
|
+
# @param element [Eddy::Models::Element::Base] Element instance that raised the exception.
|
|
87
88
|
# @param arg [Object] Passed argument that caused the exception.
|
|
88
89
|
# @param msg [String] ("")
|
|
89
90
|
# @return [void]
|
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
module Eddy
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
module Models
|
|
3
|
+
module Element
|
|
4
|
+
# Alphanumeric string including special characters
|
|
5
|
+
class AN < Base
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
# @param min [Integer]
|
|
8
|
+
# @param max [Integer]
|
|
9
|
+
# @param req [String] (nil)
|
|
10
|
+
# @param ref [String] (nil)
|
|
11
|
+
# @param val [String] (nil)
|
|
12
|
+
# @return [void]
|
|
13
|
+
def initialize(
|
|
14
|
+
min:,
|
|
15
|
+
max:,
|
|
16
|
+
req: nil,
|
|
17
|
+
ref: nil,
|
|
18
|
+
val: nil
|
|
19
|
+
)
|
|
20
|
+
@type = "AN"
|
|
21
|
+
@min = min
|
|
22
|
+
@max = max
|
|
23
|
+
self.req = req
|
|
24
|
+
self.ref = ref
|
|
25
|
+
self.value = val
|
|
26
|
+
end
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
# @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
|
|
29
|
+
# @return [String]
|
|
30
|
+
def value()
|
|
31
|
+
if @val.nil?
|
|
32
|
+
case self.req
|
|
33
|
+
when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
|
|
34
|
+
when "O", "C" then return ""
|
|
35
|
+
else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
|
|
36
|
+
end
|
|
35
37
|
end
|
|
38
|
+
return @val.ljust(self.min)
|
|
36
39
|
end
|
|
37
|
-
return @val.ljust(self.min)
|
|
38
|
-
end
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
# @raise [Eddy::Errors::ElementValidationError]
|
|
42
|
+
# @param arg [String]
|
|
43
|
+
# @return [void]
|
|
44
|
+
def value=(arg)
|
|
45
|
+
if arg.nil?
|
|
46
|
+
@val = arg
|
|
47
|
+
return
|
|
48
|
+
end
|
|
49
|
+
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(String)
|
|
50
|
+
raise Eddy::Errors::LengthValidationError.new(element: self, arg: arg) if arg.length > self.max
|
|
45
51
|
@val = arg
|
|
46
|
-
return
|
|
47
52
|
end
|
|
48
|
-
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(String)
|
|
49
|
-
raise Eddy::Errors::LengthValidationError.new(element: self, arg: arg) if arg.length > self.max
|
|
50
|
-
@val = arg
|
|
51
|
-
end
|
|
52
53
|
|
|
54
|
+
end
|
|
53
55
|
end
|
|
54
56
|
end
|
|
55
57
|
end
|
|
@@ -1,53 +1,55 @@
|
|
|
1
1
|
module Eddy
|
|
2
|
-
module
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
module Models
|
|
3
|
+
module Element
|
|
4
|
+
# Binary Data.
|
|
5
|
+
# This type only occurs in the BIN segment.
|
|
6
|
+
#
|
|
7
|
+
# See:
|
|
8
|
+
#
|
|
9
|
+
# - [Maximum Length of Binary Data Element - X12 RFI](http://www.x12.org/rfis/Maximum%20Length%20of%20Binary%20Data%20Element.pdf)
|
|
10
|
+
class B < Base
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
# @param min [Integer]
|
|
13
|
+
# @param max [Integer]
|
|
14
|
+
# @param req [String] (nil)
|
|
15
|
+
# @param ref [String] (nil)
|
|
16
|
+
# @param val [String] (nil)
|
|
17
|
+
# @return [void]
|
|
18
|
+
def initialize(
|
|
19
|
+
min:,
|
|
20
|
+
max:,
|
|
21
|
+
req: nil,
|
|
22
|
+
ref: nil,
|
|
23
|
+
val: nil
|
|
24
|
+
)
|
|
25
|
+
@type = "B"
|
|
26
|
+
@min = min
|
|
27
|
+
@max = max
|
|
28
|
+
self.req = req
|
|
29
|
+
self.ref = ref
|
|
30
|
+
self.value = val
|
|
31
|
+
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
# @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
|
|
34
|
+
# @return [String<Binary>]
|
|
35
|
+
def value()
|
|
36
|
+
super()
|
|
37
|
+
if @val.nil?
|
|
38
|
+
case self.req
|
|
39
|
+
when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
|
|
40
|
+
when "O", "C" then return ""
|
|
41
|
+
else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
|
|
42
|
+
end
|
|
41
43
|
end
|
|
42
44
|
end
|
|
43
|
-
end
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
# @param _arg [Object] Whatever is to be assigned to `value`
|
|
47
|
+
# @return [void]
|
|
48
|
+
def value=(_arg)
|
|
49
|
+
super()
|
|
50
|
+
end
|
|
50
51
|
|
|
52
|
+
end
|
|
51
53
|
end
|
|
52
54
|
end
|
|
53
55
|
end
|