123456789_123456789_123456789_123456789_123456789_

Class: ActionView::Helpers::TextHelper::Cycle

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: actionview/lib/action_view/helpers/text_helper.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(first_value, *values) ⇒ Cycle

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 485

def initialize(first_value, *values)
  @values = values.unshift(first_value)
  reset
end

Instance Attribute Details

#values (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 483

attr_reader :values

Instance Method Details

#current_value

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 494

def current_value
  @values[previous_index].to_s
end

#next_index (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 505

def next_index
  step_index(1)
end

#previous_index (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 509

def previous_index
  step_index(-1)
end

#reset

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 490

def reset
  @index = 0
end

#step_index(n) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 513

def step_index(n)
  (@index + n) % @values.size
end

#to_s

[ GitHub ]

  
# File 'actionview/lib/action_view/helpers/text_helper.rb', line 498

def to_s
  value = @values[@index].to_s
  @index = next_index
  value
end