Class: Scale::Destination::Enumerable
- Inherits:
-
Object
- Object
- Scale::Destination::Enumerable
- Defined in:
- lib/scale/destination.rb
Overview
Contains logic for dealing with input that includes Ruby’s core ::Enumerable
Instance Method Summary collapse
-
#initialize(enum) ⇒ Enumerable
constructor
A new instance of Enumerable.
-
#scale(input, source) ⇒ Numeric
Scale the given input and source using this destination.
Constructor Details
#initialize(enum) ⇒ Enumerable
Returns a new instance of Enumerable.
37 38 39 |
# File 'lib/scale/destination.rb', line 37 def initialize(enum) @enum = enum end |
Instance Method Details
#scale(input, source) ⇒ Numeric
Scale the given input and source using this destination
45 46 47 48 49 |
# File 'lib/scale/destination.rb', line 45 def scale(input, source) proportion = source.numerator(input) / source.denominator index = [((proportion * @enum.size).to_i - 1), 0].max @enum.to_a.at(index) end |