class Scale::Destination::Range
Contains logic for dealing with Ruby's core ::Range as input
Public Class Methods
new(range)
click to toggle source
@param [::Range] range A range to operate with
# File lib/scale/destination.rb, line 12 def initialize(range) @range = range end
Public Instance Methods
scale(input, source)
click to toggle source
Scale
the given input and source using this destination @param [Numeric] input A numeric value to scale @param [Scale::Source] source The source for the input value @return [Numeric]
# File lib/scale/destination.rb, line 20 def scale(input, source) to_range_len = (@range.last - @range.first).abs proportion = to_range_len.to_f / source.denominator abs_output = proportion.to_f * source.numerator(input) output = abs_output + @range.first float_requested = [@range.first, @range.last].any? { |n| n.kind_of?(::Float) } float_requested ? output : output.to_i end