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.
29 30 31 32 33 |
# 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 |
Instance Attribute Details
#max_value ⇒ Integer (readonly)
The maximum before index wraps back to zero.
17 18 19 |
# File 'lib/spoonerize/bumper.rb', line 17 def max_value @max_value end |
#value ⇒ Integer (readonly)
The number after being bumped.
11 12 13 |
# File 'lib/spoonerize/bumper.rb', line 11 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.
43 44 45 |
# File 'lib/spoonerize/bumper.rb', line 43 def bump @value = bump_value(value) end |
#reverse? ⇒ Boolean
Should we decrement instead of increment?
51 52 53 |
# File 'lib/spoonerize/bumper.rb', line 51 def reverse? @reverse end |