class Eddy::Models::Loop::Base

A repeated collection of Segments and/or other Loops.

See:

Attributes

content[RW]

An array of loop iterations. @return [Array<Array>]

id[R]

(Name) A unique string used to identify the Loop within its Transaction Set. This is not EDI standardized, any name will do. @return [String]

repeat_limit[R]

Number of times a particular Loop may be repeated. @return [Integer]

repeat_object[R]

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]

req[R]

Defines if/how the Loop is required. @return [String]

store[R]

@return [Eddy::Data::Store] Data passed down from a Transaction Set.

Public Class Methods

new(store, repeat_object) click to toggle source

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

all_contents() click to toggle source

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
repeat(&block) click to toggle source

@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