Class: Eddy::Models::Loop::Base
- Inherits:
-
Object
- Object
- Eddy::Models::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::Base, TransactionSets::TS810::Loops::N1::Base, TransactionSets::TS810::Loops::PID::Base, TransactionSets::TS810::Loops::SAC::Base, TransactionSets::TS850::Loops::N1::Base, TransactionSets::TS850::Loops::PO1::Base, TransactionSets::TS855::Loops::ACK::Base, TransactionSets::TS855::Loops::N1::Base, TransactionSets::TS855::Loops::PID::Base, TransactionSets::TS855::Loops::PO1::Base, TransactionSets::TS856::Loops::HL_Item::Base, TransactionSets::TS856::Loops::HL_Order::Base, TransactionSets::TS856::Loops::HL_Shipment::Base, TransactionSets::TS856::Loops::HL_Tare::Base, TransactionSets::TS856::Loops::N1::Base, TransactionSets::TS856::Loops::SLN::Base
Instance Attribute Summary collapse
-
#content ⇒ Array<Array>
An array of loop iterations.
-
#id ⇒ String
readonly
(Name) A unique string used to identify the Loop within its Transaction Set.
-
#repeat_limit ⇒ Integer
readonly
Number of times a particular Loop may be repeated.
-
#repeat_object ⇒ Eddy::Models::Loop::Repeat
readonly
Used to contain the components of a single loop iteration (or a single loop repeat).
-
#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
-
#all_contents ⇒ Array<Eddy::Models::Segment>
Return all contained Segments in a single, flattened array.
-
#initialize(store, repeat_object) ⇒ void
constructor
All of a Loop's elements need to be declared in its constructor.
- #repeat(&block) ⇒ void
Constructor Details
#initialize(store, repeat_object) ⇒ void
All of a Loop's elements need to be declared in its constructor.
37 38 39 40 41 |
# File 'lib/eddy/models/loop/base.rb', line 37 def initialize(store, repeat_object) @store = store @repeat_object = repeat_object @content = [] end |
Instance Attribute Details
#content ⇒ Array<Array>
An array of loop iterations.
30 31 32 |
# File 'lib/eddy/models/loop/base.rb', line 30 def content @content end |
#id ⇒ String (readonly)
(Name) A unique string used to identify the Loop within its Transaction Set. This is not EDI standardized, any name will do.
15 16 17 |
# File 'lib/eddy/models/loop/base.rb', line 15 def id @id end |
#repeat_limit ⇒ Integer (readonly)
Number of times a particular Loop may be repeated.
18 19 20 |
# File 'lib/eddy/models/loop/base.rb', line 18 def repeat_limit @repeat_limit end |
#repeat_object ⇒ Eddy::Models::Loop::Repeat (readonly)
Used to contain the components of a single loop iteration (or a single loop repeat). This value is a class, not an instance.
25 26 27 |
# File 'lib/eddy/models/loop/base.rb', line 25 def repeat_object @repeat_object end |
#req ⇒ String (readonly)
Defines if/how the Loop is required.
21 22 23 |
# File 'lib/eddy/models/loop/base.rb', line 21 def req @req end |
#store ⇒ Eddy::Data::Store (readonly)
Returns Data passed down from a Transaction Set.
27 28 29 |
# File 'lib/eddy/models/loop/base.rb', line 27 def store @store end |
Instance Method Details
#all_contents ⇒ Array<Eddy::Models::Segment>
Return all contained Segments in a single, flattened array.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/eddy/models/loop/base.rb', line 46 def all_contents() contents = self.content.flatten.map do |c| case c when Eddy::Models::Loop::Repeat then c.all_contents() when Eddy::Models::Loop::Base then c.all_contents() when Eddy::Models::Segment then c else raise Eddy::Errors::RenderError end end return contents.flatten end |
#repeat(&block) ⇒ void
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/eddy/models/loop/base.rb', line 60 def repeat(&block) rep = self.repeat_object.new(self.store) if block_given? rep.repeat(&block) else raise Eddy::Errors::Error, "No block given in loop iteration" end self.content << rep return nil end |