Class: CubeSmart::Rates
- Inherits:
-
Object
- Object
- CubeSmart::Rates
- Defined in:
- lib/cubesmart/rates.rb
Overview
The rates (street + web) for a facility
Constant Summary collapse
- STREET_SELECTOR =
'.ptOriginalPriceSpan'
- WEB_SELECTOR =
'.ptDiscountPriceSpan'
- VALUE_REGEX =
/(?<value>[\d\.]+)/
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(street:, web:) ⇒ Rates
constructor
A new instance of Rates.
- #inspect ⇒ String
-
#text ⇒ String
E.g.
Constructor Details
#initialize(street:, web:) ⇒ Rates
Returns a new instance of Rates.
40 41 42 43 |
# File 'lib/cubesmart/rates.rb', line 40 def initialize(street:, web:) @street = street @web = web end |
Instance Attribute Details
#street ⇒ Integer
12 13 14 |
# File 'lib/cubesmart/rates.rb', line 12 def street @street end |
#web ⇒ Integer
16 17 18 |
# File 'lib/cubesmart/rates.rb', line 16 def web @web end |
Class Method Details
.parse(element:) ⇒ Rates
21 22 23 24 25 26 |
# File 'lib/cubesmart/rates.rb', line 21 def self.parse(element:) street = parse_value(element: element.at_css(STREET_SELECTOR)) web = parse_value(element: element.at_css(WEB_SELECTOR)) new(street: street || web, web: web || street) end |
.parse_value(element:) ⇒ Float?
31 32 33 34 35 36 |
# File 'lib/cubesmart/rates.rb', line 31 def self.parse_value(element:) return if element.nil? match = VALUE_REGEX.match(element.text) Float(match[:value]) if match end |
Instance Method Details
#inspect ⇒ String
46 47 48 49 50 51 52 |
# File 'lib/cubesmart/rates.rb', line 46 def inspect props = [ "street=#{@street.inspect}", "web=#{@web.inspect}" ] "#<#{self.class.name} #{props.join(' ')}>" end |
#text ⇒ String
Returns e.g. “$80 (street) | $60 (web)”.
55 56 57 |
# File 'lib/cubesmart/rates.rb', line 55 def text "$#{@street} (street) | $#{@web} (web)" end |