runby_pace 0.6.113 → 0.6.114
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.rb +4 -3
- data/lib/runby_pace/pace.rb +53 -10
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 466c5700e4c0a990f27205c500ee6838c752d79e
|
|
4
|
+
data.tar.gz: 6238b9f490e7d70b922a00f8d9d3fcc92824fa9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b435b16123b83dc030788020e7ecd295bcd70fcfd52bfdfa4fc4c0a4db3fd511af58d89d03962dbb6e5824982f1af8c9f9b85046fc6d4bd6df237fbca423c926
|
|
7
|
+
data.tar.gz: 190c585deabe76e379dffa602a6d4af6b71b6ebb553e46e4eb4feb2c34d8cf06b3ed8d9b40907690de464eca7a42bae061e86c1dc5e107f82080dfe8c7ede10a
|
data/lib/runby_pace/distance.rb
CHANGED
|
@@ -35,7 +35,8 @@ module Runby
|
|
|
35
35
|
|
|
36
36
|
def self.parse(str)
|
|
37
37
|
str = str.strip.chomp.downcase
|
|
38
|
-
multiplier = str.scan(/[\d,.]+/).first
|
|
38
|
+
multiplier = str.scan(/[\d,.]+/).first
|
|
39
|
+
multiplier = multiplier.nil? ? 1 : multiplier.to_f
|
|
39
40
|
uom = str.scan(/[-_a-z ]+$/).first
|
|
40
41
|
raise "Unable to find distance unit in '#{str}'" if uom.nil?
|
|
41
42
|
|
|
@@ -65,8 +66,8 @@ module Runby
|
|
|
65
66
|
|
|
66
67
|
def <=>(other)
|
|
67
68
|
raise "Cannot compare Runby::Distance to #{other.class}" unless [Distance, String].include? other.class
|
|
68
|
-
if
|
|
69
|
-
return 0 if to_s == other
|
|
69
|
+
if other.is_a?(String)
|
|
70
|
+
return 0 if to_s == other || to_s(format: :long) == other
|
|
70
71
|
return self <=> try_parse(other)[:distance]
|
|
71
72
|
end
|
|
72
73
|
kilometers <=> other.kilometers
|
data/lib/runby_pace/pace.rb
CHANGED
|
@@ -6,11 +6,15 @@ module Runby
|
|
|
6
6
|
attr_reader :time, :distance
|
|
7
7
|
|
|
8
8
|
def initialize(time_or_pace, distance = '1K')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
case time_or_pace
|
|
10
|
+
when Pace
|
|
11
|
+
return init_from_clone time_or_pace
|
|
12
|
+
when RunbyTime
|
|
13
|
+
return init_from_time time_or_pace, distance
|
|
14
|
+
when String
|
|
15
|
+
return init_from_string time_or_pace, distance
|
|
16
|
+
else
|
|
17
|
+
raise 'Invalid Time or Pace'
|
|
14
18
|
end
|
|
15
19
|
end
|
|
16
20
|
|
|
@@ -30,26 +34,49 @@ module Runby
|
|
|
30
34
|
Runby::Speed.new distance
|
|
31
35
|
end
|
|
32
36
|
|
|
37
|
+
# @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"
|
|
38
|
+
def self.parse(str)
|
|
39
|
+
str = str.to_s.strip.chomp
|
|
40
|
+
if str.match(/^(?<time>[:\d]*) ?(?: per |p\/)(?<distance>(?:[\d.]+ ?)?\w+)$/)
|
|
41
|
+
time = Runby::RunbyTime.new($~[:time])
|
|
42
|
+
distance = Runby::Distance.new($~[:distance])
|
|
43
|
+
Pace.new time, distance
|
|
44
|
+
else
|
|
45
|
+
raise "Invalid pace format (#{str})"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.try_parse(str)
|
|
50
|
+
pace, error_message = nil, warning_message = nil
|
|
51
|
+
begin
|
|
52
|
+
pace = Pace.parse str
|
|
53
|
+
rescue StandardError => ex
|
|
54
|
+
error_message = ex.message
|
|
55
|
+
end
|
|
56
|
+
{ pace: pace, error: error_message, warning: warning_message }
|
|
57
|
+
end
|
|
58
|
+
|
|
33
59
|
def <=>(other)
|
|
34
60
|
if other.is_a? Pace
|
|
35
|
-
|
|
61
|
+
raise 'Comparing paces of different distances is not currently supported' unless @distance == other.distance
|
|
36
62
|
@time <=> other.time
|
|
37
63
|
elsif other.is_a? RunbyTime
|
|
38
64
|
@time <=> other.time
|
|
39
65
|
elsif other.is_a? String
|
|
40
|
-
|
|
41
|
-
@time
|
|
66
|
+
return 0 if to_s == other || to_s(format: :long) == other
|
|
67
|
+
return 0 if @time == other
|
|
68
|
+
self <=> try_parse(other)[:pace]
|
|
42
69
|
end
|
|
43
70
|
end
|
|
44
71
|
|
|
45
72
|
def almost_equals?(other_pace, tolerance_time = '00:01')
|
|
46
73
|
return @time.almost_equals?(other_pace, tolerance_time) if other_pace.is_a?(RunbyTime)
|
|
47
74
|
if other_pace.is_a?(String)
|
|
48
|
-
|
|
75
|
+
return @time.almost_equals?(other_pace, tolerance_time) if other_pace =~ /^\d\d:\d\d$/
|
|
49
76
|
other_pace = Pace.parse(other_pace)
|
|
50
77
|
end
|
|
51
78
|
tolerance = RunbyTime.new(tolerance_time)
|
|
52
|
-
self
|
|
79
|
+
(self - tolerance) <= other_pace && (self + tolerance) >= other_pace
|
|
53
80
|
end
|
|
54
81
|
|
|
55
82
|
# @param [Pace, RunbyTime] other
|
|
@@ -86,5 +113,21 @@ module Runby
|
|
|
86
113
|
@time = other_pace.time
|
|
87
114
|
@distance = other_pace.distance
|
|
88
115
|
end
|
|
116
|
+
|
|
117
|
+
def init_from_string(string, distance = '1K')
|
|
118
|
+
pace = Pace.try_parse(string)
|
|
119
|
+
if pace[:pace]
|
|
120
|
+
@time = pace[:pace].time
|
|
121
|
+
@distance = pace[:pace].distance
|
|
122
|
+
return
|
|
123
|
+
end
|
|
124
|
+
@time = Runby::RunbyTime.new string
|
|
125
|
+
@distance = Runby::Distance.new distance
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def init_from_time(time, distance)
|
|
129
|
+
@time = time
|
|
130
|
+
@distance = Runby::Distance.new distance
|
|
131
|
+
end
|
|
89
132
|
end
|
|
90
133
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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.114
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ty Walls
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-11-
|
|
11
|
+
date: 2016-11-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -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: d6e06c6e669965e0c1225bab6f06d671dca85bb4
|
|
105
105
|
post_install_message:
|
|
106
106
|
rdoc_options: []
|
|
107
107
|
require_paths:
|