runby_pace 0.6.142 → 0.6.143

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ca16f06cd0e2fb02322c8be33f6c6ae6a043c0d
4
- data.tar.gz: 35a76844e0106a92f721030cb17911ed829ef9fb
3
+ metadata.gz: a168825022bc1fb0538091f2cd05b587d81f7994
4
+ data.tar.gz: dce210b22b9cdd6d75599b666cf9e08e6da0dd8c
5
5
  SHA512:
6
- metadata.gz: 09005d4cd8494ded7689d653f66fd43d0b6be001b38773df751a12994aeff87498e9b3806286b0ab39e5e6f1c79330c50e850aab92c213c042c52c994560dbb4
7
- data.tar.gz: 6228df8777be6c11e99fa4d1d0c415d628867be9686e366decfb33bfd41424aef5fefaa9105ddd5594e8fead75836f6a7b2f4a7f9eb044acbc7eb120f728c10c
6
+ metadata.gz: 5bda98da133fa292cfb85e93f9e0998aa695634c6f404678f7cec9ab95c4118bbae636ca321ec7ab1aea318c9e3ba7636cda73a411ea938b0a6ce975d39256b0
7
+ data.tar.gz: d8019e291d0cc0a7670b76f8fef64937cc6aa9c3b830feb3c4f8b7b9cec0955fe26bea37012392e96b60f89b9ca8af2aa089a11ef7a638823db62301f1504c32
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Runby
2
4
  # Represents a human-readable time in the format MM:ss
3
5
  class RunbyTime
@@ -20,7 +22,7 @@ module Runby
20
22
  hours = total_seconds.abs.to_i / 60 / 60
21
23
  minutes = (total_seconds.abs.to_i / 60) % 60
22
24
  seconds = total_seconds.abs.to_i % 60
23
- if hours > 0
25
+ if hours.positive?
24
26
  RunbyTime.new format('%d:%02d:%02d', hours, minutes, seconds)
25
27
  else
26
28
  RunbyTime.new format('%02d:%02d', minutes, seconds)
@@ -38,42 +40,7 @@ module Runby
38
40
  end
39
41
 
40
42
  def self.parse(str)
41
- time = str.to_s.strip.chomp
42
-
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$/
49
- parts = time.split(':')
50
- hours_part = 0
51
- minutes_part = parts[0].to_i
52
- seconds_part = parts[1].to_i
53
- elsif time =~ /^\d+$/
54
- hours_part = 0
55
- minutes_part = time.to_i
56
- seconds_part = 0
57
- elsif time =~ /^\d+[,. ]\d+$/
58
- parts = time.split(/[,. ]/)
59
- hours_part = 0
60
- minutes_part = parts[0].to_i
61
- seconds_part = (parts[1].to_i / 10.0 * 60).to_i
62
- else
63
- raise 'Invalid time format'
64
- end
65
-
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.positive? && minutes_part > 59
68
- raise 'Minutes must be less than 99 if no hours are supplied' if hours_part.zero? && minutes_part > 99
69
- raise 'Seconds must be less than 60' if seconds_part > 59
70
- hours_part_formatted = ''
71
- if hours_part.positive?
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')}"
75
-
76
- RunbyTime.new(time_s: time_formatted, hours_part: hours_part, minutes_part: minutes_part, seconds_part: seconds_part)
43
+ RunbyTimeParser.parse str
77
44
  end
78
45
 
79
46
  def self.try_parse(str, is_five_k = false)
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Runby
4
+ # Helper class which parses strings and returns new RunbyTime(s)
5
+ class RunbyTimeParser
6
+ def self.parse(str)
7
+ time = str.to_s.strip.chomp
8
+
9
+ if time.match?(/^\d?\d:\d\d:\d\d$/)
10
+ parts = time.split(':')
11
+ hours_part = parts[0].to_i
12
+ minutes_part = parts[1].to_i
13
+ seconds_part = parts[2].to_i
14
+ elsif time.match?(/^\d?\d:\d\d$/)
15
+ parts = time.split(':')
16
+ hours_part = 0
17
+ minutes_part = parts[0].to_i
18
+ seconds_part = parts[1].to_i
19
+ elsif time.match?(/^\d+$/)
20
+ hours_part = 0
21
+ minutes_part = time.to_i
22
+ seconds_part = 0
23
+ elsif time.match?(/^\d+[,. ]\d+$/)
24
+ parts = time.split(/[,. ]/)
25
+ hours_part = 0
26
+ minutes_part = parts[0].to_i
27
+ seconds_part = (parts[1].to_i / 10.0 * 60).to_i
28
+ else
29
+ raise 'Invalid time format'
30
+ end
31
+
32
+ raise 'Hours must be less than 24' if hours_part > 23
33
+ raise 'Minutes must be less than 60 if hours are supplied' if hours_part.positive? && minutes_part > 59
34
+ raise 'Minutes must be less than 99 if no hours are supplied' if hours_part.zero? && minutes_part > 99
35
+ raise 'Seconds must be less than 60' if seconds_part > 59
36
+ hours_part_formatted = ''
37
+ if hours_part.positive?
38
+ hours_part_formatted = "#{hours_part.to_s.rjust(2, '0')}:"
39
+ end
40
+ time_formatted = "#{hours_part_formatted}#{minutes_part.to_s.rjust(2, '0')}:#{seconds_part.to_s.rjust(2, '0')}"
41
+
42
+ RunbyTime.new(time_s: time_formatted, hours_part: hours_part, minutes_part: minutes_part, seconds_part: seconds_part)
43
+ end
44
+ end
45
+ end
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.6.142
4
+ version: 0.6.143
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ty Walls
@@ -95,6 +95,7 @@ files:
95
95
  - lib/runby_pace/run_types/ten_kilometer_race_run.rb
96
96
  - lib/runby_pace/runby_range.rb
97
97
  - lib/runby_pace/runby_time.rb
98
+ - lib/runby_pace/runby_time_parser.rb
98
99
  - lib/runby_pace/speed.rb
99
100
  - lib/runby_pace/speed_range.rb
100
101
  - lib/runby_pace/version.rb
@@ -104,7 +105,7 @@ homepage: https://github.com/tygerbytes/runby-pace
104
105
  licenses:
105
106
  - MIT
106
107
  metadata:
107
- commit-hash: 1b69e5a5f3d05761bb3d5784091d1294ec588ff0
108
+ commit-hash: 83c260f4c540d7ab5b42c37fa1606905c151d6b9
108
109
  post_install_message:
109
110
  rdoc_options: []
110
111
  require_paths: