Class: NSAStorage::Geocode
- Inherits:
-
Object
- Object
- NSAStorage::Geocode
- 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
-
#initialize(latitude:, longitude:) ⇒ Geocode
constructor
A new instance of Geocode.
- #inspect ⇒ String
- #text ⇒ String
Constructor Details
#initialize(latitude:, longitude:) ⇒ Geocode
Returns a new instance of Geocode.
31 32 33 34 |
# File 'lib/nsastorage/geocode.rb', line 31 def initialize(latitude:, longitude:) @latitude = latitude @longitude = longitude end |
Instance Attribute Details
#latitude ⇒ Float
11 12 13 |
# File 'lib/nsastorage/geocode.rb', line 11 def latitude @latitude end |
#longitude ⇒ Float
15 16 17 |
# File 'lib/nsastorage/geocode.rb', line 15 def longitude @longitude end |
Class Method Details
.parse(document:) ⇒ Geocode
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
#inspect ⇒ 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 |
#text ⇒ String
46 47 48 |
# File 'lib/nsastorage/geocode.rb', line 46 def text "#{@latitude},#{@longitude}" end |