Class: CubeSmart::Rates

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(street:, web:) ⇒ Rates

Returns a new instance of Rates.

Parameters:

  • street (Integer)
  • web (Integer)


40
41
42
43
# File 'lib/cubesmart/rates.rb', line 40

def initialize(street:, web:)
  @street = street
  @web = web
end

Instance Attribute Details

#streetInteger

Returns:

  • (Integer)


12
13
14
# File 'lib/cubesmart/rates.rb', line 12

def street
  @street
end

#webInteger

Returns:

  • (Integer)


16
17
18
# File 'lib/cubesmart/rates.rb', line 16

def web
  @web
end

Class Method Details

.parse(element:) ⇒ Rates

Parameters:

  • element (Nokogiri::XML::Element)

Returns:



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?

Parameters:

  • element (Nokogiri::XML::Element)

Returns:

  • (Float, nil)


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

#inspectString

Returns:

  • (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

#textString

Returns e.g. “$80 (street) | $60 (web)”.

Returns:

  • (String)

    e.g. “$80 (street) | $60 (web)”



55
56
57
# File 'lib/cubesmart/rates.rb', line 55

def text
  "$#{@street} (street) | $#{@web} (web)"
end