Class: ExtraSpace::Address

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

Overview

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

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)


40
41
42
43
44
45
# File 'lib/extraspace/address.rb', line 40

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

Instance Attribute Details

#cityString

Returns:

  • (String)


12
13
14
# File 'lib/extraspace/address.rb', line 12

def city
  @city
end

#stateString

Returns:

  • (String)


16
17
18
# File 'lib/extraspace/address.rb', line 16

def state
  @state
end

#streetString

Returns:

  • (String)


8
9
10
# File 'lib/extraspace/address.rb', line 8

def street
  @street
end

#zipString

Returns:

  • (String)


20
21
22
# File 'lib/extraspace/address.rb', line 20

def zip
  @zip
end

Class Method Details

.parse(data:) ⇒ Address

Parameters:

  • data (Hash)

Returns:



25
26
27
28
29
30
31
32
33
34
# File 'lib/extraspace/address.rb', line 25

def self.parse(data:)
  lines = %w[line1 line2 line3 line4].map { |key| data[key] }

  new(
    street: lines.compact.reject(&:empty?).join(' '),
    city: data['city'],
    state: data['stateName'],
    zip: data['postalCode']
  )
end

Instance Method Details

#inspectString

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
# File 'lib/extraspace/address.rb', line 48

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

#textString

Returns:

  • (String)


59
60
61
# File 'lib/extraspace/address.rb', line 59

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