Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- 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
-
#scaled ⇒ Scale::Scheme
Build a Scheme for this numeric as input.
-
#scaled_from(source) ⇒ Numeric, Scale::Scheme
Build a scheme with this numeric as input and add the given source to it.
-
#scaled_to(destination) ⇒ Numeric, Scale::Scheme
Build a scheme with this numeric as input and add the given destination to it.
-
#scaled_using(source, destination) ⇒ Numeric
Scale using the given source and destination, with this numeric as input.
Instance Method Details
#scaled ⇒ Scale::Scheme
Build a Scheme for this numeric as input.
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.
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.
42 43 44 |
# File 'lib/scale/core_ext.rb', line 42 def scaled_to(destination) Scale.transform(self).to(destination) end |