Class: Scale::Scheme

Inherits:
Object
  • Object
show all
Defined in:
lib/scale/scheme.rb

Overview

Describes a particular scaling scenario

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Scheme

Returns a new instance of Scheme.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):



18
19
20
21
22
# File 'lib/scale/scheme.rb', line 18

def initialize(options = {})
  @input = options[:input]
  @source = Source.new(options[:source]) unless options[:source].nil?
  @destination = Destination.new(options[:destination]) unless options[:destination].nil?
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



13
14
15
# File 'lib/scale/scheme.rb', line 13

def destination
  @destination
end

#inputObject (readonly)

Returns the value of attribute input.



13
14
15
# File 'lib/scale/scheme.rb', line 13

def input
  @input
end

#sourceObject (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.

Parameters:

Returns:



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.

Parameters:

Returns:



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

Parameters:



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