-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathtotal_elevation_gain.rb
More file actions
81 lines (72 loc) · 2.47 KB
/
total_elevation_gain.rb
File metadata and controls
81 lines (72 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
module Strava
module Models
module Mixins
#
# Provides total elevation gain conversion and formatting methods.
#
# Total elevation gain represents the cumulative upward elevation change
# during an activity. This is distinct from elevation_gain - this property
# is typically used for activities while elevation_gain is used for routes.
#
# This mixin adds the total_elevation_gain property and helper methods to
# convert and format it in meters or feet.
#
# @example Using total elevation gain helpers
# activity = client.activity(1234567890)
# puts activity.total_elevation_gain # => 725.3 (meters)
# puts activity.total_elevation_gain_s # => "725.3m"
# puts activity.total_elevation_gain_in_feet_s # => "2379.6ft"
#
module TotalElevationGain
extend ActiveSupport::Concern
included do
# @return [Float] Total elevation gain in meters
property 'total_elevation_gain'
end
#
# Returns total elevation gain in feet.
#
# @return [Float] Total elevation gain in feet
#
def total_elevation_gain_in_feet
total_elevation_gain * 3.28084
end
#
# Returns total elevation gain in meters (same as total_elevation_gain).
#
# @return [Float] Total elevation gain in meters
#
def total_elevation_gain_in_meters
total_elevation_gain
end
#
# Returns formatted total elevation gain in meters.
#
# @return [String, nil] Formatted elevation (e.g., "725.3m")
#
def total_elevation_gain_in_meters_s
return if total_elevation_gain.nil?
format('%gm', format('%.1f', total_elevation_gain_in_meters))
end
#
# Returns formatted total elevation gain in feet.
#
# @return [String, nil] Formatted elevation (e.g., "2379.6ft")
#
def total_elevation_gain_in_feet_s
return if total_elevation_gain.nil?
format('%gft', format('%.1f', total_elevation_gain_in_feet))
end
#
# Returns default formatted total elevation gain (meters).
#
# @return [String, nil] Formatted elevation (e.g., "725.3m")
#
def total_elevation_gain_s
total_elevation_gain_in_meters_s
end
end
end
end
end