Class: Eddy::Models::Loop::Repeat

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

Overview

Data form a single loop iteration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, *components) ⇒ void

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

Parameters:



19
20
21
22
23
# File 'lib/eddy/models/loop/repeat.rb', line 19

def initialize(store, *components)
  @store = store
  components.flatten!
  @components = components || []
end

Instance Attribute Details

#componentsArray<Eddy::Models::Segment, Eddy::Models::Loop::Base> (readonly)

An array of Segments and/or other Loops. This is used as a template to populate content.



10
11
12
# File 'lib/eddy/models/loop/repeat.rb', line 10

def components
  @components
end

#storeEddy::Data::Store (readonly)

Returns Data passed down from a Transaction Set.

Returns:



12
13
14
# File 'lib/eddy/models/loop/repeat.rb', line 12

def store
  @store
end

Instance Method Details

#all_contentsArray<Eddy::Models::Segment>

Return all contained Segments in a single, flattened array.

Returns:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eddy/models/loop/repeat.rb', line 28

def all_contents()
  contents = self.components.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 {|rep| ... } ⇒ self

Yield Parameters:

  • rep (self)

Returns:

  • (self)


42
43
44
45
46
47
48
49
# File 'lib/eddy/models/loop/repeat.rb', line 42

def repeat()
  if block_given?
    yield(self)
  else
    raise Eddy::Errors::Error, "No block given in loop iteration"
  end
  return self
end