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 48 49 50 51 52 53 54 |
# File 'lib/scale/scheme.rb', line 43 def initialize( = {}) @input = [:input] @destination = nil @source = nil unless [:source].nil? @source = Source.new([:source]) end unless [:destination].nil? @destination = Destination.new([:destination]) end 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.
62 63 64 65 |
# File 'lib/scale/scheme.rb', line 62 def from(source) @source = Source.new(source) scale? ? result : self end |
#result ⇒ Numeric?
Get the result of this scaling scenario
112 113 114 |
# File 'lib/scale/scheme.rb', line 112 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.
98 99 100 101 |
# File 'lib/scale/scheme.rb', line 98 def scale(number) @input = number scale? ? result : self end |
#scale? ⇒ Boolean
Scan this scaling scenario be run?
106 107 108 |
# File 'lib/scale/scheme.rb', line 106 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.
73 74 75 76 |
# File 'lib/scale/scheme.rb', line 73 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.
85 86 87 88 89 |
# File 'lib/scale/scheme.rb', line 85 def using(source, destination) @source = Source.new(source) @destination = Destination.new(destination) scale? ? result : self end |