class Scale::Scheme
Describes a particular scaling scenario
Attributes
Public Class Methods
@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
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
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
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
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
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
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