Class: GeonamesClient::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/geonames_client/location.rb

Overview

This class is not suitable for distances over a couple of miles. Due to the fact that spherical triginometry must be employed due to the curvature of the earth.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude_in_decimal_degrees, longitude_in_decimal_degrees) ⇒ Location

Returns a new instance of Location.



9
10
11
12
13
# File 'lib/geonames_client/location.rb', line 9

def initialize( latitude_in_decimal_degrees,
                longitude_in_decimal_degrees )
  @latitude_in_decimal_degrees  = latitude_in_decimal_degrees
  @longitude_in_decimal_degrees = longitude_in_decimal_degrees
end

Instance Attribute Details

#latitude_in_decimal_degreesObject (readonly)

Returns the value of attribute latitude_in_decimal_degrees.



7
8
9
# File 'lib/geonames_client/location.rb', line 7

def latitude_in_decimal_degrees
  @latitude_in_decimal_degrees
end

#longitude_in_decimal_degreesObject (readonly)

Returns the value of attribute longitude_in_decimal_degrees.



7
8
9
# File 'lib/geonames_client/location.rb', line 7

def longitude_in_decimal_degrees
  @longitude_in_decimal_degrees
end

Instance Method Details

#==(another_location) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/geonames_client/location.rb', line 56

def ==( another_location )
  return false unless another_location.is_a?( Location )
  return false unless another_location.latitude_in_decimal_degrees == latitude_in_decimal_degrees
  return false unless another_location.longitude_in_decimal_degrees == longitude_in_decimal_degrees

  true
end

#bounding_box_locations(distance) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/geonames_client/location.rb', line 38

def bounding_box_locations( distance )
  %w(
    northeast
    northwest
    southwest
    southeast
  ).map do |direction|
    send( "bounding_box_#{direction}_location", distance )
  end
end

#bounding_box_locations_as_array(distance) ⇒ Object



15
16
17
# File 'lib/geonames_client/location.rb', line 15

def bounding_box_locations_as_array( distance )
  bounding_box_locations( distance ).map &:to_a
end

#bounding_box_locations_as_hash(distance) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/geonames_client/location.rb', line 28

def bounding_box_locations_as_hash( distance )
  hash = {}

  bounding_box_locations_as_hash_like_array( distance ).each do |direction, location|
    hash[direction] = location
  end

  hash
end

#bounding_box_locations_as_hash_like_array(distance) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/geonames_client/location.rb', line 19

def bounding_box_locations_as_hash_like_array( distance )
    [
      :northeast,
      :northwest,
      :southwest,
      :southeast
    ].zip( bounding_box_locations_as_array( distance ) )
end

#to_aObject



49
50
51
52
53
54
# File 'lib/geonames_client/location.rb', line 49

def to_a
  [
    latitude_in_decimal_degrees,
    longitude_in_decimal_degrees
  ]
end