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