Class: Metro::Units::Dimensions
- Inherits:
-
Struct
- Object
- Struct
- Metro::Units::Dimensions
- 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, height) ⇒ 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
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.
12 13 14 |
# File 'lib/metro/units/dimensions.rb', line 12 def self.none of 0.0, 0.0 end |
.of(width, height) ⇒ Object
An alternate way of creating a dimensions object which will enforce that the values added are converted to floating point numbers.
31 32 33 |
# File 'lib/metro/units/dimensions.rb', line 31 def self.of(width,height) 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.
21 22 23 |
# File 'lib/metro/units/dimensions.rb', line 21 def self.parse(string) of *string.split(",",2).map(&:to_f) end |
Instance Method Details
#to_s ⇒ Object
35 36 37 |
# File 'lib/metro/units/dimensions.rb', line 35 def to_s "#{width},#{height}" end |