Class: Metro::Units::Scale
- Inherits:
-
Struct
- Object
- Struct
- Metro::Units::Scale
- 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
-
#x_factor ⇒ Object
Returns the value of attribute x_factor.
-
#y_factor ⇒ Object
Returns the value of attribute y_factor.
Class Method Summary collapse
-
.one ⇒ Object
Create a scale that is 1:1.
-
.parse(string) ⇒ Object
Parse a string representation of a scale object.
-
.to(x, y) ⇒ Object
An alternative way to create a scale which will automatically convert the inputs into floating numbers.
Instance Method Summary collapse
Methods included from CalculationValidations
#*, #+, #-, #calculate, #check_calculation_requirements
Instance Attribute Details
#x_factor ⇒ Object
Returns the value of attribute x_factor
7 8 9 |
# File 'lib/metro/units/scale.rb', line 7 def x_factor @x_factor end |
#y_factor ⇒ Object
Returns the value of attribute y_factor
7 8 9 |
# File 'lib/metro/units/scale.rb', line 7 def y_factor @y_factor end |
Class Method Details
.one ⇒ Object
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_s ⇒ Object
34 35 36 |
# File 'lib/metro/units/scale.rb', line 34 def to_s "#{x_factor},#{y_factor}" end |