Class: Liquid2::ForLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid2/nodes/tags/for.rb

Overview

for loop helper variables.

Constant Summary collapse

KEYS =

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, length, parent_loop) ⇒ ForLoop

Returns a new instance of ForLoop.



124
125
126
127
128
129
# File 'lib/liquid2/nodes/tags/for.rb', line 124

def initialize(name, length, parent_loop)
  @name = name
  @length = length
  @parentloop = parent_loop
  @index = -1
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



110
111
112
# File 'lib/liquid2/nodes/tags/for.rb', line 110

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



110
111
112
# File 'lib/liquid2/nodes/tags/for.rb', line 110

def name
  @name
end

#parentloopObject (readonly)

Returns the value of attribute parentloop.



110
111
112
# File 'lib/liquid2/nodes/tags/for.rb', line 110

def parentloop
  @parentloop
end

Instance Method Details

#[](key) ⇒ Object



135
136
137
# File 'lib/liquid2/nodes/tags/for.rb', line 135

def [](key)
  send(key) if KEYS.member?(key)
end

#fetch(key, default = :undefined) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/liquid2/nodes/tags/for.rb', line 139

def fetch(key, default = :undefined)
  if KEYS.member?(key)
    send(key)
  else
    default
  end
end

#firstObject



152
# File 'lib/liquid2/nodes/tags/for.rb', line 152

def first = @index.zero?

#indexObject



148
# File 'lib/liquid2/nodes/tags/for.rb', line 148

def index = @index + 1

#index0Object



149
# File 'lib/liquid2/nodes/tags/for.rb', line 149

def index0 = @index

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/liquid2/nodes/tags/for.rb', line 131

def key?(key)
  KEYS.member?(key)
end

#lastObject



153
# File 'lib/liquid2/nodes/tags/for.rb', line 153

def last = @index == @length - 1

#nextObject



147
# File 'lib/liquid2/nodes/tags/for.rb', line 147

def next = @index += 1

#rindexObject



150
# File 'lib/liquid2/nodes/tags/for.rb', line 150

def rindex = @length - @index

#rindex0Object



151
# File 'lib/liquid2/nodes/tags/for.rb', line 151

def rindex0 = @length - @index - 1