Class: Eddy::Loop::Base
- Inherits:
-
Object
- Object
- Eddy::Loop::Base
- Defined in:
- lib/eddy/models/loop/base.rb
Overview
A repeated collection of Segments and/or other Loops.
See:
Direct Known Subclasses
TransactionSets::TS810::Loops::IT1, TransactionSets::TS810::Loops::N1, TransactionSets::TS810::Loops::PID, TransactionSets::TS810::Loops::SAC, TransactionSets::TS850::Loops::N1, TransactionSets::TS850::Loops::PO1, TransactionSets::TS855::Loops::ACK, TransactionSets::TS855::Loops::N1, TransactionSets::TS855::Loops::PID, TransactionSets::TS855::Loops::PO1, TransactionSets::TS856::Loops::HL_ITEM, TransactionSets::TS856::Loops::HL_ORDER, TransactionSets::TS856::Loops::HL_SHIPMENT, TransactionSets::TS856::Loops::HL_TARE, TransactionSets::TS856::Loops::N1
Instance Attribute Summary collapse
-
#components ⇒ Array<Eddy::Segment, Eddy::Loop::Base>
readonly
An array of Segments and/or other Loops.
-
#content ⇒ Array<Array>
An array of loop iterations.
-
#loop_id ⇒ String
readonly
(Name) A unique string used to identify the Loop within its Transaction Set.
-
#repeat ⇒ Integer
readonly
Number of times a particular Loop may be repeated.
-
#req ⇒ String
readonly
Defines if/how the Loop is required.
-
#store ⇒ Eddy::Data::Store
readonly
Data passed down from a Transaction Set.
Instance Method Summary collapse
- #add_iteration(&block) ⇒ void
-
#all_contents ⇒ Array<Eddy::Segment>
Return all contained Segments in a single, flattened array.
-
#initialize(store, *components) ⇒ void
constructor
All of a Loop's elements need to be declared in its constructor.
Constructor Details
#initialize(store, *components) ⇒ void
All of a Loop's elements need to be declared in its constructor.
35 36 37 38 39 40 |
# File 'lib/eddy/models/loop/base.rb', line 35 def initialize(store, *components) @store = store components.flatten! @components = components || [] @content = [] end |
Instance Attribute Details
#components ⇒ Array<Eddy::Segment, Eddy::Loop::Base> (readonly)
An array of Segments and/or other Loops.
This is used as a template to populate content.
23 24 25 |
# File 'lib/eddy/models/loop/base.rb', line 23 def components @components end |
#content ⇒ Array<Array>
An array of loop iterations.
28 29 30 |
# File 'lib/eddy/models/loop/base.rb', line 28 def content @content end |
#loop_id ⇒ String (readonly)
(Name) A unique string used to identify the Loop within its Transaction Set.
13 14 15 |
# File 'lib/eddy/models/loop/base.rb', line 13 def loop_id @loop_id end |
#repeat ⇒ Integer (readonly)
Number of times a particular Loop may be repeated.
16 17 18 |
# File 'lib/eddy/models/loop/base.rb', line 16 def repeat @repeat end |
#req ⇒ String (readonly)
Defines if/how the Loop is required.
19 20 21 |
# File 'lib/eddy/models/loop/base.rb', line 19 def req @req end |
#store ⇒ Eddy::Data::Store (readonly)
25 26 27 |
# File 'lib/eddy/models/loop/base.rb', line 25 def store @store end |
Instance Method Details
#add_iteration(&block) ⇒ void
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/eddy/models/loop/base.rb', line 61 def add_iteration(&block) iteration = self.components.map { |c| c.new(self.store) } if block_given? yield(*iteration) else raise Eddy::Errors::Error, "No block given in loop iteration" end self.content << iteration return nil end |
#all_contents ⇒ Array<Eddy::Segment>
Return all contained Segments in a single, flattened array.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/eddy/models/loop/base.rb', line 45 def all_contents() contents = self.content.flatten.map do |c| if c.is_a?(Eddy::Loop::Base) c.all_contents() elsif c.is_a?(Eddy::Segment) # elsif c < Eddy::Segment c else raise Eddy::Errors::RenderError end end return contents.flatten end |