class Scale::Scheme

Describes a particular scaling scenario

Attributes

destination[R]
input[R]
source[R]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [::Enumerable] :destination The destination for this scaling scenario @option options [::Enumerable] :source The source for this scaling scenario

# File lib/scale/scheme.rb, line 43
def initialize(options = {})
  @input = options[:input]
  @destination = nil
  @source = nil

  unless options[:source].nil?
    @source = Source.new(options[:source])
  end
  unless options[:destination].nil?
    @destination = Destination.new(options[:destination])
  end
end

Public Instance Methods

from(source) click to toggle source

Set the source for this scaling scenario. If on calling this method, the scenario has all of its needed properties, the scaled value will be returned. Otherwise this method will return the updated Scheme object.

@param [::Enumerable] source @return [Numeric, Scale::Scheme]

# File lib/scale/scheme.rb, line 62
def from(source)
  @source = Source.new(source)
  scale? ? result : self
end
result() click to toggle source

Get the result of this scaling scenario @return [Numeric, nil]

# File lib/scale/scheme.rb, line 112
def result
  @result ||= @destination.scale(@input, @source)
end
scale(number) click to toggle source

Set the input of this scaling scenario. If on calling this method, the scenario has all of its needed properties, the scaled value will be returned. Otherwise this method will return the updated Scheme object.

@param [Numeric] number @return [Numeric, Scale::Scheme]

# File lib/scale/scheme.rb, line 98
def scale(number)
  @input = number
  scale? ? result : self
end
Also aliased as: transform
scale?() click to toggle source

Scan this scaling scenario be run? @return [Boolean] Whether this scaling scenario can be run

# File lib/scale/scheme.rb, line 106
def scale?
  !@input.nil? && !@source.nil? && !@destination.nil?
end
to(destination) click to toggle source

Set the destination for this scaling scenario. If on calling this method, the scenario has all of its needed properties, the scaled value will be returned. Otherwise this method will return the updated Scheme object.

@param [::Enumerable] destination @return [Numeric, Scale::Scheme]

# File lib/scale/scheme.rb, line 73
def to(destination)
  @destination = Destination.new(destination)
  scale? ? result : self
end
transform(number)
Alias for: scale
using(source, destination) click to toggle source

Set both the source and destination on this scheme. If on calling this method, the scenario has all of its needed properties, the scaled value will be returned. Otherwise this method will return the updated Scheme object.

@param [::Enumerable] source @param [::Enumerable] destination @return [Numeric, Scale::Scheme]

# File lib/scale/scheme.rb, line 85
def using(source, destination)
  @source = Source.new(source)
  @destination = Destination.new(destination)
  scale? ? result : self
end