Class: UHaul::Rates

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

Overview

The rates (street + web) for a facility

Constant Summary collapse

RATE_REGEX =
/\$(?<price>[\d\.\,]+) Per Month/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(price:) ⇒ Rates

Returns a new instance of Rates.

Parameters:

  • street (Integer)
  • web (Integer)


26
27
28
# File 'lib/uhaul/rates.rb', line 26

def initialize(price:)
  @price = price
end

Instance Attribute Details

#priceObject Also known as: street, web

Returns the value of attribute price.



10
11
12
# File 'lib/uhaul/rates.rb', line 10

def price
  @price
end

#rateInteger

Returns:

  • (Integer)


10
# File 'lib/uhaul/rates.rb', line 10

attr_accessor :price

Class Method Details

.parse(text:) ⇒ Rates

Parameters:

  • text (String)

Returns:



18
19
20
21
22
# File 'lib/uhaul/rates.rb', line 18

def self.parse(text:)
  price = Float(RATE_REGEX.match(text)[:price].gsub(',', ''))

  new(price:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


31
32
33
# File 'lib/uhaul/rates.rb', line 31

def inspect
  "#<#{self.class.name} price=#{@price.inspect}>"
end

#textString

Returns e.g. “$80”.

Returns:

  • (String)

    e.g. “$80”



36
37
38
# File 'lib/uhaul/rates.rb', line 36

def text
  "$#{@price}"
end