Class: NSAStorage::Geocode

Inherits:
Object
  • Object
show all
Defined in:
lib/nsastorage/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)


31
32
33
34
# File 'lib/nsastorage/geocode.rb', line 31

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

Instance Attribute Details

#latitudeFloat

Returns:

  • (Float)


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

def latitude
  @latitude
end

#longitudeFloat

Returns:

  • (Float)


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

def longitude
  @longitude
end

Class Method Details

.parse(document:) ⇒ Geocode

Parameters:

  • document (Nokogiri::HTML::Document)

Returns:



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

def self.parse(document:)
  latitude = LATITUDE_REGEX.match(document.text)&.[](:latitude)
  longitude = LONGITUDE_REGEX.match(document.text)&.[](:longitude)

  return if latitude.nil? || longitude.nil?

  new(latitude: Float(latitude), longitude: Float(longitude))
end

Instance Method Details

#inspectString

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/nsastorage/geocode.rb', line 37

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

#textString

Returns:

  • (String)


46
47
48
# File 'lib/nsastorage/geocode.rb', line 46

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