class Spoonerize::Bumper

Class that handles bumping an index.

Attributes

max_value[R]

The maximum before index wraps back to zero.

@return [Integer]

value[R]

The number after being bumped.

@return [Integer]

Public Class Methods

new(initial_value, max_value, reverse = false) click to toggle source

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

# File lib/spoonerize/bumper.rb, line 28
def initialize(initial_value, max_value, reverse = false)
  @max_value = max_value
  @reverse = reverse
  @value = bump_value(initial_value)
end

Public Instance Methods

bump() click to toggle source

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]

# File lib/spoonerize/bumper.rb, line 42
def bump
  @value = bump_value(value)
end
reverse?() click to toggle source

Should we decrement instead of increment?

@return [Boolean]

# File lib/spoonerize/bumper.rb, line 50
def reverse?
  @reverse
end