class Numeric
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”
Public Instance Methods
Build a Scheme for this numeric as input. @return [Scale::Scheme]
# File lib/scale/core_ext.rb, line 12 def scaled Scale.transform(self) end
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.
@param [Scale::Source] source @return [Numeric, Scale::Scheme]
# File lib/scale/core_ext.rb, line 31 def scaled_from(source) Scale.transform(self).from(source) end
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.
@param [Scale::Destination] destination @return [Numeric, Scale::Scheme]
# File lib/scale/core_ext.rb, line 42 def scaled_to(destination) Scale.transform(self).to(destination) end
Scale
using the given source and destination, with this numeric as input. @param [Scale::Source] source @param [Scale::Destination] destination @return [Numeric]
# File lib/scale/core_ext.rb, line 20 def scaled_using(source, destination) Scale.transform(self).using(source, destination) end