Class: NWS::GeocodingResult

Inherits:
Object
  • Object
show all
Defined in:
lib/nws/geocoder.rb

Overview

Represents a geocoding result with coordinates and metadata

Constant Summary collapse

ATTRIBUTION =

Returns Attribution text required by ODbL license.

Returns:

  • (String)

    Attribution text required by ODbL license

Geocoder::ATTRIBUTION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude:, longitude:, display_name:, place_type:, from_cache: false) ⇒ GeocodingResult

Initialize a new GeocodingResult

Parameters:

  • latitude (Float)

    Latitude of the location

  • longitude (Float)

    Longitude of the location

  • display_name (String)

    Full display name of the location

  • place_type (String)

    Type of place

  • from_cache (Boolean) (defaults to: false)

    Whether this result was retrieved from cache



240
241
242
243
244
245
246
# File 'lib/nws/geocoder.rb', line 240

def initialize(latitude:, longitude:, display_name:, place_type:, from_cache: false)
  @latitude = latitude
  @longitude = longitude
  @display_name = display_name
  @place_type = place_type
  @from_cache = from_cache
end

Instance Attribute Details

#display_nameString (readonly)

Returns Full display name of the location.

Returns:

  • (String)

    Full display name of the location



222
223
224
# File 'lib/nws/geocoder.rb', line 222

def display_name
  @display_name
end

#from_cacheBoolean (readonly)

Returns Whether this result was retrieved from cache.

Returns:

  • (Boolean)

    Whether this result was retrieved from cache



228
229
230
# File 'lib/nws/geocoder.rb', line 228

def from_cache
  @from_cache
end

#latitudeFloat (readonly)

Returns Latitude of the location.

Returns:

  • (Float)

    Latitude of the location



216
217
218
# File 'lib/nws/geocoder.rb', line 216

def latitude
  @latitude
end

#longitudeFloat (readonly)

Returns Longitude of the location.

Returns:

  • (Float)

    Longitude of the location



219
220
221
# File 'lib/nws/geocoder.rb', line 219

def longitude
  @longitude
end

#place_typeString (readonly)

Returns Type of place (e.g., “city”, “administrative”).

Returns:

  • (String)

    Type of place (e.g., “city”, “administrative”)



225
226
227
# File 'lib/nws/geocoder.rb', line 225

def place_type
  @place_type
end

Instance Method Details

#attributionString

Get the required attribution text

Returns:

  • (String)

    Attribution text for OpenStreetMap/ODbL



272
273
274
# File 'lib/nws/geocoder.rb', line 272

def attribution
  ATTRIBUTION
end

#from_cache?Boolean

Check if this result was retrieved from cache

Returns:

  • (Boolean)

    True if from cache



251
252
253
# File 'lib/nws/geocoder.rb', line 251

def from_cache?
  @from_cache
end

#to_aArray<Float>

Convert to array of [latitude, longitude]

Returns:

  • (Array<Float>)

    Coordinate pair as [latitude, longitude]



258
259
260
# File 'lib/nws/geocoder.rb', line 258

def to_a
  [latitude, longitude]
end

#to_sString

Get a formatted string representation

Returns:

  • (String)

    Coordinates and display name



265
266
267
# File 'lib/nws/geocoder.rb', line 265

def to_s
  "#{latitude}, #{longitude} (#{display_name})"
end