runby_pace 0.2.66 → 0.2.67
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 +8 -8
- data/lib/runby_pace/pace_time.rb +60 -33
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWFhOWIxZjc3NGZlZDE0NGUyZTUyNTFjYmYwZDA5ZmE3Y2I4OGUyMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTk2NTNmMGMzNzYxMjUzODQ5ZjQ0OGViNTFiNzdmYWRmZWQxMTk1ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzMwNGI4NzU3ZmRmYjRkZjA2YjkwMWNjYmM1ZDcwOWJjOGRiNmU2OGFhOTMw
|
10
|
+
ZmFlN2ExYzhmMzUxZGIwMTMzODQ1MjIwYmJhZGNkZmI4ODc1NTFlMDBhMDY3
|
11
|
+
MThhMmNhNTQzN2Q3Mzc1Zjg3MGUxMmY0YTUwODI4ODg3Y2YwYjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmEyZjJkNDA1ZjExMTA4NWYzZDcwYWIwMGEzZWRjMmNiZWRlODBiMTUyOTNl
|
14
|
+
MDhjZDVlZDJkMDY4YWU4YzIzZTNjZmEzM2VjNGY3OWMwYThhNTNlZjI1YmQz
|
15
|
+
OGQzZmJkZTAwM2JhOGY4MTU2ZWUyNDc1NmU1NTIwMmE4MWJiNGI=
|
data/lib/runby_pace/pace_time.rb
CHANGED
@@ -5,9 +5,11 @@ module RunbyPace
|
|
5
5
|
|
6
6
|
def initialize(time)
|
7
7
|
if time.is_a?(String) || time.is_a?(Symbol)
|
8
|
-
init_from_string
|
8
|
+
init_from_string time
|
9
9
|
elsif time.is_a?(PaceTime)
|
10
|
-
init_from_clone
|
10
|
+
init_from_clone time
|
11
|
+
elsif time.is_a?(Hash)
|
12
|
+
init_from_hash time
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -23,6 +25,52 @@ module RunbyPace
|
|
23
25
|
self.from_seconds(total_minutes * 60.0)
|
24
26
|
end
|
25
27
|
|
28
|
+
def self.parse(str)
|
29
|
+
time = str.to_s.strip.chomp
|
30
|
+
is_negative = false
|
31
|
+
|
32
|
+
if time[0] == '-'
|
33
|
+
is_negative = true
|
34
|
+
time = time[1..-1]
|
35
|
+
end
|
36
|
+
|
37
|
+
if time.match(/^\d?\d:\d\d$/)
|
38
|
+
parts = time.split(':')
|
39
|
+
minutes_part = parts[0].to_i
|
40
|
+
seconds_part = parts[1].to_i
|
41
|
+
elsif time.match(/^\d+$/)
|
42
|
+
minutes_part = time.to_i
|
43
|
+
seconds_part = 0
|
44
|
+
elsif time.match(/^\d+[,\. ]\d+$/)
|
45
|
+
parts = time.split(/[,\. ]/)
|
46
|
+
minutes_part = parts[0].to_i
|
47
|
+
seconds_part = (parts[1].to_i / 10.0 * 60).to_i
|
48
|
+
else
|
49
|
+
raise 'Invalid time format'
|
50
|
+
end
|
51
|
+
|
52
|
+
raise 'Minutes must be less than 100' if minutes_part > 99
|
53
|
+
raise 'Seconds must be less than 60' if seconds_part > 59
|
54
|
+
if is_negative
|
55
|
+
minutes_part *= -1
|
56
|
+
seconds_part *= -1
|
57
|
+
end
|
58
|
+
time_formatted = "#{minutes_part.to_s.rjust(2, '0')}:#{seconds_part.to_s.rjust(2, '0')}"
|
59
|
+
|
60
|
+
PaceTime.new({ :time_s => time_formatted, :minutes_part => minutes_part, :seconds_part => seconds_part })
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.try_parse(str)
|
64
|
+
time, error_message = nil
|
65
|
+
begin
|
66
|
+
time = self.parse str
|
67
|
+
rescue Exception => ex
|
68
|
+
error_message = "#{ex.message} (#{str})"
|
69
|
+
end
|
70
|
+
|
71
|
+
return { :time => time, :error_message => error_message}
|
72
|
+
end
|
73
|
+
|
26
74
|
def to_s
|
27
75
|
@time_s
|
28
76
|
end
|
@@ -91,37 +139,11 @@ module RunbyPace
|
|
91
139
|
|
92
140
|
private
|
93
141
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
is_negative = true
|
100
|
-
time = time[1..-1]
|
101
|
-
end
|
102
|
-
|
103
|
-
if time.match(/^\d?\d:\d\d$/)
|
104
|
-
parts = time.split(':')
|
105
|
-
@minutes_part = parts[0].to_i
|
106
|
-
@seconds_part = parts[1].to_i
|
107
|
-
elsif time.match(/^\d+$/)
|
108
|
-
@minutes_part = time.to_i
|
109
|
-
@seconds_part = 0
|
110
|
-
elsif time.match(/^\d+[,\. ]\d+$/)
|
111
|
-
parts = time.split(/[,\. ]/)
|
112
|
-
@minutes_part = parts[0].to_i
|
113
|
-
@seconds_part = (parts[1].to_i / 10.0 * 60).to_i
|
114
|
-
else
|
115
|
-
raise 'Invalid time format'
|
116
|
-
end
|
117
|
-
|
118
|
-
raise 'Minutes must be less than 100' if @minutes_part > 99
|
119
|
-
raise 'Seconds must be less than 60' if @seconds_part > 59
|
120
|
-
if is_negative
|
121
|
-
@minutes_part *= -1
|
122
|
-
@seconds_part *= -1
|
123
|
-
end
|
124
|
-
@time_s = "#{@minutes_part.to_s.rjust(2, '0')}:#{@seconds_part.to_s.rjust(2, '0')}"
|
142
|
+
# @param [Hash] params
|
143
|
+
def init_from_hash(params = {})
|
144
|
+
@time_s = params.fetch :time_s, '00:00'
|
145
|
+
@minutes_part = params.fetch :minutes_part, 0.0
|
146
|
+
@seconds_part = params.fetch :seconds_part, 0.0
|
125
147
|
end
|
126
148
|
|
127
149
|
# @param [PaceTime] time
|
@@ -130,5 +152,10 @@ module RunbyPace
|
|
130
152
|
@minutes_part = time.minutes_part
|
131
153
|
@seconds_part = time.seconds_part
|
132
154
|
end
|
155
|
+
|
156
|
+
# @param [String] time
|
157
|
+
def init_from_string(time)
|
158
|
+
init_from_clone PaceTime.parse time
|
159
|
+
end
|
133
160
|
end
|
134
161
|
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.2.
|
4
|
+
version: 0.2.67
|
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-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ homepage: https://github.com/tygerbytes/runby-pace
|
|
96
96
|
licenses:
|
97
97
|
- MIT
|
98
98
|
metadata:
|
99
|
-
commit-hash:
|
99
|
+
commit-hash: 03aab75e562677d45c86a0d10ba2dd99b0e9d489
|
100
100
|
post_install_message:
|
101
101
|
rdoc_options: []
|
102
102
|
require_paths:
|