Class: Metro::Units::Dimensions
- Inherits:
-
Struct
- Object
- Struct
- Metro::Units::Dimensions
- Includes:
- CalculationValidations
- Defined in:
- lib/metro/units/dimensions.rb
Overview
Represents an object that contains both the width and height.
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.none ⇒ Object
Create a dimensions objects with zero width and zero height.
-
.of(width = 0.0, height = 0.0) ⇒ Object
An alternate way of creating a dimensions object which will enforce that the values added are converted to floating point numbers.
-
.parse(string) ⇒ Object
Parse a string representation of a dimensions object.
Instance Method Summary collapse
-
#<=>(value) ⇒ Fixnum
Compare the dimension to another dimensions-like structure.
- #to_s ⇒ Object
Methods included from CalculationValidations
#*, #+, #-, #calculate, #check_calculation_requirements
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height
7 8 9 |
# File 'lib/metro/units/dimensions.rb', line 7 def height @height end |
#width ⇒ Object
Returns the value of attribute width
7 8 9 |
# File 'lib/metro/units/dimensions.rb', line 7 def width @width end |
Class Method Details
.none ⇒ Object
Create a dimensions objects with zero width and zero height.
13 14 15 |
# File 'lib/metro/units/dimensions.rb', line 13 def self.none of 0.0, 0.0 end |
.of(width = 0.0, height = 0.0) ⇒ Object
An alternate way of creating a dimensions object which will enforce that the values added are converted to floating point numbers.
32 33 34 |
# File 'lib/metro/units/dimensions.rb', line 32 def self.of(width=0.0,height=0.0) new width.to_f, height.to_f end |
.parse(string) ⇒ Object
Parse a string representation of a dimensions object. The supported formated is a comma-delimited string that contains two attributes width and height.
22 23 24 |
# File 'lib/metro/units/dimensions.rb', line 22 def self.parse(string) of *string.to_s.split(",",2).map(&:to_f) end |
Instance Method Details
#<=>(value) ⇒ Fixnum
Compare the dimension to another dimensions-like structure.
47 48 49 50 |
# File 'lib/metro/units/dimensions.rb', line 47 def <=>(value) check_calculation_requirements(value) (width * height) <=> (value.width * value.height) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/metro/units/dimensions.rb', line 36 def to_s "#{width},#{height}" end |