class Eddy::Models::Loop::Base
A repeated collection of Segments
and/or other Loops.
See:
-
[HL
Loop
Structure in TS 837 - X12 RFI](www.x12.org/rfis/HL%20Loop%20Structure%20in%20TS%20837.pdf) -
[HL
Segment
Content - X12 RFI](www.x12.org/rfis/HL%20Segment%20Content.pdf)
Attributes
An array of loop iterations. @return [Array<Array>]
(Name) A unique string used to identify the Loop
within its Transaction Set. This is not EDI standardized, any name will do. @return [String]
Number of times a particular Loop
may be repeated. @return [Integer]
Used to contain the components of a single loop iteration (or a single loop repeat). This value is a class, not an instance. @return [Eddy::Models::Loop::Repeat]
Defines if/how the Loop
is required. @return [String]
@return [Eddy::Data::Store] Data
passed down from a Transaction Set.
Public Class Methods
All of a Loop's elements need to be declared in its constructor.
@param store [Eddy::Data::Store] @param repeat_object
[Eddy::Models::Loop::Repeat] @return [void]
# File lib/eddy/models/loop/base.rb, line 37 def initialize(store, repeat_object) @store = store @repeat_object = repeat_object @content = [] end
Public Instance Methods
Return all contained Segments
in a single, flattened array.
@return [Array<Eddy::Models::Segment>]
# 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
@param block [Block] @return [void]
# 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