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,94 +1,96 @@
|
|
1
1
|
module Eddy
|
2
|
-
module
|
3
|
-
|
4
|
-
|
2
|
+
module Models
|
3
|
+
module Element
|
4
|
+
# Numeric (implies the number of decimal points, e.g., N2 would be two decimal positions)
|
5
|
+
class N < Base
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
# *Implied* number of decimal points.
|
8
|
+
# @return [Integer]
|
9
|
+
attr_accessor :decimals
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
11
|
+
# @param min [Integer]
|
12
|
+
# @param max [Integer]
|
13
|
+
# @param req [String] (nil)
|
14
|
+
# @param ref [String] (nil)
|
15
|
+
# @param val [Numeric] (nil)
|
16
|
+
# @param decimals [Integer] (0)
|
17
|
+
# @return [void]
|
18
|
+
def initialize(
|
19
|
+
min:,
|
20
|
+
max:,
|
21
|
+
req: nil,
|
22
|
+
ref: nil,
|
23
|
+
val: nil,
|
24
|
+
decimals: 0
|
25
|
+
)
|
26
|
+
@min = min
|
27
|
+
@max = max
|
28
|
+
self.req = req
|
29
|
+
self.ref = ref
|
30
|
+
self.decimals = decimals
|
31
|
+
self.value = val
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
# @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
|
35
|
+
# @return [String]
|
36
|
+
def value()
|
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
|
44
|
+
return self.process_value()
|
42
45
|
end
|
43
|
-
return self.process_value()
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
# @raise [Eddy::Errors::ElementValidationError]
|
48
|
+
# @param arg [Numeric]
|
49
|
+
# @return [void]
|
50
|
+
def value=(arg)
|
51
|
+
if arg.nil?
|
52
|
+
@val = nil
|
53
|
+
return
|
54
|
+
end
|
55
|
+
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Numeric)
|
56
|
+
@val = arg
|
53
57
|
end
|
54
|
-
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Numeric)
|
55
|
-
@val = arg
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
# @return [String]
|
60
|
+
def process_value()
|
61
|
+
return self.class.process_value(
|
62
|
+
@val,
|
63
|
+
self.decimals,
|
64
|
+
min: self.min,
|
65
|
+
max: self.max,
|
66
|
+
)
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
# Convert a Float or Integer value to a valid EDI string representation.
|
70
|
+
# [Stas Spiridonov is a wizard](https://github.com/spiridonov/baldr/blob/master/lib/baldr/types.rb#L43).
|
71
|
+
#
|
72
|
+
# @param val [Numeric] Original value.
|
73
|
+
# @param decimals [Integer] *Implied* number of decimal points.
|
74
|
+
# @param min [Integer] (1) Minimum length for a valid value.
|
75
|
+
# @param max [Integer] (nil) Maximum length for a valid value.
|
76
|
+
# @return [String]
|
77
|
+
def self.process_value(val, decimals, min: 1, max: nil)
|
78
|
+
case val
|
79
|
+
when Integer
|
80
|
+
if (val - val.floor) == 0
|
81
|
+
return sprintf("%0#{min}d", val.truncate)
|
82
|
+
else
|
83
|
+
return sprintf("%0#{min}d", val.round(2))
|
84
|
+
end
|
85
|
+
# return sprintf("%0#{min}d", val)
|
86
|
+
when Float
|
87
|
+
return (val * (10.0**decimals)).round.to_s
|
81
88
|
else
|
82
|
-
|
89
|
+
raise ArgumentError, "'val' must be a Float or an Integer."
|
83
90
|
end
|
84
|
-
# return sprintf("%0#{min}d", val)
|
85
|
-
when Float
|
86
|
-
return (val * (10.0**decimals)).round.to_s
|
87
|
-
else
|
88
|
-
raise ArgumentError, "'val' must be a Float or an Integer."
|
89
91
|
end
|
90
|
-
end
|
91
92
|
|
93
|
+
end
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
@@ -1,84 +1,86 @@
|
|
1
1
|
require "bigdecimal"
|
2
2
|
|
3
3
|
module Eddy
|
4
|
-
module
|
5
|
-
|
6
|
-
|
4
|
+
module Models
|
5
|
+
module Element
|
6
|
+
# Decimal Numeric (decimal points must be transmitted if used).
|
7
|
+
class R < Base
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
9
|
+
# @param min [Integer]
|
10
|
+
# @param max [Integer]
|
11
|
+
# @param req [String] (nil)
|
12
|
+
# @param ref [String] (nil)
|
13
|
+
# @param val [Numeric] (nil)
|
14
|
+
# @return [void]
|
15
|
+
def initialize(
|
16
|
+
min:,
|
17
|
+
max:,
|
18
|
+
req: nil,
|
19
|
+
ref: nil,
|
20
|
+
val: nil
|
21
|
+
)
|
22
|
+
@type = "R"
|
23
|
+
@min = min
|
24
|
+
@max = max
|
25
|
+
self.req = req
|
26
|
+
self.ref = ref
|
27
|
+
self.value = val
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
# @return [String]
|
31
|
+
def value()
|
32
|
+
if @val.nil?
|
33
|
+
case self.req
|
34
|
+
when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
|
35
|
+
when "O", "C" then return ""
|
36
|
+
else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
|
37
|
+
end
|
36
38
|
end
|
39
|
+
return process(@val)
|
37
40
|
end
|
38
|
-
return process(@val)
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
# @param arg [Numeric]
|
43
|
+
# @raise [ArgumentError] Unless passed a Numeric value.
|
44
|
+
# @return [void]
|
45
|
+
def value=(arg)
|
46
|
+
if arg.nil?
|
47
|
+
@val = arg
|
48
|
+
return
|
49
|
+
end
|
50
|
+
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Numeric)
|
46
51
|
@val = arg
|
47
|
-
return
|
48
52
|
end
|
49
|
-
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Numeric)
|
50
|
-
@val = arg
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
54
|
+
# Stringify a float value and trim to the element's `max` attribute.
|
55
|
+
#
|
56
|
+
# TODO: Use `sprintf` here?
|
57
|
+
#
|
58
|
+
# See:
|
59
|
+
#
|
60
|
+
# - [Ruby class types and case statements (Stack Overflow)](https://stackoverflow.com/questions/3908380/ruby-class-types-and-case-statements)
|
61
|
+
# - [Numbers and Class Hierarchy in Ruby (Medium)](https://medium.com/rubyinside/numbers-and-class-hierarchy-in-ruby-8c93c4749316)
|
62
|
+
#
|
63
|
+
# @param val [Numeric]
|
64
|
+
# @return [String]
|
65
|
+
def process(val)
|
66
|
+
case val
|
67
|
+
when Integer
|
68
|
+
return val.to_s.slice(0..self.max)
|
69
|
+
when Float
|
70
|
+
return val.to_s.slice(0..(self.max + 1))
|
71
|
+
when Complex
|
72
|
+
# TODO: Handle case
|
73
|
+
raise NotImplementedError
|
74
|
+
when Rational
|
75
|
+
# TODO: Handle case
|
76
|
+
raise NotImplementedError
|
77
|
+
when BigDecimal
|
78
|
+
# TODO: Handle case
|
79
|
+
raise NotImplementedError
|
80
|
+
end
|
79
81
|
end
|
80
|
-
end
|
81
82
|
|
83
|
+
end
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -1,113 +1,115 @@
|
|
1
1
|
require "time"
|
2
2
|
|
3
3
|
module Eddy
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
module Models
|
5
|
+
module Element
|
6
|
+
# Time in `HHMMSSDD` format.
|
7
|
+
# Time expressed in 24-hour clock time as follows:
|
8
|
+
# `HHMM`, or `HHMMSS`, or `HHMMSSD`, or `HHMMSSDD`
|
9
|
+
# where H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) and DD = decimal seconds;
|
10
|
+
# decimal seconds are expressed as follows:
|
11
|
+
# D = tenths (0-9) and DD = hundredths (00-99)
|
12
|
+
#
|
13
|
+
# Values for this type are generated from a *UTC* formatted [Time][time] object.
|
14
|
+
#
|
15
|
+
# [time]: https://ruby-doc.org/stdlib-2.6.5/libdoc/time/rdoc/Time.html
|
16
|
+
class TM < Base
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# Format for the date. Valid values: `:hhmm`, `:hhmmss`, `:hhmmssd`, and `:hhmmssdd`
|
19
|
+
# TODO: Decide if this should be an attr_accessor
|
20
|
+
# @return [Symbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>]
|
21
|
+
attr_reader :fmt
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
23
|
+
# TM elements require either a `fmt` value, or `min` and `max` values.
|
24
|
+
#
|
25
|
+
# @raise [ArgumentError] If an invalid format argument is passed.
|
26
|
+
# @param min [Integer] (nil)
|
27
|
+
# @param max [Integer] (nil)
|
28
|
+
# @param req [String] (nil)
|
29
|
+
# @param ref [String] (nil)
|
30
|
+
# @param val [Time] (nil)
|
31
|
+
# @param fmt [Symbol] (nil) Format for the date. Valid values: `:hhmm`, `:hhmmss`, `:hhmmssd`, and `:hhmmssdd`
|
32
|
+
# @return [void]
|
33
|
+
def initialize(
|
34
|
+
min: nil,
|
35
|
+
max: nil,
|
36
|
+
req: nil,
|
37
|
+
ref: nil,
|
38
|
+
val: nil,
|
39
|
+
fmt: nil
|
40
|
+
)
|
41
|
+
@type = "TM"
|
42
|
+
@min = min
|
43
|
+
@max = max
|
44
|
+
self.req = req
|
45
|
+
self.ref = ref
|
46
|
+
if fmt.nil?
|
47
|
+
raise ArgumentError, "TM elements require either a `fmt` value, or `min` and `max` values." if min.nil? || max.nil?
|
48
|
+
@fmt = determine_format()
|
49
|
+
else
|
50
|
+
self.fmt = fmt
|
51
|
+
end
|
52
|
+
self.value = val
|
50
53
|
end
|
51
|
-
self.value = val
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
# @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
|
56
|
+
# @return [String]
|
57
|
+
def value()
|
58
|
+
if @val.nil?
|
59
|
+
case self.req
|
60
|
+
when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
|
61
|
+
when "O", "C" then return ""
|
62
|
+
else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
case self.fmt
|
66
|
+
when :hhmm then return Eddy::Util::Time.hhmm(@val)
|
67
|
+
when :hhmmss then return Eddy::Util::Time.hhmmss(@val)
|
68
|
+
when :hhmmssd then return Eddy::Util::Time.hhmmssd(@val)
|
69
|
+
when :hhmmssdd then return Eddy::Util::Time.hhmmssdd(@val)
|
70
|
+
else raise Eddy::Errors::Error, "invalid fmt value for TM object"
|
62
71
|
end
|
63
72
|
end
|
64
|
-
case self.fmt
|
65
|
-
when :hhmm then return Eddy::Util::Time.hhmm(@val)
|
66
|
-
when :hhmmss then return Eddy::Util::Time.hhmmss(@val)
|
67
|
-
when :hhmmssd then return Eddy::Util::Time.hhmmssd(@val)
|
68
|
-
when :hhmmssdd then return Eddy::Util::Time.hhmmssdd(@val)
|
69
|
-
else raise Eddy::Errors::Error, "invalid fmt value for TM object"
|
70
|
-
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
# @raise [ElementValidationError] Unless passed a *UTC* formatted Time object.
|
75
|
+
# @param arg [Time] A *UTC* formatted `Time` object.
|
76
|
+
# @return [void]
|
77
|
+
def value=(arg)
|
78
|
+
if arg.nil?
|
79
|
+
@val = arg
|
80
|
+
return
|
81
|
+
end
|
82
|
+
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Time)
|
83
|
+
raise Eddy::Errors::ElementValidationError.new("Argument is not in UTC format", element: self) unless arg.utc?()
|
78
84
|
@val = arg
|
79
|
-
return
|
80
85
|
end
|
81
|
-
raise Eddy::Errors::TypeValidationError.new(element: self, arg: arg) unless arg.is_a?(Time)
|
82
|
-
raise Eddy::Errors::ElementValidationError.new("Argument is not in UTC format", element: self) unless arg.utc?()
|
83
|
-
@val = arg
|
84
|
-
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
# @param fmt [Symbol]
|
88
|
+
# @return [void]
|
89
|
+
def fmt=(fmt)
|
90
|
+
return if fmt.nil?
|
91
|
+
fmt = fmt.to_sym.downcase
|
92
|
+
raise ArgumentError unless accepted_formats.include?(fmt)
|
93
|
+
@fmt = fmt
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
# @return [Array<Symbol>]
|
97
|
+
def accepted_formats()
|
98
|
+
return [:hhmm, :hhmmss, :hhmmssd, :hhmmssdd]
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
# @return [Symbol]
|
102
|
+
def determine_format()
|
103
|
+
case self.max
|
104
|
+
when 4 then return :hhmm
|
105
|
+
when 6 then return :hhmmss
|
106
|
+
when 7 then return :hhmmssd
|
107
|
+
when 8 then return :hhmmssdd
|
108
|
+
else raise Eddy::Errors::Error, "unable to determine format for TM element"
|
109
|
+
end
|
108
110
|
end
|
109
|
-
end
|
110
111
|
|
112
|
+
end
|
111
113
|
end
|
112
114
|
end
|
113
115
|
end
|
data/lib/eddy/models/element.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
module Eddy
|
2
|
-
|
3
|
-
|
2
|
+
module Models
|
3
|
+
# A group of `Eddy::Models::TransactionSet::Base` classes.
|
4
|
+
class FunctionalGroup
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
# @return [String]
|
7
|
+
attr_reader :id
|
8
|
+
# @return [Eddy::Data::Store] Data store for the Interchange and all encompassed components.
|
9
|
+
attr_accessor :store
|
10
|
+
# An array of Transaction Set instances.
|
11
|
+
# @return [Array<Eddy::Models::TransactionSet>]
|
12
|
+
attr_accessor :transaction_sets
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
# @param store [Eddy::Data::Store]
|
15
|
+
# @param transaction_sets [Eddy::Models::TransactionSet]
|
16
|
+
# @return [void]
|
17
|
+
def initialize(store, *transaction_sets)
|
18
|
+
self.store = store
|
19
|
+
transaction_sets.flatten!
|
20
|
+
self.transaction_sets = transaction_sets || []
|
21
|
+
if self.transaction_sets.length == 0
|
22
|
+
raise ArgumentError, "At least one transaction set is required to create a functional group"
|
23
|
+
end
|
24
|
+
@id = self.transaction_sets.first.functional_group
|
22
25
|
end
|
23
|
-
@id = self.transaction_sets.first.functional_group
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
# @return [Array<#render>]
|
28
|
+
def render()
|
29
|
+
f_group_ctrl_num = Eddy::Data.new_functional_group_control_number(@id)
|
30
|
+
gs = Eddy::Segments::GS.new(store, f_group_ctrl_num, @id)
|
31
|
+
ge = Eddy::Segments::GE.new(store, f_group_ctrl_num, self.transaction_sets.length)
|
32
|
+
return [gs, self.transaction_sets, ge].flatten.map(&:render)
|
33
|
+
end
|
33
34
|
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|