-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
distance.rb
63 lines (47 loc) · 1.26 KB
/
distance.rb
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
# frozen_string_literal: true
module Strava
module Models
module Mixins
module Distance
extend ActiveSupport::Concern
included do
property 'distance'
end
def distance_in_meters
distance
end
def distance_in_feet
distance * 3.28084
end
def distance_in_miles
distance_in_meters * 0.00062137
end
def distance_in_miles_s
return unless distance&.positive?
format('%gmi', format('%.2f', distance_in_miles))
end
def distance_in_yards
distance_in_meters * 1.09361
end
def distance_in_yards_s
return unless distance&.positive?
format('%gyd', format('%.1f', distance_in_yards))
end
def distance_in_meters_s
return unless distance&.positive?
format('%gm', format('%d', distance_in_meters))
end
def distance_in_kilometers
distance_in_meters / 1000
end
def distance_in_kilometers_s
return unless distance&.positive?
format('%gkm', format('%.2f', distance_in_kilometers))
end
def distance_s
distance_in_kilometers_s
end
end
end
end
end