Class: Dilation::Utils::Dilator
- Inherits:
-
Object
- Object
- Dilation::Utils::Dilator
- Defined in:
- lib/dilation/utils/dilator.rb
Overview
TODO:
Fix floating point issue (see specs)
This class is used for controlling the dilation and contraction factors of Core
Instance Method Summary collapse
-
#factor=(val) ⇒ Object
Set the factor and reset the dilator.
-
#initialize ⇒ Dilator
constructor
A new instance of Dilator.
-
#invert ⇒ Object
Invert the dilator.
-
#inverted? ⇒ Boolean
True if this dilator is inverted.
-
#reset ⇒ Object
Reset this dilator.
-
#run { ... } ⇒ Object
Run ths dilator based on the factor.
-
#uninvert ⇒ Object
Uninvert the dilator.
Constructor Details
#initialize ⇒ Dilator
Returns a new instance of Dilator.
9 10 11 |
# File 'lib/dilation/utils/dilator.rb', line 9 def initialize self.factor = 1 end |
Instance Method Details
#factor=(val) ⇒ Object
Set the factor and reset the dilator
16 17 18 19 |
# File 'lib/dilation/utils/dilator.rb', line 16 def factor=(val) @factor = val reset end |
#invert ⇒ Object
Invert the dilator. When inverted, ‘factor` calls to #run yield once. Also resets the dilator
25 26 27 28 |
# File 'lib/dilation/utils/dilator.rb', line 25 def invert @invert = true reset end |
#inverted? ⇒ Boolean
Returns true if this dilator is inverted.
40 41 42 |
# File 'lib/dilation/utils/dilator.rb', line 40 def inverted? defined?(@invert) && @invert end |
#reset ⇒ Object
TODO:
should this be public?
Reset this dilator
46 47 48 |
# File 'lib/dilation/utils/dilator.rb', line 46 def reset @count = 0 end |
#run { ... } ⇒ Object
Run ths dilator based on the factor
55 56 57 58 59 |
# File 'lib/dilation/utils/dilator.rb', line 55 def run(&blk) begin blk.call end while run_again? if ready? end |
#uninvert ⇒ Object
Uninvert the dilator. When uninverted, one call to #run yield ‘factor` times. Also resets the dilator
34 35 36 37 |
# File 'lib/dilation/utils/dilator.rb', line 34 def uninvert @invert = false reset end |