eddy 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +23 -4
  4. data/Gemfile.lock +1 -1
  5. data/README.md +1 -1
  6. data/lib/definitions/elements/generated/1005.hierarchical_structure_code.rb +1 -1
  7. data/lib/definitions/elements/generated/1019.invoice_type_code.rb +1 -1
  8. data/lib/definitions/elements/generated/103.packaging_code.rb +1 -1
  9. data/lib/definitions/elements/generated/1166.contract_type_code.rb +1 -1
  10. data/lib/definitions/elements/generated/1232.purchase_category.rb +1 -1
  11. data/lib/definitions/elements/generated/127.reference_identification.rb +1 -1
  12. data/lib/definitions/elements/generated/128.reference_identification_qualifier.rb +1 -1
  13. data/lib/definitions/elements/generated/1300.service_promotion_allowance_or_charge_code.rb +1 -1
  14. data/lib/definitions/elements/generated/1301.agency_service_promotion_allowance_or_charge_code.rb +1 -1
  15. data/lib/definitions/elements/generated/133.routing_sequence_code.rb +1 -1
  16. data/lib/definitions/elements/generated/166.address_information.rb +1 -1
  17. data/lib/definitions/elements/generated/183.volume.rb +1 -1
  18. data/lib/definitions/elements/generated/187.weight_qualifier.rb +1 -1
  19. data/lib/definitions/elements/generated/19.city_name.rb +1 -1
  20. data/lib/definitions/elements/generated/206.equipment_initial.rb +1 -1
  21. data/lib/definitions/elements/generated/207.equipment_number.rb +1 -1
  22. data/lib/definitions/elements/generated/212.unit_price.rb +1 -1
  23. data/lib/definitions/elements/generated/22.commodity_code.rb +1 -1
  24. data/lib/definitions/elements/generated/23.commodity_code_qualifier.rb +1 -1
  25. data/lib/definitions/elements/generated/234.product_service_id.rb +1 -1
  26. data/lib/definitions/elements/generated/235.product_service_id_qualifier.rb +1 -1
  27. data/lib/definitions/elements/generated/236.price_identifier_code.rb +1 -1
  28. data/lib/definitions/elements/generated/248.allowance_or_charge_indicator.rb +1 -1
  29. data/lib/definitions/elements/generated/26.country_code.rb +1 -1
  30. data/lib/definitions/elements/generated/284.service_level_code.rb +1 -1
  31. data/lib/definitions/elements/generated/324.purchase_order_number.rb +1 -1
  32. data/lib/definitions/elements/generated/326.request_reference_number.rb +1 -1
  33. data/lib/definitions/elements/generated/327.change_order_sequence_number.rb +1 -1
  34. data/lib/definitions/elements/generated/328.release_number.rb +1 -1
  35. data/lib/definitions/elements/generated/330.quantity_ordered.rb +1 -1
  36. data/lib/definitions/elements/generated/347.hash_total.rb +1 -1
  37. data/lib/definitions/elements/generated/349.item_description_type.rb +1 -1
  38. data/lib/definitions/elements/generated/352.description.rb +1 -1
  39. data/lib/definitions/elements/generated/353.transaction_set_purpose_code.rb +1 -1
  40. data/lib/definitions/elements/generated/354.number_of_line_items.rb +1 -1
  41. data/lib/definitions/elements/generated/355.unit_or_basis_for_measurement_code.rb +1 -1
  42. data/lib/definitions/elements/generated/358.quantity_invoiced.rb +1 -1
  43. data/lib/definitions/elements/generated/367.contract_number.rb +1 -1
  44. data/lib/definitions/elements/generated/368.shipment_order_status_code.rb +1 -1
  45. data/lib/definitions/elements/generated/374.date_time_qualifier.rb +1 -1
  46. data/lib/definitions/elements/generated/380.quantity.rb +1 -1
  47. data/lib/definitions/elements/generated/382.number_of_units_shipped.rb +1 -1
  48. data/lib/definitions/elements/generated/387.routing.rb +1 -1
  49. data/lib/definitions/elements/generated/396.shipment_identification.rb +1 -1
  50. data/lib/definitions/elements/generated/559.agency_qualifier_code.rb +1 -1
  51. data/lib/definitions/elements/generated/587.acknowledgment_type.rb +1 -1
  52. data/lib/definitions/elements/generated/610.amount.rb +1 -1
  53. data/lib/definitions/elements/generated/639.basis_of_unit_price_code.rb +1 -1
  54. data/lib/definitions/elements/generated/640.transaction_type_code.rb +1 -1
  55. data/lib/definitions/elements/generated/646.quantity_shipped_to_date.rb +1 -1
  56. data/lib/definitions/elements/generated/648.price_multiplier_qualifier.rb +1 -1
  57. data/lib/definitions/elements/generated/649.multiplier.rb +1 -1
  58. data/lib/definitions/elements/generated/66.identification_code_qualifier.rb +1 -1
  59. data/lib/definitions/elements/generated/662.relationship_code.rb +1 -1
  60. data/lib/definitions/elements/generated/668.line_item_status_code.rb +1 -1
  61. data/lib/definitions/elements/generated/67.identification_code.rb +1 -1
  62. data/lib/definitions/elements/generated/687.class_of_trade_code.rb +1 -1
  63. data/lib/definitions/elements/generated/750.product_process_characteristic_code.rb +1 -1
  64. data/lib/definitions/elements/generated/751.product_description_code.rb +1 -1
  65. data/lib/definitions/elements/generated/76.invoice_number.rb +1 -1
  66. data/lib/definitions/elements/generated/782.monetary_amount.rb +1 -1
  67. data/lib/definitions/elements/generated/786.security_level_code.rb +1 -1
  68. data/lib/definitions/elements/generated/79.lading_description.rb +1 -1
  69. data/lib/definitions/elements/generated/80.lading_quantity.rb +1 -1
  70. data/lib/definitions/elements/generated/87.marks_and_numbers.rb +1 -1
  71. data/lib/definitions/elements/generated/88.marks_and_numbers_qualifier.rb +1 -1
  72. data/lib/definitions/elements/generated/91.transportation_method_type_code.rb +1 -1
  73. data/lib/definitions/elements/generated/92.purchase_order_type_code.rb +1 -1
  74. data/lib/definitions/elements/generated/98.entity_identifier_code.rb +1 -1
  75. data/lib/definitions/elements/manual/116.postal_code.rb +1 -1
  76. data/lib/definitions/elements/manual/124.application_receivers_code.rb +1 -1
  77. data/lib/definitions/elements/manual/140.standard_carrier_alpha_code.rb +1 -1
  78. data/lib/definitions/elements/manual/142.application_senders_code.rb +1 -1
  79. data/lib/definitions/elements/manual/143.transaction_set_identifier_code.rb +1 -1
  80. data/lib/definitions/elements/manual/156.state_or_province_code.rb +1 -1
  81. data/lib/definitions/elements/manual/28.group_control_number.rb +1 -1
  82. data/lib/definitions/elements/manual/329.transactional_set_control_number.rb +2 -2
  83. data/lib/definitions/elements/manual/337.time.rb +1 -1
  84. data/lib/definitions/elements/manual/350.assigned_identification.rb +1 -1
  85. data/lib/definitions/elements/manual/373.date.rb +1 -1
  86. data/lib/definitions/elements/manual/455.responsible_agency_code.rb +1 -1
  87. data/lib/definitions/elements/manual/479.functional_identifier_code.rb +1 -1
  88. data/lib/definitions/elements/manual/480.version_release_industry_identifier_code.rb +1 -1
  89. data/lib/definitions/elements/manual/784.length_of_binary_data.rb +1 -1
  90. data/lib/definitions/elements/manual/785.binary_data.rb +1 -1
  91. data/lib/definitions/elements/manual/96.number_of_included_segments.rb +1 -1
  92. data/lib/definitions/elements/manual/97.number_of_transaction_sets_included.rb +1 -1
  93. data/lib/definitions/elements/manual/hl/628.hierarchical_id_number.rb +1 -1
  94. data/lib/definitions/elements/manual/hl/734.hierarchical_parent_id_number.rb +1 -1
  95. data/lib/definitions/elements/manual/hl/735.hierarchical_level_code.rb +1 -1
  96. data/lib/definitions/elements/manual/hl/736.hierarchical_child_code.rb +1 -1
  97. data/lib/definitions/elements/manual/i/I01.authorization_information_qualifier.rb +1 -1
  98. data/lib/definitions/elements/manual/i/I02.authorization_information.rb +1 -1
  99. data/lib/definitions/elements/manual/i/I03.security_information_qualifier.rb +1 -1
  100. data/lib/definitions/elements/manual/i/I04.security_information.rb +1 -1
  101. data/lib/definitions/elements/manual/i/I05.interchange_id_qualifier.rb +1 -1
  102. data/lib/definitions/elements/manual/i/I06.interchange_sender_id.rb +1 -1
  103. data/lib/definitions/elements/manual/i/I07.interchange_receiver_id.rb +1 -1
  104. data/lib/definitions/elements/manual/i/I08.interchange_date.rb +1 -1
  105. data/lib/definitions/elements/manual/i/I09.interchange_time.rb +1 -1
  106. data/lib/definitions/elements/manual/i/I10.interchange_control_standards_identifier.rb +1 -1
  107. data/lib/definitions/elements/manual/i/I11.interchange_control_version_number.rb +1 -1
  108. data/lib/definitions/elements/manual/i/I12.interchange_control_number.rb +1 -1
  109. data/lib/definitions/elements/manual/i/I13.acknowledgment_requested.rb +1 -1
  110. data/lib/definitions/elements/manual/i/I14.usage_indicator.rb +1 -1
  111. data/lib/definitions/elements/manual/i/I15.component_element_separator.rb +1 -1
  112. data/lib/definitions/elements/manual/i/I16.number_of_included_functional_groups.rb +1 -1
  113. data/lib/definitions/elements/manual/misc/81.weight.rb +1 -1
  114. data/lib/definitions/elements/manual/misc/93.name.rb +1 -1
  115. data/lib/definitions/segments/generated/ack.rb +1 -1
  116. data/lib/definitions/segments/generated/bak.rb +1 -1
  117. data/lib/definitions/segments/generated/beg.rb +1 -1
  118. data/lib/definitions/segments/generated/big.rb +1 -1
  119. data/lib/definitions/segments/generated/bsn.rb +1 -1
  120. data/lib/definitions/segments/generated/cad.rb +1 -1
  121. data/lib/definitions/segments/generated/ctp.rb +1 -1
  122. data/lib/definitions/segments/generated/ctt.rb +1 -1
  123. data/lib/definitions/segments/generated/dtm.rb +1 -1
  124. data/lib/definitions/segments/generated/it1.rb +1 -1
  125. data/lib/definitions/segments/generated/lin.rb +1 -1
  126. data/lib/definitions/segments/generated/man.rb +1 -1
  127. data/lib/definitions/segments/generated/n1.rb +1 -1
  128. data/lib/definitions/segments/generated/n3.rb +1 -1
  129. data/lib/definitions/segments/generated/n4.rb +1 -1
  130. data/lib/definitions/segments/generated/pid.rb +1 -1
  131. data/lib/definitions/segments/generated/po1.rb +1 -1
  132. data/lib/definitions/segments/generated/prf.rb +1 -1
  133. data/lib/definitions/segments/generated/ref.rb +1 -1
  134. data/lib/definitions/segments/generated/sac.rb +1 -1
  135. data/lib/definitions/segments/generated/sln.rb +1 -1
  136. data/lib/definitions/segments/generated/sn1.rb +1 -1
  137. data/lib/definitions/segments/generated/td1.rb +1 -1
  138. data/lib/definitions/segments/generated/td5.rb +1 -1
  139. data/lib/definitions/segments/generated/tds.rb +1 -1
  140. data/lib/definitions/segments/manual/envelopes/ge.rb +1 -1
  141. data/lib/definitions/segments/manual/envelopes/gs.rb +1 -1
  142. data/lib/definitions/segments/manual/envelopes/iea.rb +1 -1
  143. data/lib/definitions/segments/manual/envelopes/isa.rb +1 -1
  144. data/lib/definitions/segments/manual/envelopes/se.rb +1 -1
  145. data/lib/definitions/segments/manual/envelopes/st.rb +1 -1
  146. data/lib/definitions/segments/manual/hl.rb +1 -1
  147. data/lib/definitions/segments/manual/n2.rb +1 -1
  148. data/lib/definitions/transaction_sets/manual/810/810.rb +19 -24
  149. data/lib/definitions/transaction_sets/manual/810/loops/it1.rb +92 -0
  150. data/lib/definitions/transaction_sets/manual/810/loops/n1.rb +72 -0
  151. data/lib/definitions/transaction_sets/manual/810/loops/pid.rb +45 -0
  152. data/lib/definitions/transaction_sets/manual/810/loops/sac.rb +45 -0
  153. data/lib/definitions/transaction_sets/manual/850/850.rb +12 -14
  154. data/lib/definitions/transaction_sets/manual/850/loops/n1.rb +74 -0
  155. data/lib/definitions/transaction_sets/manual/850/loops/po1.rb +51 -0
  156. data/lib/definitions/transaction_sets/manual/855/855.rb +11 -15
  157. data/lib/definitions/transaction_sets/manual/855/loops/ack.rb +45 -0
  158. data/lib/definitions/transaction_sets/manual/855/loops/n1.rb +72 -0
  159. data/lib/definitions/transaction_sets/manual/855/loops/pid.rb +45 -0
  160. data/lib/definitions/transaction_sets/manual/855/loops/po1.rb +80 -0
  161. data/lib/definitions/transaction_sets/manual/856/856.rb +8 -16
  162. data/lib/definitions/transaction_sets/manual/856/loops/hl_item.rb +87 -0
  163. data/lib/definitions/transaction_sets/manual/856/loops/hl_order.rb +59 -0
  164. data/lib/definitions/transaction_sets/manual/856/loops/hl_shipment.rb +159 -0
  165. data/lib/definitions/transaction_sets/manual/856/loops/hl_tare.rb +59 -0
  166. data/lib/definitions/transaction_sets/manual/856/loops/n1.rb +71 -0
  167. data/lib/definitions/transaction_sets/manual/856/loops/sln.rb +44 -0
  168. data/lib/eddy/build/elements/element.rb +5 -5
  169. data/lib/eddy/build/elements/elements.rb +3 -3
  170. data/lib/eddy/build/elements/id.rb +1 -1
  171. data/lib/eddy/build/elements/n.rb +1 -1
  172. data/lib/eddy/build/loop/base.rb +49 -0
  173. data/lib/eddy/build/loop/render.rb +18 -0
  174. data/lib/eddy/build/loop/repeat.rb +86 -0
  175. data/lib/eddy/build/segment_builder.rb +14 -9
  176. data/lib/eddy/build/transaction_set_builder.rb +60 -93
  177. data/lib/eddy/build.rb +3 -1
  178. data/lib/eddy/errors.rb +16 -15
  179. data/lib/eddy/models/element/an.rb +45 -43
  180. data/lib/eddy/models/element/b.rb +45 -43
  181. data/lib/eddy/models/element/base.rb +102 -100
  182. data/lib/eddy/models/element/composite.rb +5 -3
  183. data/lib/eddy/models/element/dt.rb +82 -80
  184. data/lib/eddy/models/element/id.rb +47 -45
  185. data/lib/eddy/models/element/n.rb +79 -77
  186. data/lib/eddy/models/element/r.rb +70 -68
  187. data/lib/eddy/models/element/tm.rb +95 -93
  188. data/lib/eddy/models/element.rb +4 -2
  189. data/lib/eddy/models/functional_group.rb +29 -27
  190. data/lib/eddy/models/interchange.rb +49 -47
  191. data/lib/eddy/models/loop/base.rb +62 -63
  192. data/lib/eddy/models/loop/repeat.rb +43 -31
  193. data/lib/eddy/models/segment.rb +30 -28
  194. data/lib/eddy/models/transaction_set.rb +82 -80
  195. data/lib/eddy/models.rb +1 -1
  196. data/lib/eddy/{schema/element_summary.rb → summary/element.rb} +3 -3
  197. data/lib/eddy/{schema/loop_summary.rb → summary/loop.rb} +53 -16
  198. data/lib/eddy/{schema/segment_summary.rb → summary/segment.rb} +14 -6
  199. data/lib/eddy/{schema/transaction_set_summary.rb → summary/transaction_set.rb} +14 -13
  200. data/lib/eddy/{schema → summary}/validate.rb +1 -1
  201. data/lib/eddy/summary.rb +10 -0
  202. data/lib/eddy/util.rb +5 -5
  203. data/lib/eddy/version.rb +1 -1
  204. data/lib/eddy.rb +1 -7
  205. data/todo.txt +3 -5
  206. metadata +28 -13
  207. data/lib/definitions/transaction_sets/manual/810/loops.rb +0 -109
  208. data/lib/definitions/transaction_sets/manual/850/loops.rb +0 -58
  209. data/lib/definitions/transaction_sets/manual/855/loops.rb +0 -104
  210. data/lib/definitions/transaction_sets/manual/856/loops.rb +0 -155
  211. data/lib/eddy/build/loop_builder.rb +0 -93
