Class: Metro::Units::Scale

Inherits:
Struct
  • Object
show all
Includes:
CalculationValidations
Defined in:
lib/metro/units/scale.rb

Overview

Represents an object that contains the x scale factor, and y scale factor.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CalculationValidations

#*, #+, #-, #calculate, #check_calculation_requirements

Instance Attribute Details

#x_factorObject

Returns the value of attribute x_factor

Returns:

  • (Object)

    the current value of x_factor



7
8
9
# File 'lib/metro/units/scale.rb', line 7

def x_factor
  @x_factor
end

#y_factorObject

Returns the value of attribute y_factor

Returns:

  • (Object)

    the current value of y_factor



7
8
9
# File 'lib/metro/units/scale.rb', line 7

def y_factor
  @y_factor
end

Class Method Details

.oneObject

Create a scale that is 1:1.



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

def self.one
  new 1.0, 1.0
end

.parse(string) ⇒ Object

Parse a string representation of a scale object. The supported formated is a comma-delimited string that contains two attributes x-factor and y-factor.



30
31
32
# File 'lib/metro/units/scale.rb', line 30

def self.parse(string)
  to *string.split(",",2).map(&:to_f)
end

.to(x, y) ⇒ Object

An alternative way to create a scale which will automatically convert the inputs into floating numbers.



21
22
23
# File 'lib/metro/units/scale.rb', line 21

def self.to(x,y)
  new x.to_f, y.to_f
end

Instance Method Details

#to_sObject



34
35
36
# File 'lib/metro/units/scale.rb', line 34

def to_s
  "#{x_factor},#{y_factor}"
end