runby_pace 0.61.153 → 0.61.154
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 +7 -13
- data/lib/runby_pace/distance_unit.rb +8 -17
- data/lib/runby_pace/pace.rb +5 -8
- data/lib/runby_pace/speed.rb +14 -15
- 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: 606c3c91ef5137d4eb17d80fec2e6abc1de92110
|
|
4
|
+
data.tar.gz: 512fafad4f8f3f04a08274e3b63a34935bf25be9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95c099f7c0e5257f68136e32065fb6149c2f06bd5fdc0cfb3fa97b09b52c7030b8a7fe62a42bcdbb0ced3e82bcdba31081dc44f6fab46c027dc164dfcd1041e0
|
|
7
|
+
data.tar.gz: 35cf6b718b23ddd67b0c4bcf3af08ad945041cfa00cd3f1d37cf3d05e4c3e52c1ee9245536c0444d428c2a636a5d590cb9c31a2594e442b0e5474cbd3eec29e6
|
data/lib/runby_pace/distance.rb
CHANGED
|
@@ -6,14 +6,17 @@ module Runby
|
|
|
6
6
|
include Comparable
|
|
7
7
|
|
|
8
8
|
attr_reader :uom, :multiplier
|
|
9
|
+
|
|
10
|
+
def self.new(uom = :km, multiplier = 1)
|
|
11
|
+
return uom if uom.is_a? Distance
|
|
12
|
+
return Distance.parse uom if uom.is_a? String
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
9
16
|
def initialize(uom = :km, multiplier = 1)
|
|
10
17
|
case uom
|
|
11
|
-
when Distance
|
|
12
|
-
init_from_clone uom
|
|
13
18
|
when DistanceUnit
|
|
14
19
|
init_from_distance_unit uom, multiplier
|
|
15
|
-
when String
|
|
16
|
-
init_from_string uom
|
|
17
20
|
when Symbol
|
|
18
21
|
init_from_symbol uom, multiplier
|
|
19
22
|
else
|
|
@@ -116,20 +119,11 @@ module Runby
|
|
|
116
119
|
|
|
117
120
|
private
|
|
118
121
|
|
|
119
|
-
def init_from_clone(distance)
|
|
120
|
-
@uom = distance.uom
|
|
121
|
-
@multiplier = distance.multiplier
|
|
122
|
-
end
|
|
123
|
-
|
|
124
122
|
def init_from_distance_unit(uom, multiplier)
|
|
125
123
|
@uom = uom
|
|
126
124
|
@multiplier = multiplier
|
|
127
125
|
end
|
|
128
126
|
|
|
129
|
-
def init_from_string(string)
|
|
130
|
-
init_from_clone Distance.parse string
|
|
131
|
-
end
|
|
132
|
-
|
|
133
127
|
def init_from_symbol(distance_uom_symbol, multiplier)
|
|
134
128
|
raise "Unknown unit of measure #{distance_uom_symbol}" unless Runby::DistanceUnit.known_uom? distance_uom_symbol
|
|
135
129
|
raise 'Invalid multiplier' unless multiplier.is_a?(Numeric)
|
|
@@ -7,12 +7,15 @@ module Runby
|
|
|
7
7
|
class DistanceUnit
|
|
8
8
|
attr_reader :symbol, :description, :conversion_factor
|
|
9
9
|
|
|
10
|
+
def self.new(unit_of_measure)
|
|
11
|
+
return unit_of_measure if unit_of_measure.is_a? DistanceUnit
|
|
12
|
+
return DistanceUnit.parse(unit_of_measure) if unit_of_measure.is_a? String
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
10
16
|
def initialize(unit_of_measure)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
elsif unit_of_measure.is_a? String
|
|
14
|
-
init_from_string unit_of_measure
|
|
15
|
-
end
|
|
17
|
+
raise "':#{unit_of_measure}' is an unknown unit of measure" unless DistanceUnit.known_uom? unit_of_measure
|
|
18
|
+
@symbol = unit_of_measure
|
|
16
19
|
@conversion_factor = UOM_DEFINITIONS[@symbol][:conversion_factor]
|
|
17
20
|
@description = UOM_DEFINITIONS[@symbol][:description]
|
|
18
21
|
freeze
|
|
@@ -81,17 +84,5 @@ module Runby
|
|
|
81
84
|
# Fun distance unit of measures
|
|
82
85
|
marathon: { description: 'marathon', description_plural: 'marathons', conversion_factor: 42.1648128,
|
|
83
86
|
synonyms: %w[marathon] } }.freeze
|
|
84
|
-
|
|
85
|
-
private
|
|
86
|
-
|
|
87
|
-
def init_from_symbol(unit_of_measure)
|
|
88
|
-
raise "':#{unit_of_measure}' is an unknown unit of measure" unless DistanceUnit.known_uom? unit_of_measure
|
|
89
|
-
@symbol = unit_of_measure
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def init_from_string(unit_of_measure)
|
|
93
|
-
parsed_uom = DistanceUnit.parse(unit_of_measure)
|
|
94
|
-
@symbol = parsed_uom.symbol
|
|
95
|
-
end
|
|
96
87
|
end
|
|
97
88
|
end
|
data/lib/runby_pace/pace.rb
CHANGED
|
@@ -7,10 +7,13 @@ module Runby
|
|
|
7
7
|
|
|
8
8
|
attr_reader :time, :distance
|
|
9
9
|
|
|
10
|
+
def self.new(time_or_pace, distance = '1K')
|
|
11
|
+
return time_or_pace if time_or_pace.is_a? Pace
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
10
15
|
def initialize(time_or_pace, distance = '1K')
|
|
11
16
|
case time_or_pace
|
|
12
|
-
when Pace
|
|
13
|
-
init_from_clone time_or_pace
|
|
14
17
|
when RunbyTime
|
|
15
18
|
init_from_time time_or_pace, distance
|
|
16
19
|
when String
|
|
@@ -128,12 +131,6 @@ module Runby
|
|
|
128
131
|
|
|
129
132
|
private
|
|
130
133
|
|
|
131
|
-
def init_from_clone(other_pace)
|
|
132
|
-
raise "#{other_pace} is not a Runby::Pace" unless other_pace.is_a? Pace
|
|
133
|
-
@time = other_pace.time
|
|
134
|
-
@distance = other_pace.distance
|
|
135
|
-
end
|
|
136
|
-
|
|
137
134
|
def init_from_string(string, distance = '1K')
|
|
138
135
|
pace = Pace.try_parse(string)
|
|
139
136
|
if pace[:pace]
|
data/lib/runby_pace/speed.rb
CHANGED
|
@@ -7,16 +7,24 @@ module Runby
|
|
|
7
7
|
|
|
8
8
|
attr_reader :distance
|
|
9
9
|
|
|
10
|
+
def self.new(distance_or_multiplier, units = :km)
|
|
11
|
+
return distance_or_multiplier if distance_or_multiplier.is_a? Speed
|
|
12
|
+
if distance_or_multiplier.is_a? String
|
|
13
|
+
parsed_speed = Speed.try_parse(distance_or_multiplier)
|
|
14
|
+
return parsed_speed[:speed] unless parsed_speed[:error]
|
|
15
|
+
end
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
10
19
|
def initialize(distance_or_multiplier, units = :km)
|
|
11
20
|
case distance_or_multiplier
|
|
12
21
|
when Distance
|
|
13
22
|
init_from_distance distance_or_multiplier
|
|
14
23
|
when String
|
|
15
|
-
|
|
24
|
+
# Already tried to parse it as a Speed string. Try parsing it as a Distance string.
|
|
25
|
+
init_from_distance_string distance_or_multiplier
|
|
16
26
|
when Numeric
|
|
17
27
|
init_from_multiplier(distance_or_multiplier, units)
|
|
18
|
-
when Speed
|
|
19
|
-
init_from_clone distance_or_multiplier
|
|
20
28
|
else
|
|
21
29
|
raise 'Unable to initialize Runby::Speed'
|
|
22
30
|
end
|
|
@@ -68,27 +76,18 @@ module Runby
|
|
|
68
76
|
|
|
69
77
|
private
|
|
70
78
|
|
|
71
|
-
def init_from_clone(other_speed)
|
|
72
|
-
@distance = Distance.new(other_speed.distance)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
79
|
def init_from_distance(distance)
|
|
76
|
-
@distance =
|
|
80
|
+
@distance = distance
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
def init_from_multiplier(multiplier, uom)
|
|
80
84
|
@distance = Distance.new(uom, multiplier)
|
|
81
85
|
end
|
|
82
86
|
|
|
83
|
-
def
|
|
84
|
-
results = Speed.try_parse(str)
|
|
85
|
-
unless results[:error]
|
|
86
|
-
init_from_clone results[:speed]
|
|
87
|
-
return
|
|
88
|
-
end
|
|
87
|
+
def init_from_distance_string(str)
|
|
89
88
|
results = Distance.try_parse(str)
|
|
90
89
|
unless results[:error]
|
|
91
|
-
|
|
90
|
+
@distance = results[:distance]
|
|
92
91
|
return
|
|
93
92
|
end
|
|
94
93
|
raise "'#{str}' is not recognized as a Speed"
|
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.61.
|
|
4
|
+
version: 0.61.154
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ty Walls
|
|
@@ -108,7 +108,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
|
108
108
|
licenses:
|
|
109
109
|
- MIT
|
|
110
110
|
metadata:
|
|
111
|
-
commit-hash:
|
|
111
|
+
commit-hash: 09fc1b1dbcb0402ebffe9a33901f65105ffb04aa
|
|
112
112
|
post_install_message:
|
|
113
113
|
rdoc_options: []
|
|
114
114
|
require_paths:
|