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) ⇒ Fixnum, Scale::Scheme
Set the source for this scaling scenario.
-
#initialize(options = {}) ⇒ Scheme
constructor
A new instance of Scheme.
-
#to(destination) ⇒ Fixnum, Scale::Scheme
Set the destination for this scaling scenario.
-
#using(source, destination) ⇒ Object
Set both the source and destination on this scheme.
Constructor Details
#initialize(options = {}) ⇒ Scheme
Returns a new instance of Scheme.
18 19 20 21 22 |
# File 'lib/scale/scheme.rb', line 18 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.
13 14 15 |
# File 'lib/scale/scheme.rb', line 13 def destination @destination end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
13 14 15 |
# File 'lib/scale/scheme.rb', line 13 def input @input end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
13 14 15 |
# File 'lib/scale/scheme.rb', line 13 def source @source end |
Instance Method Details
#from(source) ⇒ Fixnum, 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.
30 31 32 33 34 35 36 37 |
# File 'lib/scale/scheme.rb', line 30 def from(source) @source = Source.new(source) if @input.nil? || @destination.nil? self else @destination.scale(@input, @source) end end |
#to(destination) ⇒ Fixnum, 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.
45 46 47 48 49 50 51 52 |
# File 'lib/scale/scheme.rb', line 45 def to(destination) @destination = Destination.new(destination) if @input.nil? || @source.nil? self else @destination.scale(@input, @source) end end |
#using(source, destination) ⇒ Object
Set both the source and destination on this scheme
57 58 59 60 61 |
# File 'lib/scale/scheme.rb', line 57 def using(source, destination) @source = Source.new(source) @destination = Destination.new(destination) @destination.scale(@input, @source) end |