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