eddy 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,58 +1,60 @@
|
|
1
1
|
module Eddy
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Models
|
3
|
+
# Top level EDI interchange.
|
4
|
+
class Interchange
|
5
|
+
# @return [Eddy::Data::Store] Data store for the Interchange.
|
6
|
+
attr_accessor :store
|
7
|
+
# @return [Array<Eddy::Models::TransactionSet>]
|
8
|
+
attr_accessor :transaction_sets
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
# @param store [Eddy::Data::Store] (Eddy::Data::Store.new)
|
11
|
+
# @return [void]
|
12
|
+
def initialize(store = Eddy::Data::Store.new())
|
13
|
+
self.store = store
|
14
|
+
self.transaction_sets = []
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
# @param _transaction_sets [Array<Eddy::Models::TransactionSet>]
|
18
|
+
# @return [Eddy::Models::Interchange]
|
19
|
+
def self.create(_transaction_sets)
|
20
|
+
itch = Eddy::Models::Interchange.new()
|
21
|
+
return itch
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
# @return [String]
|
25
|
+
def render()
|
26
|
+
ctrl_num = Eddy::Data.new_interchange_control_number()
|
27
|
+
f_groups = self.functional_groups()
|
28
|
+
sep = self.store.segment_separator
|
29
|
+
isa = Eddy::Segments::ISA.new(self.store, ctrl_num)
|
30
|
+
iea = Eddy::Segments::IEA.new(self.store, ctrl_num, f_groups.length)
|
31
|
+
yield(isa, iea) if block_given?
|
32
|
+
return [isa, f_groups, iea].flatten.map(&:render).join(sep) + sep
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
# @return [Array<Eddy::Models::FunctionalGroup>]
|
36
|
+
def functional_groups()
|
37
|
+
sorted_sets = {}
|
38
|
+
self.transaction_sets.each do |ts|
|
39
|
+
sorted_sets[ts.functional_group] ||= []
|
40
|
+
sorted_sets[ts.functional_group] << ts
|
41
|
+
end
|
42
|
+
return sorted_sets.map { |_, value| Eddy::Models::FunctionalGroup.new(self.store, *value) }
|
40
43
|
end
|
41
|
-
return sorted_sets.map { |_, value| Eddy::FunctionalGroup.new(self.store, *value) }
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
+
private
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
# @raise [ArgumentError] Unless `transaction_set` is a subclass of {Eddy::Models::TransactionSet}
|
48
|
+
# @param transaction_set [Eddy::Models::TransactionSet]
|
49
|
+
# @return [void]
|
50
|
+
def verify_transaction_set(transaction_set)
|
51
|
+
raise ArgumentError unless transaction_set < Eddy::Models::TransactionSet
|
52
|
+
raise ArgumentError unless transaction_set <= Eddy::Models::TransactionSet
|
53
|
+
raise ArgumentError unless transaction_set.ancestors.include?(Eddy::Models::TransactionSet)
|
54
|
+
raise ArgumentError unless transaction_set.superclass == Eddy::Models::TransactionSet
|
55
|
+
return nil
|
56
|
+
end
|
56
57
|
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
@@ -1,75 +1,74 @@
|
|
1
1
|
module Eddy
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
module Models
|
3
|
+
module Loop
|
4
|
+
# A repeated collection of Segments and/or other Loops.
|
5
|
+
#
|
6
|
+
# See:
|
7
|
+
#
|
8
|
+
# - [HL Loop Structure in TS 837 - X12 RFI](http://www.x12.org/rfis/HL%20Loop%20Structure%20in%20TS%20837.pdf)
|
9
|
+
# - [HL Segment Content - X12 RFI](http://www.x12.org/rfis/HL%20Segment%20Content.pdf)
|
10
|
+
class Base
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
12
|
+
# (Name) A unique string used to identify the Loop within its Transaction Set.
|
13
|
+
# This is not EDI standardized, any name will do.
|
14
|
+
# @return [String]
|
15
|
+
attr_reader :id
|
16
|
+
# Number of times a particular Loop may be repeated.
|
17
|
+
# @return [Integer]
|
18
|
+
attr_reader :repeat_limit
|
19
|
+
# Defines if/how the Loop is required.
|
20
|
+
# @return [String]
|
21
|
+
attr_reader :req
|
22
|
+
# Used to contain the components of a single loop iteration (or a single loop *repeat*).
|
23
|
+
# This value is a class, not an instance.
|
24
|
+
# @return [Eddy::Models::Loop::Repeat]
|
25
|
+
attr_reader :repeat_object
|
26
|
+
# @return [Eddy::Data::Store] Data passed down from a Transaction Set.
|
27
|
+
attr_reader :store
|
28
|
+
# An array of loop iterations.
|
29
|
+
# @return [Array<Array>]
|
30
|
+
attr_accessor :content
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
32
|
+
# All of a Loop's elements need to be declared in its constructor.
|
33
|
+
#
|
34
|
+
# @param store [Eddy::Data::Store]
|
35
|
+
# @param repeat_object [Eddy::Models::Loop::Repeat]
|
36
|
+
# @return [void]
|
37
|
+
def initialize(store, repeat_object)
|
38
|
+
@store = store
|
39
|
+
@repeat_object = repeat_object
|
40
|
+
@content = []
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
c.all_contents()
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
raise Eddy::Errors::RenderError
|
43
|
+
# Return all contained Segments in a single, flattened array.
|
44
|
+
#
|
45
|
+
# @return [Array<Eddy::Models::Segment>]
|
46
|
+
def all_contents()
|
47
|
+
contents = self.content.flatten.map do |c|
|
48
|
+
case c
|
49
|
+
when Eddy::Models::Loop::Repeat then c.all_contents()
|
50
|
+
when Eddy::Models::Loop::Base then c.all_contents()
|
51
|
+
when Eddy::Models::Segment then c
|
52
|
+
else raise Eddy::Errors::RenderError
|
53
|
+
end
|
55
54
|
end
|
55
|
+
return contents.flatten
|
56
56
|
end
|
57
|
-
return contents.flatten
|
58
|
-
end
|
59
57
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
58
|
+
# @param block [Block]
|
59
|
+
# @return [void]
|
60
|
+
def repeat(&block)
|
61
|
+
rep = self.repeat_object.new(self.store)
|
62
|
+
if block_given?
|
63
|
+
rep.repeat(&block)
|
64
|
+
else
|
65
|
+
raise Eddy::Errors::Error, "No block given in loop iteration"
|
66
|
+
end
|
67
|
+
self.content << rep
|
68
|
+
return nil
|
68
69
|
end
|
69
|
-
self.content << iteration
|
70
|
-
return nil
|
71
|
-
end
|
72
70
|
|
71
|
+
end
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -1,42 +1,54 @@
|
|
1
1
|
module Eddy
|
2
|
-
module
|
3
|
-
|
4
|
-
|
2
|
+
module Models
|
3
|
+
module Loop
|
4
|
+
# Data form a single loop iteration.
|
5
|
+
class Repeat
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
# An array of Segments and/or other Loops.
|
8
|
+
# This is used as a template to populate `content`.
|
9
|
+
# @return [Array<Eddy::Models::Segment, Eddy::Models::Loop::Base>]
|
10
|
+
attr_reader :components
|
11
|
+
# @return [Eddy::Data::Store] Data passed down from a Transaction Set.
|
12
|
+
attr_reader :store
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
# All of a Loop's elements need to be declared in its constructor.
|
15
|
+
#
|
16
|
+
# @param store [Eddy::Data::Store]
|
17
|
+
# @param components [Array<Eddy::Models::Loop, Eddy::Models::Segment>]
|
18
|
+
# @return [void]
|
19
|
+
def initialize(store, *components)
|
20
|
+
@store = store
|
21
|
+
components.flatten!
|
22
|
+
@components = components || []
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
c.all_contents()
|
31
|
-
|
32
|
-
c
|
25
|
+
# Return all contained Segments in a single, flattened array.
|
26
|
+
#
|
27
|
+
# @return [Array<Eddy::Models::Segment>]
|
28
|
+
def all_contents()
|
29
|
+
contents = self.components.flatten.map do |c|
|
30
|
+
case c
|
31
|
+
when Eddy::Models::Loop::Repeat then c.all_contents()
|
32
|
+
when Eddy::Models::Loop::Base then c.all_contents()
|
33
|
+
when Eddy::Models::Segment then c
|
34
|
+
else raise Eddy::Errors::RenderError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return contents.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
# @yieldparam [self] rep
|
41
|
+
# @return [self]
|
42
|
+
def repeat()
|
43
|
+
if block_given?
|
44
|
+
yield(self)
|
33
45
|
else
|
34
|
-
raise Eddy::Errors::
|
46
|
+
raise Eddy::Errors::Error, "No block given in loop iteration"
|
35
47
|
end
|
48
|
+
return self
|
36
49
|
end
|
37
|
-
return contents.flatten
|
38
|
-
end
|
39
50
|
|
51
|
+
end
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
data/lib/eddy/models/segment.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
module Eddy
|
2
|
-
|
3
|
-
|
2
|
+
module Models
|
3
|
+
# Base class for EDI Segments.
|
4
|
+
class Segment
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
# An alphanumeric code unique to each Segment type.
|
7
|
+
# @return [String]
|
8
|
+
attr_reader :id
|
9
|
+
# Short name of the Segment.
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :name
|
12
|
+
# @return [Array<Element>]
|
13
|
+
attr_accessor :elements
|
14
|
+
# @return [Eddy::Data::Store] Data passed down from a Transaction Set.
|
15
|
+
attr_accessor :store
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
# All of a Segment's elements need to be declared in its constructor.
|
18
|
+
#
|
19
|
+
# @param store [Eddy::Data::Store]
|
20
|
+
# @param elements [Eddy::Models::Element::Base]
|
21
|
+
# @return [void]
|
22
|
+
def initialize(store, *elements)
|
23
|
+
self.store = store
|
24
|
+
elements.flatten!
|
25
|
+
self.elements = elements || []
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
# @param separator [String] (self.store.element_separator) String used to delimit elements within a segment.
|
29
|
+
# @return [String]
|
30
|
+
def render(separator = self.store.element_separator)
|
31
|
+
segment = [self.id, self.elements.map(&:value)].join(separator)
|
32
|
+
return Eddy::Util.trim_delims_from_segment(segment, separator: separator)
|
33
|
+
end
|
33
34
|
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,100 +1,102 @@
|
|
1
1
|
module Eddy
|
2
|
-
|
3
|
-
|
2
|
+
module Models
|
3
|
+
# Base class for EDI Transaction Sets.
|
4
|
+
class TransactionSet
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
# @return [Integer]
|
7
|
+
ID = nil
|
8
|
+
# @return [String]
|
9
|
+
NAME = nil
|
10
|
+
# @return [String]
|
11
|
+
FUNCTIONAL_GROUP = nil
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# @return [Array<Segment, Loop>]
|
14
|
+
attr_accessor :components
|
15
|
+
# @return [Eddy::Data::Store] Container used to distribute state throughout an Interchange.
|
16
|
+
attr_accessor :store
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
# @param store [Eddy::Data::Store]
|
19
|
+
# @param components [Array<Segment, Loop>]
|
20
|
+
# @return [void]
|
21
|
+
def initialize(store, *components)
|
22
|
+
self.store = store
|
23
|
+
components.flatten!
|
24
|
+
self.components = components || []
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
# @return [String]
|
28
|
+
def id
|
29
|
+
return self.class::ID
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
# @return [String]
|
33
|
+
def self.id
|
34
|
+
return self::ID
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
# @return [String]
|
38
|
+
def functional_group
|
39
|
+
return self.class::FUNCTIONAL_GROUP
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
# @return [String]
|
43
|
+
def self.functional_group
|
44
|
+
return self::FUNCTIONAL_GROUP
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
# @return [String]
|
48
|
+
def name
|
49
|
+
return self.class::NAME
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
# @return [String]
|
53
|
+
def self.name
|
54
|
+
return self::NAME
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
# Add `ST` and `SE` segments to the `components` array.
|
58
|
+
#
|
59
|
+
# @param control_number [Integer] (Eddy::Data.new_transaction_set_control_number())
|
60
|
+
# @return [void]
|
61
|
+
def add_envelope(control_number = Eddy::Data.new_transaction_set_control_number(self.id))
|
62
|
+
st = Eddy::Segments::ST.new(self.store)
|
63
|
+
st.TransactionSetIdentifierCode = self.id
|
64
|
+
st.TransactionSetControlNumber = control_number
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
se = Eddy::Segments::SE.new(self.store)
|
67
|
+
se.NumberOfIncludedSegments = self.all_components.length + 2
|
68
|
+
se.TransactionSetControlNumber = control_number
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
self.components.unshift(st)
|
71
|
+
self.components.push(se)
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
# This shouldn't be used.
|
75
|
+
# An Interchange or FunctionalGroup should call `all_components` and render those itself.
|
76
|
+
#
|
77
|
+
# @param s_sep [String] (self.store.segment_separator)
|
78
|
+
# @return [String]
|
79
|
+
def render(s_sep = self.store.segment_separator)
|
80
|
+
add_envelope()
|
81
|
+
return self.all_components.map { |s| s.render(self.store.element_separator) }.join(s_sep)
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
84
|
+
# Return all contained Segments in a single, flattened array.
|
85
|
+
#
|
86
|
+
# @return [Array<Eddy::Models::Segment>]
|
87
|
+
def all_components()
|
88
|
+
comps = self.components.map do |c|
|
89
|
+
if c.is_a?(Eddy::Models::Loop::Base)
|
90
|
+
c.all_contents()
|
91
|
+
elsif c.is_a?(Eddy::Models::Segment)
|
92
|
+
c
|
93
|
+
else
|
94
|
+
raise Eddy::Errors::RenderError
|
95
|
+
end
|
94
96
|
end
|
97
|
+
return comps.flatten
|
95
98
|
end
|
96
|
-
return comps.flatten
|
97
|
-
end
|
98
99
|
|
100
|
+
end
|
99
101
|
end
|
100
102
|
end
|
data/lib/eddy/models.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "eddy/models/element"
|
2
2
|
require "eddy/models/segment"
|
3
3
|
require "eddy/models/loop/base"
|
4
|
-
|
4
|
+
require "eddy/models/loop/repeat"
|
5
5
|
require "eddy/models/transaction_set"
|
6
6
|
require "eddy/models/functional_group"
|
7
7
|
require "eddy/models/interchange"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Eddy
|
2
|
-
module
|
2
|
+
module Summary
|
3
3
|
# An individual EDI Data Element. Used in Companion Guides to define requirements for a Segment.
|
4
|
-
class
|
4
|
+
class Element
|
5
5
|
|
6
6
|
# Indicates the order in which Elements should appear in their Segment.
|
7
7
|
# @return [String]
|
@@ -37,7 +37,7 @@ module Eddy
|
|
37
37
|
# @param params [Hash] ({})
|
38
38
|
# @return [self]
|
39
39
|
def self.create(params = {})
|
40
|
-
summary = new()
|
40
|
+
summary = self.new()
|
41
41
|
summary.ref = params[:ref]&.strip
|
42
42
|
summary.id = params[:id]&.strip
|
43
43
|
summary.name = params[:name]&.strip
|