Class: ExtraSpace::Dimensions

Inherits:
Object
  • Object
show all
Defined in:
lib/extraspace/dimensions.rb

Overview

The dimensions (width + depth + sqft) of a price.

Constant Summary collapse

DEFAULT_HEIGHT =

feet

8.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth:, width:, height: DEFAULT_HEIGHT) ⇒ Dimensions

Returns a new instance of Dimensions.

Parameters:

  • depth (Float)
  • width (Float)
  • height (Float) (defaults to: DEFAULT_HEIGHT)


30
31
32
33
34
# File 'lib/extraspace/dimensions.rb', line 30

def initialize(depth:, width:, height: DEFAULT_HEIGHT)
  @depth = depth
  @width = width
  @height = height
end

Instance Attribute Details

#depthFloat

Returns:

  • (Float)


10
11
12
# File 'lib/extraspace/dimensions.rb', line 10

def depth
  @depth
end

#heightFloat

Returns:

  • (Float)


18
19
20
# File 'lib/extraspace/dimensions.rb', line 18

def height
  @height
end

#widthFloat

Returns:

  • (Float)


14
15
16
# File 'lib/extraspace/dimensions.rb', line 14

def width
  @width
end

Class Method Details

.parse(data:) ⇒ Dimensions

Parameters:

  • data (Hash)

Returns:



23
24
25
# File 'lib/extraspace/dimensions.rb', line 23

def self.parse(data:)
  new(depth: data['depth'], width: data['width'], height: DEFAULT_HEIGHT)
end

Instance Method Details

#cuftInteger

Returns:

  • (Integer)


52
53
54
# File 'lib/extraspace/dimensions.rb', line 52

def cuft
  Integer(@width * @depth * @height)
end

#inspectString

Returns:

  • (String)


37
38
39
40
41
42
43
44
# File 'lib/extraspace/dimensions.rb', line 37

def inspect
  props = [
    "depth=#{@depth.inspect}",
    "width=#{@width.inspect}",
    "height=#{@height.inspect}"
  ]
  "#<#{self.class.name} #{props.join(' ')}>"
end

#sqftInteger

Returns:

  • (Integer)


47
48
49
# File 'lib/extraspace/dimensions.rb', line 47

def sqft
  Integer(@width * @depth)
end

#textString

Returns e.g. “10’ × 10’ (100 sqft)”.

Returns:

  • (String)

    e.g. “10’ × 10’ (100 sqft)”



57
58
59
# File 'lib/extraspace/dimensions.rb', line 57

def text
  "#{format('%g', @width)}' × #{format('%g', @depth)}' (#{sqft} sqft)"
end