@@ -1,94 +1,96 @@
1
1
  module Eddy
2
- module Element
3
- # Numeric (implies the number of decimal points, e.g., N2 would be two decimal positions)
4
- class N < Base
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
- # *Implied* number of decimal points.
7
- # @return [Integer]
8
- attr_accessor :decimals
7
+ # *Implied* number of decimal points.
8
+ # @return [Integer]
9
+ attr_accessor :decimals
9
10
 
10
- # @param min [Integer]
11
- # @param max [Integer]
12
- # @param req [String] (nil)
13
- # @param ref [String] (nil)
14
- # @param val [Numeric] (nil)
15
- # @param decimals [Integer] (0)
16
- # @return [void]
17
- def initialize(
18
- min:,
19
- max:,
20
- req: nil,
21
- ref: nil,
22
- val: nil,
23
- decimals: 0
24
- )
25
- @min = min
26
- @max = max
27
- self.req = req
28
- self.ref = ref
29
- self.decimals = decimals
30
- self.value = val
31
- end
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
- # @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
34
- # @return [String]
35
- def value()
36
- if @val.nil?
37
- case self.req
38
- when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
39
- when "O", "C" then return ""
40
- else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
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
- # @raise [Eddy::Errors::ElementValidationError]
47
- # @param arg [Numeric]
48
- # @return [void]
49
- def value=(arg)
50
- if arg.nil?
51
- @val = nil
52
- return
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
- # @return [String]
59
- def process_value()
60
- return self.class.process_value(
61
- @val,
62
- self.decimals,
63
- min: self.min,
64
- max: self.max,
65
- )
66
- end
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
- # Convert a Float or Integer value to a valid EDI string representation.
69
- # [Stas Spiridonov is a wizard](https://github.com/spiridonov/baldr/blob/master/lib/baldr/types.rb#L43).
70
- #
71
- # @param val [Numeric] Original value.
72
- # @param decimals [Integer] *Implied* number of decimal points.
73
- # @param min [Integer] (1) Minimum length for a valid value.
74
- # @param max [Integer] (nil) Maximum length for a valid value.
75
- # @return [String]
76
- def self.process_value(val, decimals, min: 1, max: nil)
77
- case val
78
- when Integer
79
- if (val - val.floor) == 0
80
- return sprintf("%0#{min}d", val.truncate)
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
- return sprintf("%0#{min}d", val.round(2))
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 Element
5
- # Decimal Numeric (decimal points must be transmitted if used).
6
- class R < Base
4
+ module Models
5
+ module Element
6
+ # Decimal Numeric (decimal points must be transmitted if used).
7
+ class R < Base
7
8
 
