Class: UHaul::Price
- Inherits:
-
Object
- Object
- UHaul::Price
- 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
-
#initialize(id:, dimensions:, features:, rates:) ⇒ Price
constructor
A new instance of Price.
- #inspect ⇒ String
-
#text ⇒ String
E.g.
Constructor Details
#initialize(id:, dimensions:, features:, rates:) ⇒ Price
Returns a new instance of Price.
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
#dimensions ⇒ Dimensions
15 16 17 |
# File 'lib/uhaul/price.rb', line 15 def dimensions @dimensions end |
#id ⇒ String
11 12 13 |
# File 'lib/uhaul/price.rb', line 11 def id @id end |
Class Method Details
.parse(element:) ⇒ Price
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
#inspect ⇒ 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 |
#text ⇒ String
Returns 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 |