Class: Spoonerize::Bumper
- Inherits:
-
Object
- Object
- Spoonerize::Bumper
- Defined in:
- lib/spoonerize/bumper.rb
Overview
Class that handles bumping an index.
Instance Attribute Summary collapse
-
#max_value ⇒ Integer
readonly
The maximum before index wraps back to zero.
-
#value ⇒ Integer
readonly
The number after being bumped.
Instance Method Summary collapse
-
#bump ⇒ Integer
Increments/Decrements the bumper.
-
#initialize(initial_value, max_value, reverse = false) ⇒ Bumper
constructor
Sets the bumper relative to the current index of words array.
-
#reverse? ⇒ Boolean
Should we decrement instead of increment?.
Constructor Details
#initialize(initial_value, max_value, reverse = false) ⇒ Bumper
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.
27 28 29 30 31 |
# File 'lib/spoonerize/bumper.rb', line 27 def initialize(initial_value, max_value, reverse = false) @max_value = max_value @reverse = reverse @value = bump_value(initial_value) end |
Instance Attribute Details
#max_value ⇒ Integer (readonly)
The maximum before index wraps back to zero.
15 16 17 |
# File 'lib/spoonerize/bumper.rb', line 15 def max_value @max_value end |
#value ⇒ Integer (readonly)
The number after being bumped.
9 10 11 |
# File 'lib/spoonerize/bumper.rb', line 9 def value @value end |
Instance Method Details
#bump ⇒ Integer
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.
41 42 43 |
# File 'lib/spoonerize/bumper.rb', line 41 def bump @value = bump_value(value) end |
#reverse? ⇒ Boolean
Should we decrement instead of increment?
49 50 51 |
# File 'lib/spoonerize/bumper.rb', line 49 def reverse? @reverse end |