Class: Strava::Models::LatLng
- Inherits:
-
Object
- Object
- Strava::Models::LatLng
- Defined in:
- lib/strava/models/lat_lng.rb
Overview
Represents geographic coordinates (latitude/longitude).
This is a helper class for working with geographic coordinates in Strava data. Coordinates are stored as an array [latitude, longitude] and can be accessed via helper methods or array syntax.
Instance Attribute Summary collapse
-
#latlng ⇒ Array<Float>
Coordinates as [latitude, longitude].
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare with another LatLng or Array.
-
#initialize(latlng = nil) ⇒ LatLng
constructor
Initialize with coordinates.
-
#inspect ⇒ String
(also: #to_s)
String representation of coordinates.
-
#lat ⇒ Float?
Latitude.
- #lat=(value) ⇒ Object
-
#lng ⇒ Float?
Longitude.
- #lng=(value) ⇒ Object
-
#to_a ⇒ Array<Float>
(also: #to_h, #as_json)
Coordinates as array [latitude, longitude].
-
#to_json(*args) ⇒ String
JSON representation.
Constructor Details
#initialize(latlng = nil) ⇒ LatLng
Initialize with coordinates.
33 34 35 |
# File 'lib/strava/models/lat_lng.rb', line 33 def initialize(latlng = nil) @latlng = latlng end |
Instance Attribute Details
#latlng ⇒ Array<Float>
Returns Coordinates as [latitude, longitude].
26 27 28 |
# File 'lib/strava/models/lat_lng.rb', line 26 def latlng @latlng end |
Instance Method Details
#==(other) ⇒ Boolean
Compare with another LatLng or Array.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/strava/models/lat_lng.rb', line 65 def ==(other) case other when LatLng @latlng == other.to_a when Array @latlng == other else false end end |
#inspect ⇒ String Also known as: to_s
Returns String representation of coordinates.
90 91 92 |
# File 'lib/strava/models/lat_lng.rb', line 90 def inspect @latlng.inspect end |
#lat ⇒ Float?
Returns Latitude.
38 39 40 |
# File 'lib/strava/models/lat_lng.rb', line 38 def lat @latlng[0] end |
#lat=(value) ⇒ Object
48 49 50 51 |
# File 'lib/strava/models/lat_lng.rb', line 48 def lat=(value) @latlng ||= [nil, nil] @latlng[0] = value end |
#lng ⇒ Float?
Returns Longitude.
43 44 45 |
# File 'lib/strava/models/lat_lng.rb', line 43 def lng @latlng[1] end |
#lng=(value) ⇒ Object
54 55 56 57 |
# File 'lib/strava/models/lat_lng.rb', line 54 def lng=(value) @latlng ||= [nil, nil] @latlng[1] = value end |
#to_a ⇒ Array<Float> Also known as: to_h, as_json
Returns Coordinates as array [latitude, longitude].
77 78 79 |
# File 'lib/strava/models/lat_lng.rb', line 77 def to_a @latlng end |
#to_json(*args) ⇒ String
Returns JSON representation.
85 86 87 |
# File 'lib/strava/models/lat_lng.rb', line 85 def to_json(*args) as_json.to_json(args) end |