Module: Scale::Destination

Defined in:
lib/scale/destination.rb

Overview

These are the classes that describe what range the transformed number will wind up in. They’re named after the core Ruby class that the input closest resembles.

Defined Under Namespace

Classes: Enumerable, Range

Constant Summary collapse

MAP =

Map Ruby classes/modules to scaling destination classes/modules

{
  ::Enumerable => Destination::Enumerable,
  ::Range => Destination::Range
}

Class Method Summary collapse

Class Method Details

.new(destination) ⇒ Scale::Destination::Enumerable, Scale::Destination::Range

Build the appropriate scaling destination class for the given Ruby object

Parameters:

  • destination (::Enumerable)

Returns:



62
63
64
65
66
67
68
69
# File 'lib/scale/destination.rb', line 62

def self.new(destination)
  klass = MAP[destination.class]
  if klass.nil?
    klasses = MAP.select { |k,v| destination.kind_of?(k) }
    klass = klasses.values.first
  end
  klass.new(destination) unless klass.nil?
end