runby_pace 0.6.136 → 0.6.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/runby_pace/distance_unit.rb +22 -17
- data/lib/runby_pace/golden_pace_set.rb +7 -7
- data/lib/runby_pace/run_types/distance_run.rb +16 -2
- data/lib/runby_pace/run_types/easy_run.rb +16 -2
- data/lib/runby_pace/run_types/long_run.rb +16 -2
- data/lib/runby_pace/run_types/tempo_run.rb +16 -2
- data/lib/runby_pace/runby_time.rb +11 -11
- data/lib/runby_pace/speed.rb +15 -13
- 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: 81bb614066b9c4b6adeae971f2669d7a7340ae18
|
4
|
+
data.tar.gz: 30c45f64bdca980098f74b2d2011d532a87e9bc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0adf46b7d38354400d1ac89ad30d3bf797b675aca5874f7b3aa141b4f47154abb6f4ee5e3a3df1cc33c9ac57061531f6555750ff11bdc1493083b6feaf4d6006
|
7
|
+
data.tar.gz: e25cb2fe2bbf8051501409453298e7b93383c7ae86569a55f2420853086226fc66cf47eb77ae892f5e5b83e1ea259d0b285fbfe1cf3023f8c7c3f6f9a81260e4
|
@@ -7,33 +7,33 @@ module Runby
|
|
7
7
|
|
8
8
|
def initialize(unit_of_measure)
|
9
9
|
if unit_of_measure.is_a? Symbol
|
10
|
-
raise "':#{unit_of_measure
|
10
|
+
raise "':#{unit_of_measure}' is an unknown unit of measure" unless DistanceUnit.known_uom? unit_of_measure
|
11
11
|
@symbol = unit_of_measure
|
12
|
-
@conversion_factor =
|
12
|
+
@conversion_factor = UOM_DEFINITIONS[@symbol][:conversion_factor]
|
13
13
|
elsif unit_of_measure.is_a? String
|
14
14
|
parsed_uom = DistanceUnit.parse(unit_of_measure)
|
15
15
|
@symbol = parsed_uom.symbol
|
16
|
-
@conversion_factor =
|
16
|
+
@conversion_factor = UOM_DEFINITIONS[@symbol][:conversion_factor]
|
17
17
|
end
|
18
18
|
|
19
|
-
@description =
|
19
|
+
@description = UOM_DEFINITIONS[@symbol][:description]
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_s(format: :long, pluralize: false)
|
23
23
|
case format
|
24
|
-
|
25
|
-
|
24
|
+
when :short then @symbol.to_s
|
25
|
+
when :long then pluralize ? description_plural : @description
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def description_plural
|
30
|
-
|
30
|
+
UOM_DEFINITIONS[@symbol][:description_plural]
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.parse(description)
|
34
34
|
description = description.strip.chomp.downcase
|
35
35
|
found_uom = nil
|
36
|
-
|
36
|
+
UOM_DEFINITIONS.each do |uom, details|
|
37
37
|
if details[:synonyms].include? description
|
38
38
|
found_uom = uom
|
39
39
|
break
|
@@ -55,7 +55,7 @@ module Runby
|
|
55
55
|
|
56
56
|
def self.known_uom?(symbol)
|
57
57
|
# TODO: test
|
58
|
-
|
58
|
+
UOM_DEFINITIONS.key?(symbol)
|
59
59
|
end
|
60
60
|
|
61
61
|
def ==(other)
|
@@ -68,14 +68,19 @@ module Runby
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
{ km: { description: 'kilometer', description_plural: 'kilometers', conversion_factor: 1.0,
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
71
|
+
UOM_DEFINITIONS =
|
72
|
+
{ km: { description: 'kilometer', description_plural: 'kilometers', conversion_factor: 1.0,
|
73
|
+
synonyms: %w[k km kms kilometer kilometers] },
|
74
|
+
m: { description: 'meter', description_plural: 'meters', conversion_factor: 0.001,
|
75
|
+
synonyms: %w[m meter meters] },
|
76
|
+
mi: { description: 'mile', description_plural: 'miles', conversion_factor: 1.609344,
|
77
|
+
synonyms: %w[mi mile miles] },
|
78
|
+
ft: { description: 'foot', description_plural: 'feet', conversion_factor: 0.0003048,
|
79
|
+
synonyms: %w[ft foot feet] },
|
80
|
+
yd: { description: 'yard', description_plural: 'yards', conversion_factor: 1093.61,
|
81
|
+
synonyms: %w[y yd yds yard yards] },
|
77
82
|
# Fun distance unit of measures
|
78
|
-
marathon: { description: 'marathon', description_plural: 'marathons', conversion_factor: 42.1648128,
|
79
|
-
|
83
|
+
marathon: { description: 'marathon', description_plural: 'marathons', conversion_factor: 42.1648128,
|
84
|
+
synonyms: %w[marathon] } }.freeze
|
80
85
|
end
|
81
86
|
end
|
@@ -10,10 +10,10 @@ module Runby
|
|
10
10
|
attr_reader :paces
|
11
11
|
|
12
12
|
# The fastest 5K time supported by RunbyPace
|
13
|
-
|
13
|
+
FASTEST_5K = :'14:00'
|
14
14
|
|
15
15
|
# The slowest 5K time supported by RunbyPace
|
16
|
-
|
16
|
+
SLOWEST_5K = :'42:00'
|
17
17
|
|
18
18
|
# @param [Hash] paces_hash is a hash mapping 5K time symbols to times, represented as strings.
|
19
19
|
# An example paces_hash is {'14:00':'4:00', '15:00':'4:55'}
|
@@ -30,19 +30,19 @@ module Runby
|
|
30
30
|
|
31
31
|
# Returns first/fastest recommended pace in the set
|
32
32
|
def first
|
33
|
-
@paces[
|
33
|
+
@paces[FASTEST_5K]
|
34
34
|
end
|
35
|
-
alias
|
35
|
+
alias fastest first
|
36
36
|
|
37
37
|
# Return the last/slowest recommended pace in the set
|
38
38
|
def last
|
39
|
-
@paces[
|
39
|
+
@paces[SLOWEST_5K]
|
40
40
|
end
|
41
|
-
alias
|
41
|
+
alias slowest last
|
42
42
|
|
43
43
|
# Creates and returns a new GoldenPaceSet with only two entries
|
44
44
|
def self.new_from_endpoints(fastest, slowest)
|
45
|
-
GoldenPaceSet.new(
|
45
|
+
GoldenPaceSet.new(FASTEST_5K => fastest, SLOWEST_5K => slowest)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -27,11 +27,25 @@ module Runby
|
|
27
27
|
# Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
|
28
28
|
class GoldenPaces
|
29
29
|
def self.fast
|
30
|
-
GoldenPaceSet.new(
|
30
|
+
GoldenPaceSet.new('14:00': '03:44',
|
31
|
+
'15:00': '03:58',
|
32
|
+
'20:00': '05:09',
|
33
|
+
'25:00': '06:18',
|
34
|
+
'30:00': '07:24',
|
35
|
+
'35:00': '08:29',
|
36
|
+
'40:00': '09:33',
|
37
|
+
'42:00': '09:58')
|
31
38
|
end
|
32
39
|
|
33
40
|
def self.slow
|
34
|
-
GoldenPaceSet.new(
|
41
|
+
GoldenPaceSet.new('14:00': '04:17',
|
42
|
+
'15:00': '04:33',
|
43
|
+
'20:00': '05:53',
|
44
|
+
'25:00': '07:09',
|
45
|
+
'30:00': '08:23',
|
46
|
+
'35:00': '09:33',
|
47
|
+
'40:00': '10:42',
|
48
|
+
'42:00': '11:10')
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -26,11 +26,25 @@ module Runby
|
|
26
26
|
# Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
|
27
27
|
class GoldenPaces
|
28
28
|
def self.fast
|
29
|
-
GoldenPaceSet.new(
|
29
|
+
GoldenPaceSet.new('14:00': '04:17',
|
30
|
+
'15:00': '04:33',
|
31
|
+
'20:00': '05:53',
|
32
|
+
'25:00': '07:09',
|
33
|
+
'30:00': '08:23',
|
34
|
+
'35:00': '09:33',
|
35
|
+
'40:00': '10:41',
|
36
|
+
'42:00': '11:08')
|
30
37
|
end
|
31
38
|
|
32
39
|
def self.slow
|
33
|
-
GoldenPaceSet.new(
|
40
|
+
GoldenPaceSet.new('14:00': '05:01',
|
41
|
+
'15:00': '05:20',
|
42
|
+
'20:00': '06:51',
|
43
|
+
'25:00': '08:17',
|
44
|
+
'30:00': '09:38',
|
45
|
+
'35:00': '10:56',
|
46
|
+
'40:00': '12:10',
|
47
|
+
'42:00': '12:39')
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
@@ -27,11 +27,25 @@ module Runby
|
|
27
27
|
# Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
|
28
28
|
class GoldenPaces
|
29
29
|
def self.fast
|
30
|
-
GoldenPaceSet.new(
|
30
|
+
GoldenPaceSet.new('14:00': '04:00',
|
31
|
+
'15:00': '04:16',
|
32
|
+
'20:00': '05:31',
|
33
|
+
'25:00': '06:44',
|
34
|
+
'30:00': '07:54',
|
35
|
+
'35:00': '09:01',
|
36
|
+
'40:00': '10:07',
|
37
|
+
'42:00': '10:32')
|
31
38
|
end
|
32
39
|
|
33
40
|
def self.slow
|
34
|
-
GoldenPaceSet.new(
|
41
|
+
GoldenPaceSet.new('14:00': '04:39',
|
42
|
+
'15:00': '04:57',
|
43
|
+
'20:00': '06:22',
|
44
|
+
'25:00': '07:43',
|
45
|
+
'30:00': '09:00',
|
46
|
+
'35:00': '10:15',
|
47
|
+
'40:00': '11:26',
|
48
|
+
'42:00': '11:53')
|
35
49
|
end
|
36
50
|
end
|
37
51
|
end
|
@@ -26,11 +26,25 @@ module Runby
|
|
26
26
|
# Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
|
27
27
|
class GoldenPaces
|
28
28
|
def self.fast
|
29
|
-
GoldenPaceSet.new(
|
29
|
+
GoldenPaceSet.new('14:00': '03:07',
|
30
|
+
'15:00': '03:20',
|
31
|
+
'20:00': '04:21',
|
32
|
+
'25:00': '05:20',
|
33
|
+
'30:00': '06:19',
|
34
|
+
'35:00': '07:16',
|
35
|
+
'40:00': '08:12',
|
36
|
+
'42:00': '08:35')
|
30
37
|
end
|
31
38
|
|
32
39
|
def self.slow
|
33
|
-
GoldenPaceSet.new(
|
40
|
+
GoldenPaceSet.new('14:00': '03:18',
|
41
|
+
'15:00': '03:31',
|
42
|
+
'20:00': '04:35',
|
43
|
+
'25:00': '05:37',
|
44
|
+
'30:00': '06:38',
|
45
|
+
'35:00': '07:38',
|
46
|
+
'40:00': '08:36',
|
47
|
+
'42:00': '08:59')
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
@@ -83,16 +83,16 @@ module Runby
|
|
83
83
|
rescue StandardError => ex
|
84
84
|
error_message = "#{ex.message} (#{str})"
|
85
85
|
end
|
86
|
-
|
87
|
-
# Break out these sanity checks into their own class if we add any more.
|
88
|
-
if !time.nil? && is_five_k
|
89
|
-
warning_message = '5K times of less than 14:00 are unlikely' if time.minutes_part < 14
|
90
|
-
warning_message = '5K times of greater than 42:00 are not fully supported' if time.total_seconds > (42 * 60)
|
91
|
-
end
|
92
|
-
|
86
|
+
warning_message = check_5k_sanity(time) if !time.nil? && is_five_k
|
93
87
|
{ time: time, error: error_message, warning: warning_message }
|
94
88
|
end
|
95
89
|
|
90
|
+
def self.check_5k_sanity(time)
|
91
|
+
return unless time.is_a? RunbyTime
|
92
|
+
return '5K times of less than 14:00 are unlikely' if time.minutes_part < 14
|
93
|
+
return '5K times of greater than 42:00 are not fully supported' if time.total_seconds > (42 * 60)
|
94
|
+
end
|
95
|
+
|
96
96
|
def to_s
|
97
97
|
@time_s.sub(/^0/, '')
|
98
98
|
end
|
@@ -133,10 +133,10 @@ module Runby
|
|
133
133
|
def /(other)
|
134
134
|
raise "Cannot divide Runby::RunbyTime by #{other.class}" unless other.is_a?(RunbyTime) || other.is_a?(Numeric)
|
135
135
|
case other
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
when RunbyTime
|
137
|
+
total_seconds / other.total_seconds
|
138
|
+
when Numeric
|
139
|
+
RunbyTime.from_seconds(total_seconds / other)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
data/lib/runby_pace/speed.rb
CHANGED
@@ -7,24 +7,24 @@ module Runby
|
|
7
7
|
|
8
8
|
def initialize(distance_or_multiplier, units = :km)
|
9
9
|
case distance_or_multiplier
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
when Distance
|
11
|
+
init_from_distance distance_or_multiplier
|
12
|
+
when String
|
13
|
+
init_from_string distance_or_multiplier
|
14
|
+
when Numeric
|
15
|
+
init_from_multiplier(distance_or_multiplier, units)
|
16
|
+
when Speed
|
17
|
+
init_from_clone distance_or_multiplier
|
18
|
+
else
|
19
|
+
raise 'Unable to initialize Runby::Speed'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_s(format: :short)
|
24
24
|
distance = @distance.to_s(format: format)
|
25
25
|
case format
|
26
|
-
|
27
|
-
|
26
|
+
when :short then "#{distance}/ph"
|
27
|
+
when :long then "#{distance} per hour"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -43,7 +43,9 @@ module Runby
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.try_parse(str)
|
46
|
-
speed
|
46
|
+
speed = nil
|
47
|
+
error_message = nil
|
48
|
+
warning_message = nil
|
47
49
|
begin
|
48
50
|
speed = Speed.parse str
|
49
51
|
rescue StandardError => ex
|
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.137
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Walls
|
@@ -104,7 +104,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
104
104
|
licenses:
|
105
105
|
- MIT
|
106
106
|
metadata:
|
107
|
-
commit-hash:
|
107
|
+
commit-hash: f7d50b31ac41c3995620d6627c563c9723701bed
|
108
108
|
post_install_message:
|
109
109
|
rdoc_options: []
|
110
110
|
require_paths:
|