runby_pace 0.6.99 → 0.6.100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/runby_pace/distance.rb +6 -1
- data/lib/runby_pace/distance_unit.rb +10 -0
- data/lib/runby_pace/pace.rb +37 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjFiOGZmNjc3Njg2NTQ0MDc0Y2JkZjM1NTk5YzBjZGRmMThiN2NlOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmNjNTY2ZjQyNTc1NzEyMjVhNGI5ODUxMDYxODc2ZDczMDgxMDY3MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGZkNTkwMWFlN2E5NTU4MTMwZDlmYzI2NWE2N2Y1NjJhNjQwNTU1M2YzNjU2
|
10
|
+
Yzk4NDA3MTkzZjIyMWFjMDcwYmRiNjIxODg4Mjc0MDIxOTQxMDYyYmE1MGJl
|
11
|
+
NWIzYjA1ZjdiMDZjNmFmMzA3NWUwZjQ4ZjcxZjZlMGM2MGZjYjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjUxNTdlOTJhNTcyODg5ZWQ3Nzg3YWZiMDQzNjdjYWE0M2QwMGEyNWQzOTFl
|
14
|
+
NWNlZjcwYzMyMWJhYTMxZmViN2UxOWI3NGUyOTFlYWQzODY2ODg3MWFkYzNm
|
15
|
+
ZjA2ZDM0NmJkODNhYmFjZDBkZmY3MmM1ZTE0NGJhYTkzMGM3MzM=
|
data/lib/runby_pace/distance.rb
CHANGED
@@ -59,12 +59,17 @@ module Runby
|
|
59
59
|
|
60
60
|
def pluralized_uom
|
61
61
|
uom_description = @uom.description.downcase
|
62
|
-
if @multiplier > 1
|
62
|
+
if @multiplier > 1
|
63
63
|
uom_description += 's'
|
64
64
|
end
|
65
65
|
uom_description
|
66
66
|
end
|
67
67
|
|
68
|
+
def ==(other)
|
69
|
+
raise "Cannot compare Runby::Distance to #{other.class}" unless other.is_a? Distance
|
70
|
+
@uom == other.uom && @multiplier == other.multiplier
|
71
|
+
end
|
72
|
+
|
68
73
|
private
|
69
74
|
|
70
75
|
def init_from_clone(distance)
|
@@ -47,6 +47,16 @@ module Runby
|
|
47
47
|
@@_uom_definitions.has_key?(symbol)
|
48
48
|
end
|
49
49
|
|
50
|
+
def ==(other)
|
51
|
+
if other.is_a? DistanceUnit
|
52
|
+
@symbol == other.symbol
|
53
|
+
elsif other.is_a? String
|
54
|
+
@symbol == DistanceUnit.parse(other)
|
55
|
+
else
|
56
|
+
raise "Error comparing DistanceUnit to #{other.class}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
@@_uom_definitions =
|
51
61
|
{ km: { description: 'Kilometer', conversion_factor: 1.0, synonyms: %w(k km kms kilometer kilometers) },
|
52
62
|
m: { description: 'Meter', conversion_factor: 0.001, synonyms: %w(m meter meters) },
|
data/lib/runby_pace/pace.rb
CHANGED
@@ -1,15 +1,49 @@
|
|
1
1
|
module Runby
|
2
2
|
# Represents a pace consisting of a distance and a time in which that distance was covered
|
3
3
|
class Pace
|
4
|
+
include Comparable
|
5
|
+
|
4
6
|
attr_reader :time, :distance
|
5
7
|
|
6
|
-
def initialize(
|
7
|
-
|
8
|
-
|
8
|
+
def initialize(time_or_pace, distance = '1K')
|
9
|
+
if time_or_pace.is_a? Pace
|
10
|
+
init_from_clone time_or_pace
|
11
|
+
else
|
12
|
+
@time = Runby::RunbyTime.parse(time_or_pace)
|
13
|
+
@distance = Runby::Distance.new(distance)
|
14
|
+
end
|
9
15
|
end
|
10
16
|
|
11
17
|
def to_s
|
12
18
|
"#{time} per #{distance.pluralized_uom}"
|
13
19
|
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
if other.is_a? Pace
|
23
|
+
return nil unless @distance == other.distance
|
24
|
+
@time <=> other.time
|
25
|
+
elsif other.is_a? RunbyTime
|
26
|
+
@time <=> other.time
|
27
|
+
elsif other.is_a? String
|
28
|
+
@time <=> RunbyTime.parse(other)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def almost_equals?(other_pace, tolerance_time = '00:01')
|
33
|
+
if other_pace.is_a?(String)
|
34
|
+
other_pace = Pace.parse(other_pace)
|
35
|
+
end
|
36
|
+
tolerance = RunbyTime.new(tolerance_time)
|
37
|
+
# TODO: Clean this up by adding +- to Pace
|
38
|
+
self.time >= (other_pace.time - tolerance) && self.time <= (other_pace.time + tolerance)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def init_from_clone(other_pace)
|
44
|
+
raise "#{other_pace} is not a Runby::Pace" unless other_pace.is_a? Pace
|
45
|
+
@time = other_pace.time
|
46
|
+
@distance = other_pace.distance
|
47
|
+
end
|
14
48
|
end
|
15
49
|
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.100
|
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-10-
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,7 +100,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
100
100
|
licenses:
|
101
101
|
- MIT
|
102
102
|
metadata:
|
103
|
-
commit-hash:
|
103
|
+
commit-hash: 5e175da0082d9fb644dfd56117271a8e51928cb2
|
104
104
|
post_install_message:
|
105
105
|
rdoc_options: []
|
106
106
|
require_paths:
|