runby_pace 0.6.139 → 0.6.140
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/pace.rb +22 -22
- data/lib/runby_pace/runby_time.rb +2 -2
- 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: 56abfe8dad10070a1ce15f6615e2b44c36508536
|
|
4
|
+
data.tar.gz: d8faf0b03d0b9a87e62efb8bfee09dffc0ce64f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d8bd2ae1fce0cb2c9a6cc7c4fa36dc26dc337de516692b0020b05903f84b864b6243b106b43dafd1bca14577688cef0ef6911d97a6ccd08e2734c7791385ef3
|
|
7
|
+
data.tar.gz: bf09f4b68dd8402fd5e2443d815bc6bf74c5b9182562b2220ffcb2f5c107e651e4b3c74576a3498227822eb95070d1ffe57d9b6a9dc7915648b666e9bc3569f1
|
data/lib/runby_pace/pace.rb
CHANGED
|
@@ -7,14 +7,14 @@ module Runby
|
|
|
7
7
|
|
|
8
8
|
def initialize(time_or_pace, distance = '1K')
|
|
9
9
|
case time_or_pace
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
when Pace
|
|
11
|
+
init_from_clone time_or_pace
|
|
12
|
+
when RunbyTime
|
|
13
|
+
init_from_time time_or_pace, distance
|
|
14
|
+
when String
|
|
15
|
+
init_from_string time_or_pace, distance
|
|
16
|
+
else
|
|
17
|
+
raise 'Invalid Time or Pace'
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -30,38 +30,38 @@ module Runby
|
|
|
30
30
|
leading_one_regex = /^1 ?/
|
|
31
31
|
distance_s.gsub!(leading_one_regex, '')
|
|
32
32
|
case format
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
when :short then "#{time} p/#{distance_s}"
|
|
34
|
+
when :long then "#{time} per #{distance_s}"
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def as_speed
|
|
39
39
|
total_minutes = @time.total_minutes
|
|
40
|
-
multiplier = total_minutes
|
|
40
|
+
multiplier = total_minutes.positive? ? (60 / total_minutes).round(2) : 0
|
|
41
41
|
distance = Runby::Distance.new(@distance.uom, multiplier)
|
|
42
42
|
Runby::Speed.new distance
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def meters_per_minute
|
|
46
46
|
total_minutes = @time.total_minutes
|
|
47
|
-
return 0 unless total_minutes
|
|
47
|
+
return 0 unless total_minutes.positive?
|
|
48
48
|
@distance.meters / total_minutes
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# @param [String] str is either a long-form pace such as "10:00 per mile" or a short-form pace like "10:00 p/mi"
|
|
52
52
|
def self.parse(str)
|
|
53
53
|
str = str.to_s.strip.chomp
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
raise "Invalid pace format (#{str})"
|
|
60
|
-
end
|
|
54
|
+
match = str.match %r{^(?<time>[:\d]*) ?(?: per |p\/)(?<distance>(?:[\d.]+ ?)?\w+)$}
|
|
55
|
+
raise "Invalid pace format (#{str})" unless match
|
|
56
|
+
time = Runby::RunbyTime.new(match[:time])
|
|
57
|
+
distance = Runby::Distance.new(match[:distance])
|
|
58
|
+
Pace.new time, distance
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
def self.try_parse(str)
|
|
64
|
-
pace
|
|
62
|
+
pace = nil
|
|
63
|
+
error_message = nil
|
|
64
|
+
warning_message = nil
|
|
65
65
|
begin
|
|
66
66
|
pace = Pace.parse str
|
|
67
67
|
rescue StandardError => ex
|
|
@@ -72,7 +72,7 @@ module Runby
|
|
|
72
72
|
|
|
73
73
|
def <=>(other)
|
|
74
74
|
if other.is_a? Pace
|
|
75
|
-
|
|
75
|
+
meters_per_minute.round(2) <=> other.meters_per_minute.round(2)
|
|
76
76
|
elsif other.is_a? RunbyTime
|
|
77
77
|
@time <=> other.time
|
|
78
78
|
elsif other.is_a? String
|
|
@@ -87,7 +87,7 @@ module Runby
|
|
|
87
87
|
return almost_equals?(Pace.new(other_pace, @distance), tolerance_time)
|
|
88
88
|
end
|
|
89
89
|
if other_pace.is_a?(String)
|
|
90
|
-
return almost_equals?(Pace.new(other_pace, @distance), tolerance_time) if other_pace
|
|
90
|
+
return almost_equals?(Pace.new(other_pace, @distance), tolerance_time) if other_pace.match? /^\d?\d:\d\d$/
|
|
91
91
|
other_pace = Pace.parse(other_pace)
|
|
92
92
|
end
|
|
93
93
|
tolerance = RunbyTime.new(tolerance_time)
|
|
@@ -64,11 +64,11 @@ module Runby
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
raise 'Hours must be less than 24' if hours_part > 23
|
|
67
|
-
raise 'Minutes must be less than 60 if hours are supplied' if hours_part
|
|
67
|
+
raise 'Minutes must be less than 60 if hours are supplied' if hours_part.positive? && minutes_part > 59
|
|
68
68
|
raise 'Minutes must be less than 99 if no hours are supplied' if hours_part.zero? && minutes_part > 99
|
|
69
69
|
raise 'Seconds must be less than 60' if seconds_part > 59
|
|
70
70
|
hours_part_formatted = ''
|
|
71
|
-
if hours_part
|
|
71
|
+
if hours_part.positive?
|
|
72
72
|
hours_part_formatted = "#{hours_part.to_s.rjust(2, '0')}:"
|
|
73
73
|
end
|
|
74
74
|
time_formatted = "#{hours_part_formatted}#{minutes_part.to_s.rjust(2, '0')}:#{seconds_part.to_s.rjust(2, '0')}"
|
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.140
|
|
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: 01a70d7e4ba6544e76da8e3822fb42674f0568df
|
|
108
108
|
post_install_message:
|
|
109
109
|
rdoc_options: []
|
|
110
110
|
require_paths:
|