Class: UHaul::Address

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

Overview

The address (street + city + state + zip) of a facility.

Constant Summary collapse

ADDRESS_SELECTOR =
'.item-des-box .text-box .part_title_1'
ADDRESS_REGEX =
/(?<street>.+),\s+(?<city>.+),\s+(?<state>.+)\s+(?<zip>\d{5})/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(street:, city:, state:, zip:) ⇒ Address

Returns a new instance of Address.

Parameters:

  • street (String)
  • city (String)
  • state (String)
  • zip (String)


28
29
30
31
32
33
# File 'lib/uhaul/address.rb', line 28

def initialize(street:, city:, state:, zip:)
  @street = street
  @city = city
  @state = state
  @zip = zip
end

Instance Attribute Details

#cityString

Returns:

  • (String)


14
15
16
# File 'lib/uhaul/address.rb', line 14

def city
  @city
end

#stateString

Returns:

  • (String)


18
19
20
# File 'lib/uhaul/address.rb', line 18

def state
  @state
end

#streetString

Returns:

  • (String)


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

def street
  @street
end

#zipString

Returns:

  • (String)


22
23
24
# File 'lib/uhaul/address.rb', line 22

def zip
  @zip
end

Class Method Details

.parse(data:) ⇒ Address

Parameters:

  • data (Hash)

Returns:



54
55
56
57
58
59
60
61
# File 'lib/uhaul/address.rb', line 54

def self.parse(data:)
  new(
    street: data['streetAddress'],
    city: data['addressLocality'],
    state: data['addressRegion'],
    zip: data['postalCode']
  )
end

Instance Method Details

#inspectString

Returns:

  • (String)


36
37
38
39
40
41
42
43
44
# File 'lib/uhaul/address.rb', line 36

def inspect
  props = [
    "street=#{@street.inspect}",
    "city=#{@city.inspect}",
    "state=#{@state.inspect}",
    "zip=#{@zip.inspect}"
  ]
  "#<#{self.class.name} #{props.join(' ')}>"
end

#textString

Returns:

  • (String)


47
48
49
# File 'lib/uhaul/address.rb', line 47

def text
  "#{street}, #{city}, #{state} #{zip}"
end