Class: UHaul::Geocode

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

Overview

The geocode (latitude + longitude) of a facility.

Constant Summary collapse

LATITUDE_REGEX =
/\\u0022lat\\u0022:(?<latitude>[\+\-\d\.]+)/
LONGITUDE_REGEX =
/\\u0022long\\u0022:(?<longitude>[\+\-\d\.]+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude:, longitude:) ⇒ Geocode

Returns a new instance of Geocode.

Parameters:

  • latitude (Float)
  • longitude (Float)


29
30
31
32
# File 'lib/uhaul/geocode.rb', line 29

def initialize(latitude:, longitude:)
  @latitude = latitude
  @longitude = longitude
end

Instance Attribute Details

#latitudeFloat

Returns:

  • (Float)


11
12
13
# File 'lib/uhaul/geocode.rb', line 11

def latitude
  @latitude
end

#longitudeFloat

Returns:

  • (Float)


15
16
17
# File 'lib/uhaul/geocode.rb', line 15

def longitude
  @longitude
end

Class Method Details

.parse(data:) ⇒ Geocode

Parameters:

  • data (Hash)

Returns:



20
21
22
23
24
25
# File 'lib/uhaul/geocode.rb', line 20

def self.parse(data:)
  latitude = Float(data['latitude'])
  longitude = Float(data['longitude'])

  new(latitude:, longitude:)
end

Instance Method Details

#inspectString

Returns:

  • (String)


35
36
37
38
39
40
41
# File 'lib/uhaul/geocode.rb', line 35

def inspect
  props = [
    "latitude=#{@latitude.inspect}",
    "longitude=#{@longitude.inspect}"
  ]
  "#<#{self.class.name} #{props.join(' ')}>"
end

#textString

Returns:

  • (String)


44
45
46
# File 'lib/uhaul/geocode.rb', line 44

def text
  "#{@latitude},#{@longitude}"
end