Class: Scale::Destination::Range
- Inherits:
-
Object
- Object
- Scale::Destination::Range
- Defined in:
- lib/scale/destination.rb
Overview
Contains logic for dealing with Ruby’s core ::Range as input
Instance Method Summary collapse
-
#initialize(range) ⇒ Range
constructor
A new instance of Range.
-
#scale(input, source) ⇒ Numeric
Scale the given input and source using this destination.
Constructor Details
#initialize(range) ⇒ Range
Returns a new instance of Range.
12 13 14 |
# File 'lib/scale/destination.rb', line 12 def initialize(range) @range = range end |
Instance Method Details
#scale(input, source) ⇒ Numeric
Scale the given input and source using this destination
20 21 22 23 24 25 26 27 28 29 |
# 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 |