class Scale::Destination::Enumerable

Contains logic for dealing with input that includes Ruby's core ::Enumerable

Public Class Methods

new(enum) click to toggle source

@param [::Enumerable] enum An enumerable (eg Array, Set) to operate with

# File lib/scale/destination.rb, line 37
def initialize(enum)
  @enum = enum
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 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