Class: Metro::Units::Dimensions

Inherits:
Struct
  • Object
show all
Defined in:
lib/metro/units/dimensions.rb

Overview

Represents an object that contains both the width and height.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



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

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



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

def width
  @width
end

Class Method Details

.noneObject

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_sObject



35
36
37
# File 'lib/metro/units/dimensions.rb', line 35

def to_s
  "#{width},#{height}"
end