runby_pace 0.6.120 → 0.6.121
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/runby_pace/run_math.rb +5 -0
- data/lib/runby_pace/runby_time.rb +34 -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: 70cde89c41d690b7e35a2e49921cf2f347cfdfd2
|
4
|
+
data.tar.gz: 7f6695e47150f07c89e664f8f5a360a413639809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efed2ee7348ba9b394821ed1afaa84e35c91746d70be7f773b144251b7e0918679170bd1ec0997e37948b7bec8f44c45bd0ec3fcc240cf17d9e010f873ba803e
|
7
|
+
data.tar.gz: b3d573405a1d3fe27df705931d5d53d5de36b3350bcb3bd1da04189dd4e1c57cae121cf4f67b6daee3fe7b63955744b68a364066819205e52a7345fcb54b095a
|
data/lib/runby_pace/run_math.rb
CHANGED
@@ -3,7 +3,7 @@ module Runby
|
|
3
3
|
class RunbyTime
|
4
4
|
include Comparable
|
5
5
|
|
6
|
-
attr_reader :time_s, :minutes_part, :seconds_part
|
6
|
+
attr_reader :time_s, :hours_part, :minutes_part, :seconds_part
|
7
7
|
|
8
8
|
def initialize(time)
|
9
9
|
if time.is_a?(String) || time.is_a?(Symbol)
|
@@ -17,9 +17,14 @@ module Runby
|
|
17
17
|
|
18
18
|
# @param [numeric] total_seconds
|
19
19
|
def self.from_seconds(total_seconds)
|
20
|
-
|
20
|
+
hours = total_seconds.abs.to_i / 60 / 60
|
21
|
+
minutes = (total_seconds.abs.to_i / 60) % 60
|
21
22
|
seconds = total_seconds.abs.to_i % 60
|
22
|
-
|
23
|
+
if hours > 0
|
24
|
+
RunbyTime.new format('%d:%02d:%02d', hours, minutes, seconds)
|
25
|
+
else
|
26
|
+
RunbyTime.new format('%02d:%02d', minutes, seconds)
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
25
30
|
# @param [numeric] total_minutes
|
@@ -27,29 +32,48 @@ module Runby
|
|
27
32
|
from_seconds(total_minutes * 60.0)
|
28
33
|
end
|
29
34
|
|
35
|
+
# @param [numeric] total_hours
|
36
|
+
def self.from_hours(total_hours)
|
37
|
+
from_seconds(total_hours * 60.0 * 60.0)
|
38
|
+
end
|
39
|
+
|
30
40
|
def self.parse(str)
|
31
41
|
time = str.to_s.strip.chomp
|
32
42
|
|
33
|
-
if time
|
43
|
+
if time =~ /^\d?\d:\d\d:\d\d$/
|
44
|
+
parts = time.split(':')
|
45
|
+
hours_part = parts[0].to_i
|
46
|
+
minutes_part = parts[1].to_i
|
47
|
+
seconds_part = parts[2].to_i
|
48
|
+
elsif time =~ /^\d?\d:\d\d$/
|
34
49
|
parts = time.split(':')
|
50
|
+
hours_part = 0
|
35
51
|
minutes_part = parts[0].to_i
|
36
52
|
seconds_part = parts[1].to_i
|
37
|
-
elsif time
|
53
|
+
elsif time =~ /^\d+$/
|
54
|
+
hours_part = 0
|
38
55
|
minutes_part = time.to_i
|
39
56
|
seconds_part = 0
|
40
|
-
elsif time
|
57
|
+
elsif time =~ /^\d+[,. ]\d+$/
|
41
58
|
parts = time.split(/[,. ]/)
|
59
|
+
hours_part = 0
|
42
60
|
minutes_part = parts[0].to_i
|
43
61
|
seconds_part = (parts[1].to_i / 10.0 * 60).to_i
|
44
62
|
else
|
45
63
|
raise 'Invalid time format'
|
46
64
|
end
|
47
65
|
|
48
|
-
raise '
|
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 > 0 && minutes_part > 59
|
68
|
+
raise 'Minutes must be less than 99 if no hours are supplied' if hours_part.zero? && minutes_part > 99
|
49
69
|
raise 'Seconds must be less than 60' if seconds_part > 59
|
50
|
-
|
70
|
+
hours_part_formatted = ''
|
71
|
+
if hours_part > 0
|
72
|
+
hours_part_formatted = "#{hours_part.to_s.rjust(2, '0')}:"
|
73
|
+
end
|
74
|
+
time_formatted = "#{hours_part_formatted}#{minutes_part.to_s.rjust(2, '0')}:#{seconds_part.to_s.rjust(2, '0')}"
|
51
75
|
|
52
|
-
RunbyTime.new(time_s: time_formatted, minutes_part: minutes_part, seconds_part: seconds_part)
|
76
|
+
RunbyTime.new(time_s: time_formatted, hours_part: hours_part, minutes_part: minutes_part, seconds_part: seconds_part)
|
53
77
|
end
|
54
78
|
|
55
79
|
def self.try_parse(str, is_five_k = false)
|
@@ -100,7 +124,7 @@ module Runby
|
|
100
124
|
total_seconds <=> other.total_seconds
|
101
125
|
elsif other.is_a? String
|
102
126
|
return 0 if @time_s == other
|
103
|
-
total_seconds <=> parse(other).total_seconds
|
127
|
+
total_seconds <=> RunbyTime.parse(other).total_seconds
|
104
128
|
end
|
105
129
|
end
|
106
130
|
|
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.121
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Walls
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-07 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: 4387aae31ecca99d9e8887c65f58aef1e877653d
|
105
105
|
post_install_message:
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|