runby_pace 0.6.123 → 0.6.124
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/runby_pace/distance.rb +42 -5
- data/lib/runby_pace/distance_unit.rb +3 -3
- data/lib/runby_pace/run_math.rb +5 -3
- data/lib/runby_pace/runby_time.rb +8 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab3528d5bb2681d6241b9ca99106635041ede241
|
4
|
+
data.tar.gz: 6fd638b564e1cd2624edabb1a9833d94483c757b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0157335b0c09de79498c21c5ddd8db68d82719dcab782731d7ffbcf66756499cc7a1562e46fc58e5abc80a3f4615865dc2e382ca74ce3c6a853c93101af8f76f
|
7
|
+
data.tar.gz: 45f5e6e4d3519630ca5cd8eebae21f96d0dd0af839ef1cbeca6ddaf1ac68b4acd599642dd2d803ef72af7a4babd8ac3c57a50110721aab3af6a71d019ca52696
|
data/lib/runby_pace/distance.rb
CHANGED
@@ -19,8 +19,8 @@ module Runby
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def convert_to(
|
23
|
-
target_uom = DistanceUnit.new
|
22
|
+
def convert_to(target_uom)
|
23
|
+
target_uom = DistanceUnit.new target_uom unless target_uom.is_a?(DistanceUnit)
|
24
24
|
target_multiplier = kilometers / (target_uom.conversion_factor * 1.0)
|
25
25
|
Distance.new target_uom, target_multiplier
|
26
26
|
end
|
@@ -43,7 +43,7 @@ module Runby
|
|
43
43
|
parsed_uom = Runby::DistanceUnit.parse uom
|
44
44
|
raise "'#{uom.strip}' is not recognized as a distance unit" if parsed_uom.nil?
|
45
45
|
|
46
|
-
|
46
|
+
new parsed_uom, multiplier
|
47
47
|
end
|
48
48
|
|
49
49
|
def self.try_parse(str)
|
@@ -51,7 +51,7 @@ module Runby
|
|
51
51
|
begin
|
52
52
|
distance = parse str
|
53
53
|
rescue StandardError => ex
|
54
|
-
error_message =
|
54
|
+
error_message = ex.message.to_s
|
55
55
|
end
|
56
56
|
{ distance: distance, error: error_message }
|
57
57
|
end
|
@@ -64,15 +64,52 @@ module Runby
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# @param [Distance, String] other
|
67
68
|
def <=>(other)
|
68
69
|
raise "Cannot compare Runby::Distance to #{other.class}" unless [Distance, String].include? other.class
|
69
70
|
if other.is_a?(String)
|
70
71
|
return 0 if to_s == other || to_s(format: :long) == other
|
71
|
-
return self <=> try_parse(other)[:distance]
|
72
|
+
return self <=> Distance.try_parse(other)[:distance]
|
72
73
|
end
|
73
74
|
kilometers <=> other.kilometers
|
74
75
|
end
|
75
76
|
|
77
|
+
# @param [Distance] other
|
78
|
+
# @return [Distance]
|
79
|
+
def +(other)
|
80
|
+
raise "Cannot add Runby::Distance to #{other.class}" unless other.is_a?(Distance)
|
81
|
+
sum_in_km = Distance.new(:km, kilometers + other.kilometers)
|
82
|
+
sum_in_km.convert_to(@uom)
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param [Distance] other
|
86
|
+
# @return [Distance]
|
87
|
+
def -(other)
|
88
|
+
raise "Cannot add Runby::Distance to #{other.class}" unless other.is_a?(Distance)
|
89
|
+
sum_in_km = Distance.new(:km, kilometers - other.kilometers)
|
90
|
+
sum_in_km.convert_to(@uom)
|
91
|
+
end
|
92
|
+
|
93
|
+
# @param [Numeric] other
|
94
|
+
# @return [Distance]
|
95
|
+
def *(other)
|
96
|
+
raise "Cannot multiply Runby::Distance by #{other.class}" unless other.is_a?(Numeric)
|
97
|
+
product_in_km = Distance.new(:km, kilometers * other)
|
98
|
+
product_in_km.convert_to(@uom)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @param [Numeric, Distance] other
|
102
|
+
# @return [Distance, Numeric]
|
103
|
+
def /(other)
|
104
|
+
raise "Cannot divide Runby::Distance by #{other.class}" unless other.is_a?(Numeric) || other.is_a?(Distance)
|
105
|
+
if other.is_a?(Numeric)
|
106
|
+
quotient_in_km = Distance.new(:km, kilometers / other)
|
107
|
+
return quotient_in_km.convert_to(@uom)
|
108
|
+
elsif other.is_a?(Distance)
|
109
|
+
return kilometers / other.kilometers
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
76
113
|
private
|
77
114
|
|
78
115
|
def init_from_clone(distance)
|
@@ -40,7 +40,7 @@ module Runby
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
raise "Error parsing distance unit '#{description}'" unless found_uom
|
43
|
-
|
43
|
+
DistanceUnit.new found_uom
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.try_parse(str)
|
@@ -48,14 +48,14 @@ module Runby
|
|
48
48
|
begin
|
49
49
|
uom = parse str
|
50
50
|
rescue StandardError => ex
|
51
|
-
error_message =
|
51
|
+
error_message = ex.message
|
52
52
|
end
|
53
53
|
{ uom: uom, error: error_message }
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.known_uom?(symbol)
|
57
57
|
# TODO: test
|
58
|
-
@@_uom_definitions.
|
58
|
+
@@_uom_definitions.key?(symbol)
|
59
59
|
end
|
60
60
|
|
61
61
|
def ==(other)
|
data/lib/runby_pace/run_math.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Runby
|
2
2
|
# An assortment of mathematical functions related to running.
|
3
3
|
class RunMath
|
4
|
-
def self.
|
5
|
-
|
6
|
-
|
4
|
+
def self.predict_race_time(race1_distance, race1_time, target_distance)
|
5
|
+
race1_distance = Distance.new(race1_distance)
|
6
|
+
race1_time = RunbyTime.new(race1_time)
|
7
|
+
target_distance = Distance.new(target_distance)
|
7
8
|
|
9
|
+
race1_time * (target_distance / race1_distance)**1.06
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -111,23 +111,27 @@ module Runby
|
|
111
111
|
|
112
112
|
# @param [RunbyTime] other
|
113
113
|
def -(other)
|
114
|
-
|
114
|
+
raise "Cannot subtract #{other.class} from a Runby::RunbyTime" unless other.is_a?(RunbyTime)
|
115
|
+
RunbyTime.from_seconds(total_seconds - other.total_seconds)
|
115
116
|
end
|
116
117
|
|
117
118
|
# @param [RunbyTime] other
|
118
119
|
def +(other)
|
119
|
-
RunbyTime
|
120
|
+
raise "Cannot add Runby::RunbyTime to a #{other.class}" unless other.is_a?(RunbyTime)
|
121
|
+
RunbyTime.from_seconds(total_seconds + other.total_seconds)
|
120
122
|
end
|
121
123
|
|
122
124
|
# @param [Numeric] other
|
123
125
|
# @return [RunbyTime]
|
124
126
|
def *(other)
|
125
|
-
|
127
|
+
raise "Cannot multiply Runby::RunbyTime with a #{other.class}" unless other.is_a?(Numeric)
|
128
|
+
RunbyTime.from_minutes(total_minutes * other)
|
126
129
|
end
|
127
130
|
|
128
131
|
# @param [RunbyTime, Numeric] other
|
129
132
|
# @return [Numeric, RunbyTime]
|
130
133
|
def /(other)
|
134
|
+
raise "Cannot divide Runby::RunbyTime by #{other.class}" unless other.is_a?(RunbyTime) || other.is_a?(Numeric)
|
131
135
|
case other
|
132
136
|
when RunbyTime
|
133
137
|
total_seconds / other.total_seconds
|
@@ -137,6 +141,7 @@ module Runby
|
|
137
141
|
end
|
138
142
|
|
139
143
|
def <=>(other)
|
144
|
+
raise "Cannot compare Runby::RunbyTime to #{other.class}" unless [RunbyTime, String].include? other.class
|
140
145
|
if other.is_a? RunbyTime
|
141
146
|
total_seconds <=> other.total_seconds
|
142
147
|
elsif other.is_a? String
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runby_pace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.124
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Walls
|
@@ -101,7 +101,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
101
101
|
licenses:
|
102
102
|
- MIT
|
103
103
|
metadata:
|
104
|
-
commit-hash:
|
104
|
+
commit-hash: 806f350b205ca30ba6edc582c854c11ee4ac2ac1
|
105
105
|
post_install_message:
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|