Class: Tenjin::HtmlTagHelper::Cycle

Inherits:
Object
  • Object
show all
Defined in:
lib/tenjin.rb

Overview

cycle values everytime when #to_s() is called ex:

cycle = Cycle.new('odd', 'even')
"#{cycle}"   #=> 'odd'
"#{cycle}"   #=> 'even'
"#{cycle}"   #=> 'odd'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*values) ⇒ Cycle

Returns a new instance of Cycle.



167
168
169
170
171
# File 'lib/tenjin.rb', line 167

def initialize(*values)
  @values = values.freeze
  @length = values.length
  @index  = -1
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



172
173
174
# File 'lib/tenjin.rb', line 172

def index
  @index
end

#valuesObject (readonly)

Returns the value of attribute values.



166
167
168
# File 'lib/tenjin.rb', line 166

def values
  @values
end

Instance Method Details

#countObject



177
178
179
# File 'lib/tenjin.rb', line 177

def count
  @index + 1
end

#nextObject Also known as: to_s



173
174
175
# File 'lib/tenjin.rb', line 173

def next
  return @values[(@index += 1) % @length]
end