Class: Dilation::Utils::Dilator

Inherits:
Object
  • Object
show all
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

Author:

Instance Method Summary collapse

Constructor Details

#initializeDilator

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

Parameters:

  • val (Number)

    the new factor



16
17
18
19
# File 'lib/dilation/utils/dilator.rb', line 16

def factor=(val)
  @factor = val
  reset
end

#invertObject

Invert the dilator. When inverted, ‘factor` calls to #run yield once. Also resets the dilator

See Also:

  • Dilation::Utils::Dilator.{{#run}


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.

Returns:

  • (Boolean)

    true if this dilator is inverted



40
41
42
# File 'lib/dilation/utils/dilator.rb', line 40

def inverted?
  defined?(@invert) && @invert
end

#resetObject

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

Yields:

  • if the factor is met

See Also:

  • Dilation::Utils::Dilator.{{#invert}
  • Dilation::Utils::Dilator.{{#uninvert}


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

#uninvertObject

Uninvert the dilator. When uninverted, one call to #run yield ‘factor` times. Also resets the dilator

See Also:

  • Dilation::Utils::Dilator.{{#run}


34
35
36
37
# File 'lib/dilation/utils/dilator.rb', line 34

def uninvert
  @invert = false
  reset
end