Class: GoogleMapsAPI::Core::Coordinate

Inherits:
Object
  • Object
show all
Defined in:
lib/google_maps_api/core/coordinate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat, lng) ⇒ Coordinate

Returns a new instance of Coordinate.



4
5
6
7
# File 'lib/google_maps_api/core/coordinate.rb', line 4

def initialize(lat, lng)
  @lat = lat.to_f
  @lng = lng.to_f
end

Instance Attribute Details

#latObject (readonly)

Returns the value of attribute lat.



2
3
4
# File 'lib/google_maps_api/core/coordinate.rb', line 2

def lat
  @lat
end

#lngObject (readonly)

Returns the value of attribute lng.



2
3
4
# File 'lib/google_maps_api/core/coordinate.rb', line 2

def lng
  @lng
end

Class Method Details

.from_array(array) ⇒ Object



37
38
39
# File 'lib/google_maps_api/core/coordinate.rb', line 37

def self.from_array(array)
  self.new(array[0], array[1])
end

.from_hash(hash) ⇒ Object



33
34
35
# File 'lib/google_maps_api/core/coordinate.rb', line 33

def self.from_hash(hash)
  self.new(hash["lat"], hash["lng"])
end

Instance Method Details

#latitudeObject



9
10
11
# File 'lib/google_maps_api/core/coordinate.rb', line 9

def latitude
  lat
end

#lonObject



17
18
19
# File 'lib/google_maps_api/core/coordinate.rb', line 17

def lon
  lng
end

#longitudeObject



13
14
15
# File 'lib/google_maps_api/core/coordinate.rb', line 13

def longitude
  lng
end

#to_aObject



21
22
23
# File 'lib/google_maps_api/core/coordinate.rb', line 21

def to_a
  [lat, lng]
end

#to_aryObject



25
26
27
# File 'lib/google_maps_api/core/coordinate.rb', line 25

def to_ary
  to_a
end

#to_hObject



29
30
31
# File 'lib/google_maps_api/core/coordinate.rb', line 29

def to_h
  {"lat" => lat, "lng" => lng}
end