Class: Eddy::Models::Loop::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/eddy/models/loop/base.rb

Overview

A repeated collection of Segments and/or other Loops.

See:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, repeat_object) ⇒ void

All of a Loop's elements need to be declared in its constructor.

Parameters:



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

#contentArray<Array>

An array of loop iterations.

Returns:

  • (Array<Array>)


30
31
32
# File 'lib/eddy/models/loop/base.rb', line 30

def content
  @content
end

#idString (readonly)

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

Returns:

  • (String)


15
16
17
# File 'lib/eddy/models/loop/base.rb', line 15

def id
  @id
end

#repeat_limitInteger (readonly)

Number of times a particular Loop may be repeated.

Returns:

  • (Integer)


18
19
20
# File 'lib/eddy/models/loop/base.rb', line 18

def repeat_limit
  @repeat_limit
end

#repeat_objectEddy::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

#reqString (readonly)

Defines if/how the Loop is required.

Returns:

  • (String)


21
22
23
# File 'lib/eddy/models/loop/base.rb', line 21

def req
  @req
end

#storeEddy::Data::Store (readonly)

Returns Data passed down from a Transaction Set.

Returns:



27
28
29
# File 'lib/eddy/models/loop/base.rb', line 27

def store
  @store
end

Instance Method Details

#all_contentsArray<Eddy::Models::Segment>

Return all contained Segments in a single, flattened array.

Returns:



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.

Parameters:

  • block (Block)


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