8
- # @param min [Integer]
9
- # @param max [Integer]
10
- # @param req [String] (nil)
11
- # @param ref [String] (nil)
12
- # @param val [Numeric] (nil)
13
- # @return [void]
14
- def initialize(
15
- min:,
16
- max:,
17
- req: nil,
18
- ref: nil,
19
- val: nil
20
- )
21
- @type = "R"
22
- @min = min
23
- @max = max
24
- self.req = req
25
- self.ref = ref
26
- self.value = val
27
- end
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
- # @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}"
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
- # @param arg [Numeric]
42
- # @raise [ArgumentError] Unless passed a Numeric value.
43
- # @return [void]
44
- def value=(arg)
45
- if arg.nil?
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
- # Stringify a float value and trim to the element's `max` attribute.
54
- #
55
- # TODO: Use `sprintf` here?
56
- #
57
- # See:
58
- #
59
- # - [Ruby class types and case statements (Stack Overflow)](https://stackoverflow.com/questions/3908380/ruby-class-types-and-case-statements)
60
- # - [Numbers and Class Hierarchy in Ruby (Medium)](https://medium.com/rubyinside/numbers-and-class-hierarchy-in-ruby-8c93c4749316)
61
- #
62
- # @param val [Numeric]
63
- # @return [String]
64
- def process(val)
65
- case val
66
- when Integer
67
- return val.to_s.slice(0..self.max)
68
- when Float
69
- return val.to_s.slice(0..(self.max + 1))
70
- when Complex
71
- # TODO: Handle case
72
- raise NotImplementedError
73
- when Rational
74
- # TODO: Handle case
75
- raise NotImplementedError
76
- when BigDecimal
77
- # TODO: Handle case
78
- raise NotImplementedError
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 Element
5
- # Time in `HHMMSSDD` format.
6
- # Time expressed in 24-hour clock time as follows:
7
- # `HHMM`, or `HHMMSS`, or `HHMMSSD`, or `HHMMSSDD`
8
- # where H = hours (00-23), M = minutes (00-59), S = integer seconds (00-59) and DD = decimal seconds;
9
- # decimal seconds are expressed as follows:
10
- # D = tenths (0-9) and DD = hundredths (00-99)
11
- #
12
- # Values for this type are generated from a *UTC* formatted [Time][time] object.
13
- #
14
- # [time]: https://ruby-doc.org/stdlib-2.6.5/libdoc/time/rdoc/Time.html
15
- class TM < Base
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
- # Format for the date. Valid values: `:hhmm`, `:hhmmss`, `:hhmmssd`, and `:hhmmssdd`
18
- # TODO: Decide if this should be an attr_accessor
19
- # @return [Symbol<:hhmm, :hhmmss, :hhmmssd, :hhmmssdd>]
20
- attr_reader :fmt
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
- # TM elements require either a `fmt` value, or `min` and `max` values.
23
- #
24
- # @raise [ArgumentError] If an invalid format argument is passed.
25
- # @param min [Integer] (nil)
26
- # @param max [Integer] (nil)
27
- # @param req [String] (nil)
28
- # @param ref [String] (nil)
29
- # @param val [Time] (nil)
30
- # @param fmt [Symbol] (nil) Format for the date. Valid values: `:hhmm`, `:hhmmss`, `:hhmmssd`, and `:hhmmssdd`
31
- # @return [void]
32
- def initialize(
33
- min: nil,
34
- max: nil,
35
- req: nil,
36
- ref: nil,
37
- val: nil,
38
- fmt: nil
39
- )
40
- @type = "TM"
41
- @min = min
42
- @max = max
43
- self.req = req
44
- self.ref = ref
45
- if fmt.nil?
46
- raise ArgumentError, "TM elements require either a `fmt` value, or `min` and `max` values." if min.nil? || max.nil?
47
- @fmt = determine_format()
48
- else
49
- self.fmt = fmt
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
- # @raise [Eddy::Errors::ElementNilValueError] If the element is required and no value has been set.
55
- # @return [String]
56
- def value()
57
- if @val.nil?
58
- case self.req
59
- when "M" then raise Eddy::Errors::ElementNilValueError.new(element: self)
60
- when "O", "C" then return ""
61
- else raise Eddy::Errors::Error, "Invalid req value: #{self.req}"
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
- # @raise [ElementValidationError] Unless passed a *UTC* formatted Time object.
74
- # @param arg [Time] A *UTC* formatted `Time` object.
75
- # @return [void]
76
- def value=(arg)
77
- if arg.nil?
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
- # @param fmt [Symbol]
87
- # @return [void]
88
- def fmt=(fmt)
89
- return if fmt.nil?
90
- fmt = fmt.to_sym.downcase
91
- raise ArgumentError unless accepted_formats.include?(fmt)
92
- @fmt = fmt
93
- end
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
- # @return [Array<Symbol>]
96
- def accepted_formats()
97
- return [:hhmm, :hhmmss, :hhmmssd, :hhmmssdd]
98
- end
96
+ # @return [Array<Symbol>]
97
+ def accepted_formats()
98
+ return [:hhmm, :hhmmss, :hhmmssd, :hhmmssdd]
99
+ end
99
100
 
