class Spoonerize::Bumper
Class that handles bumping an index.
Attributes
The maximum before index wraps back to zero.
@return [Integer]
The number after being bumped.
@return [Integer]
Public Class Methods
Source
# File lib/spoonerize/bumper.rb, line 29 def initialize(initial_value, max_value, reverse = false) @max_value = max_value @reverse = reverse @value = bump_value(initial_value) end
Sets the bumper relative to the current index of words array. The value is automatically bumped once when instantiated. If on the last element of the words array, sets the bumper to 0.
@param [Integer] initial_value
@param [Integer] max_value
@param [Boolean] reverse Flip the order
Public Instance Methods
Source
# File lib/spoonerize/bumper.rb, line 43 def bump @value = bump_value(value) end
Increments/Decrements the bumper. If on the last element of the words array, sets the bumper to 0. We donβt need to worry about resetting the value to 0 when going in reverse, because when the array index is negative, it reads from the end of the array, which is already what we want.
@return [Integer]
Source
# File lib/spoonerize/bumper.rb, line 51 def reverse? @reverse end
Should we decrement instead of increment?
@return [Boolean]