Class: Scale::Scheme
- Inherits:
-
Object
- Object
- Scale::Scheme
- Defined in:
- lib/scale/scheme.rb
Overview
Describes a particular scaling scenario
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#from(source) ⇒ Numeric, Scale::Scheme
Set the source for this scaling scenario.
-
#initialize(options = {}) ⇒ Scheme
constructor
A new instance of Scheme.
-
#result ⇒ Numeric?
Get the result of this scaling scenario.
-
#scale(number) ⇒ Numeric, Scale::Scheme
(also: #transform)
Set the input of this scaling scenario.
-
#scale? ⇒ Boolean
Scan this scaling scenario be run?.
-
#to(destination) ⇒ Numeric, Scale::Scheme
Set the destination for this scaling scenario.
-
#using(source, destination) ⇒ Numeric, Scale::Scheme
Set both the source and destination on this scheme.
Constructor Details
#initialize(options = {}) ⇒ Scheme
Returns a new instance of Scheme.
43 44 45 46 47 |
# File 'lib/scale/scheme.rb', line 43 def initialize( = {}) @input = [:input] @source = Source.new([:source]) unless [:source].nil? @destination = Destination.new([:destination]) unless [:destination].nil? end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
38 39 40 |
# File 'lib/scale/scheme.rb', line 38 def destination @destination end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
38 39 40 |
# File 'lib/scale/scheme.rb', line 38 def input @input end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
38 39 40 |
# File 'lib/scale/scheme.rb', line 38 def source @source end |
Instance Method Details
#from(source) ⇒ Numeric, Scale::Scheme
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.
55 56 57 58 |
# File 'lib/scale/scheme.rb', line 55 def from(source) @source = Source.new(source) scale? ? result : self end |
#result ⇒ Numeric?
Get the result of this scaling scenario
105 106 107 |
# File 'lib/scale/scheme.rb', line 105 def result @result ||= @destination.scale(@input, @source) end |
#scale(number) ⇒ Numeric, Scale::Scheme Also known as: transform
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.
91 92 93 94 |
# File 'lib/scale/scheme.rb', line 91 def scale(number) @input = number scale? ? result : self end |
#scale? ⇒ Boolean
Scan this scaling scenario be run?
99 100 101 |
# File 'lib/scale/scheme.rb', line 99 def scale? !@input.nil? && !@source.nil? && !@destination.nil? end |
#to(destination) ⇒ Numeric, Scale::Scheme
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.
66 67 68 69 |
# File 'lib/scale/scheme.rb', line 66 def to(destination) @destination = Destination.new(destination) scale? ? result : self end |
#using(source, destination) ⇒ Numeric, Scale::Scheme
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.
78 79 80 81 82 |
# File 'lib/scale/scheme.rb', line 78 def using(source, destination) @source = Source.new(source) @destination = Destination.new(destination) scale? ? result : self end |