Class: UHaul::Price

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

Overview

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

Constant Summary collapse

ID_REGEX =
%r{(?<id>\d+)/(?:rent|reserve)/}
PRICE_SELECTOR =
'[data-unit-size="small"],[data-unit-size="medium"],[data-unit-size="large"]'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Price.

Parameters:



29
30
31
32
33
34
# File 'lib/uhaul/price.rb', line 29

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

Instance Attribute Details

#dimensionsDimensions

Returns:



15
16
17
# File 'lib/uhaul/price.rb', line 15

def dimensions
  @dimensions
end

#featuresFeatures

Returns:



19
20
21
# File 'lib/uhaul/price.rb', line 19

def features
  @features
end

#idString

Returns:

  • (String)


11
12
13
# File 'lib/uhaul/price.rb', line 11

def id
  @id
end

#ratesRates

Returns:



23
24
25
# File 'lib/uhaul/price.rb', line 23

def rates
  @rates
end

Class Method Details

.parse(element:) ⇒ Price

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/uhaul/price.rb', line 55

def self.parse(element:)
  id_element = element.at_css('form input[name="RentableInventoryPk"]')
  return unless id_element

  id = id_element['value']
  text = element.text.strip.gsub(/\s+/, ' ')

  dimensions = Dimensions.parse(text:)
  features = Features.parse(text:)
  rates = Rates.parse(text:)

  new(id:, dimensions:, features:, rates:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
# File 'lib/uhaul/price.rb', line 37

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

#textString

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

Returns:

  • (String)

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



48
49
50
# File 'lib/uhaul/price.rb', line 48

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