Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/scale/core_ext.rb

Overview

Extend the Numeric class to add a scaling helper. eg: 0.40.scaled_from(0..1).to([512, 128, 64, 32, 16, 12, 8, 4, 2, 0])

This is not included by default with the rest of the library. use require “scale/core_ext”

Instance Method Summary collapse

Instance Method Details

#scaledScale::Scheme

Build a Scheme for this numeric as input.

Returns:



12
13
14
# File 'lib/scale/core_ext.rb', line 12

def scaled
  Scale.transform(self)
end

#scaled_from(source) ⇒ Numeric, Scale::Scheme

Build a scheme with this numeric as input and add the given source to it. If on calling this method, the scheme has all of its needed properties, the scaled value will be returned. Otherwise # this method will return the updated Scheme object.

Parameters:

Returns:



31
32
33
# File 'lib/scale/core_ext.rb', line 31

def scaled_from(source)
  Scale.transform(self).from(source)
end

#scaled_to(destination) ⇒ Numeric, Scale::Scheme

Build a scheme with this numeric as input and add the given destination to it. If on calling this method, the scheme has all of its needed properties, the scaled value will be returned. Otherwise # this method will return the updated Scheme object.

Parameters:

Returns:



42
43
44
# File 'lib/scale/core_ext.rb', line 42

def scaled_to(destination)
  Scale.transform(self).to(destination)
end

#scaled_using(source, destination) ⇒ Numeric

Scale using the given source and destination, with this numeric as input.

Parameters:

Returns:



20
21
22
# File 'lib/scale/core_ext.rb', line 20

def scaled_using(source, destination)
  Scale.transform(self).using(source, destination)
end