Class: PublicStorage::Dimensions

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

Overview

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

Constant Summary collapse

SELECTOR =
'.unit-size'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(depth:, width:, sqft:) ⇒ Dimensions

Returns a new instance of Dimensions.

Parameters:

  • depth (Float)
  • width (Float)
  • sqft (Integer)


23
24
25
26
27
# File 'lib/publicstorage/dimensions.rb', line 23

def initialize(depth:, width:, sqft:)
  @depth = depth
  @width = width
  @sqft = sqft
end

Instance Attribute Details

#depthInteger

Returns:

  • (Integer)


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

def depth
  @depth
end

#sqftInteger

Returns:

  • (Integer)


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

def sqft
  @sqft
end

#widthInteger

Returns:

  • (Integer)


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

def width
  @width
end

Class Method Details

.parse(data:) ⇒ Dimensions

Parameters:

  • data (Hash)

Returns:



47
48
49
50
51
52
53
54
# File 'lib/publicstorage/dimensions.rb', line 47

def self.parse(data:)
  match = data['dimension'].match(/(?<depth>[\d\.]+)'x(?<width>[\d\.]+)'/)
  depth = Float(match[:depth])
  width = Float(match[:width])
  sqft = Integer(depth * width)

  new(depth:, width:, sqft:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


30
31
32
33
34
35
36
37
# File 'lib/publicstorage/dimensions.rb', line 30

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

#textString

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

Returns:

  • (String)

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



40
41
42
# File 'lib/publicstorage/dimensions.rb', line 40

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