Class: PublicStorage::Price

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

Overview

The price (id + dimensions + rate) for a facility

Constant Summary collapse

GTM_SELECTOR =
'button[data-gtmdata]'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, dimensions:, rates:) ⇒ Price

Returns a new instance of Price.

Parameters:



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

def initialize(id:, dimensions:, rates:)
  @id = id
  @dimensions = dimensions
  @rates = rates
end

Instance Attribute Details

#dimensionsDimensions

Returns:



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

def dimensions
  @dimensions
end

#idString

Returns:

  • (String)


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

def id
  @id
end

#ratesRates

Returns:



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

def rates
  @rates
end

Class Method Details

.parse(element:) ⇒ Price

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/publicstorage/price.rb', line 47

def self.parse(element:)
  data = JSON.parse(element.at(GTM_SELECTOR).attribute('data-gtmdata'))

  rates = Rates.parse(data:)
  dimensions = Dimensions.parse(data:)

  new(
    id: element.attr('data-unitid'),
    dimensions: dimensions,
    rates: rates
  )
end

Instance Method Details

#inspectString

Returns:

  • (String)


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

def inspect
  props = [
    "id=#{@id.inspect}",
    "dimensions=#{@dimensions.inspect}",
    "rates=#{@rates.inspect}"
  ]
  "#<#{self.class.name} #{props.join(' ')}>"
end

#textString

Returns e.g. “123 | 5’ × 5’ (25 sqft) | $100 (street) / $90 (web)”.

Returns:

  • (String)

    e.g. “123 | 5’ × 5’ (25 sqft) | $100 (street) / $90 (web)”



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

def text
  "#{@id} | #{@dimensions.text} | #{@rates.text}"
end