Class: AIXM::R

Inherits:
Object show all
Includes:
Concerns::HashEquality
Defined in:
lib/aixm/r.rb

Overview

Rectangle shape composed of two lengths

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::HashEquality

#eql?, #hash

Constructor Details

#initialize(length, width = nil) ⇒ R

See the overview for examples.



30
31
32
# File 'lib/aixm/r.rb', line 30

def initialize(length, width=nil)
  self.length, self.width = length, (width || length)
end

Instance Attribute Details

#lengthAIXM::D (readonly) #length=(value) ⇒ Object (readonly)

Rectangle length

Overloads:



19
20
21
# File 'lib/aixm/r.rb', line 19

def length
  @length
end

#widthAIXM::D (readonly) #width=(value) ⇒ Object (readonly)

Rectangle width

Overloads:



27
28
29
# File 'lib/aixm/r.rb', line 27

def width
  @width
end

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


60
61
62
# File 'lib/aixm/r.rb', line 60

def ==(other)
  self.class === other && length == other.length && width == other.width
end

#inspectString

Returns:

  • (String)


35
36
37
# File 'lib/aixm/r.rb', line 35

def inspect
  %Q(#<#{self.class} #{to_s}>)
end

#surfaceFloat

Calculate the surface in square meters.

Returns:

  • (Float)


55
56
57
# File 'lib/aixm/r.rb', line 55

def surface
  length.to_m.dim * width.to_m.dim
end

#to_sString

Returns human readable representation (e.g. “25.0 m x 20.0 m”).

Returns:

  • (String)

    human readable representation (e.g. “25.0 m x 20.0 m”)



40
41
42
# File 'lib/aixm/r.rb', line 40

def to_s
  [length, width].join(' x ')
end