100
- # @return [Symbol]
101
- def determine_format()
102
- case self.max
103
- when 4 then return :hhmm
104
- when 6 then return :hhmmss
105
- when 7 then return :hhmmssd
106
- when 8 then return :hhmmssdd
107
- else raise Eddy::Errors::Error, "unable to determine format for TM element"
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
@@ -1,6 +1,8 @@
1
1
  module Eddy
2
- # Base types for EDI Data Elements.
3
- module Element; end
2
+ module Models
3
+ # Base types for EDI Data Elements.
4
+ module Element; end
5
+ end
4
6
  end
5
7
 
6
8
  require "eddy/models/element/base"
@@ -1,35 +1,37 @@
1
1
  module Eddy
2
- # A group of `Eddy::TransactionSet::Base` classes.
3
- class FunctionalGroup
2
+ module Models
3
+ # A group of `Eddy::Models::TransactionSet::Base` classes.
4
+ class FunctionalGroup
4
5
 
5
- # @return [String]
6
- attr_reader :id
7
- # @return [Eddy::Data::Store] Data store for the Interchange and all encompassed components.
8
- attr_accessor :store
9
- # An array of Transaction Set instances.
10
- # @return [Array<Eddy::TransactionSet>]
11
- attr_accessor :transaction_sets
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
- # @param store [Eddy::Data::Store]
14
- # @param transaction_sets [Eddy::TransactionSet]
15
- # @return [void]
16
- def initialize(store, *transaction_sets)
17
- self.store = store
18
- transaction_sets.flatten!
19
- self.transaction_sets = transaction_sets || []
20
- if self.transaction_sets.length == 0
21
- raise ArgumentError, "At least one transaction set is required to create a functional group"
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
- # @return [Array<#render>]
27
- def render()
28
- f_group_ctrl_num = Eddy::Data.new_functional_group_control_number(@id)
29
- gs = Eddy::Segments::GS.new(store, f_group_ctrl_num, @id)
30
- ge = Eddy::Segments::GE.new(store, f_group_ctrl_num, self.transaction_sets.length)
31
- return [gs, self.transaction_sets, ge].flatten.map(&:render)
32
- end
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