Class: Strava::Models::LatLng

Inherits:
Object
  • Object
show all
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.

Examples:

Accessing coordinates

activity = client.activity(1234567890)
start = activity.start_latlng
puts "Latitude: #{start.lat}"
puts "Longitude: #{start.lng}"
puts "Array: #{start.to_a.inspect}"  # [40.7128, -74.0060]

Creating coordinates

coords = Strava::Models::LatLng.new([40.7128, -74.0060])
coords.lat  # => 40.7128
coords.lng  # => -74.0060

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latlng = nil) ⇒ LatLng

Initialize with coordinates.

Parameters:

  • latlng (Array<Float>, nil) (defaults to: nil)

    Coordinates as [latitude, longitude]



33
34
35
# File 'lib/strava/models/lat_lng.rb', line 33

def initialize(latlng = nil)
  @latlng = latlng
end

Instance Attribute Details

#latlngArray<Float>

Returns Coordinates as [latitude, longitude].

Returns:

  • (Array<Float>)

    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.

Parameters:

  • other (LatLng, Array)

    Object to compare with

Returns:

  • (Boolean)

    true if coordinates are equal



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

#inspectString Also known as: to_s

Returns String representation of coordinates.

Returns:

  • (String)

    String representation of coordinates



90
91
92
# File 'lib/strava/models/lat_lng.rb', line 90

def inspect
  @latlng.inspect
end

#latFloat?

Returns Latitude.

Returns:

  • (Float, nil)

    Latitude



38
39
40
# File 'lib/strava/models/lat_lng.rb', line 38

def lat
  @latlng[0]
end

#lat=(value) ⇒ Object

Parameters:

  • value (Float)

    Latitude value



48
49
50
51
# File 'lib/strava/models/lat_lng.rb', line 48

def lat=(value)
  @latlng ||= [nil, nil]
  @latlng[0] = value
end

#lngFloat?

Returns Longitude.

Returns:

  • (Float, nil)

    Longitude



43
44
45
# File 'lib/strava/models/lat_lng.rb', line 43

def lng
  @latlng[1]
end

#lng=(value) ⇒ Object

Parameters:

  • value (Float)

    Longitude value



54
55
56
57
# File 'lib/strava/models/lat_lng.rb', line 54

def lng=(value)
  @latlng ||= [nil, nil]
  @latlng[1] = value
end

#to_aArray<Float> Also known as: to_h, as_json

Returns Coordinates as array [latitude, longitude].

Returns:

  • (Array<Float>)

    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.

Returns:

  • (String)

    JSON representation



85
86
87
# File 'lib/strava/models/lat_lng.rb', line 85

def to_json(*args)
  as_json.to_json(args)
end