runby_pace 0.6.120 → 0.6.121

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: 4f503f49bf7fb6a5f24fdc23aabc30847d816474
4
- data.tar.gz: eedaf1fbae8328eb4ca890743abe84c00d6d5789
3
+ metadata.gz: 70cde89c41d690b7e35a2e49921cf2f347cfdfd2
4
+ data.tar.gz: 7f6695e47150f07c89e664f8f5a360a413639809
5
5
  SHA512:
6
- metadata.gz: 036b4b1212269bf9499d7e57f1d45dd30db49940d7703f2a2b260bee3ac78ebc0f0efe279a208f5e4077fee4578dea2273790aec5dc06c299316f2ff791ca346
7
- data.tar.gz: 9fb73eb7ed4ca68cdb106089bbda3e92f99bae23ab6f4b09e5756b8bd7f6ee09195a8c987e6aebb6c4ef24f511c47a655c6d773c1c7864c8c0f634c7d0251bb2
6
+ metadata.gz: efed2ee7348ba9b394821ed1afaa84e35c91746d70be7f773b144251b7e0918679170bd1ec0997e37948b7bec8f44c45bd0ec3fcc240cf17d9e010f873ba803e
7
+ data.tar.gz: b3d573405a1d3fe27df705931d5d53d5de36b3350bcb3bd1da04189dd4e1c57cae121cf4f67b6daee3fe7b63955744b68a364066819205e52a7345fcb54b095a
@@ -1,5 +1,10 @@
1
1
  module Runby
2
2
  # An assortment of mathematical functions related to running.
3
3
  class RunMath
4
+ def self.predict_five_k_time(distance, time)
5
+ distance = Distance.new(distance)
6
+ time = RunbyTime.new(time)
7
+
8
+ end
4
9
  end
5
10
  end
@@ -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
- minutes = total_seconds.abs.to_i / 60
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
- RunbyTime.new format('%02d:%02d', minutes, seconds)
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.match(/^\d?\d:\d\d$/)
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.match(/^\d+$/)
53
+ elsif time =~ /^\d+$/
54
+ hours_part = 0
38
55
  minutes_part = time.to_i
39
56
  seconds_part = 0
40
- elsif time.match(/^\d+[,. ]\d+$/)
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 'Minutes must be less than 100' if minutes_part > 99
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
- time_formatted = "#{minutes_part.to_s.rjust(2, '0')}:#{seconds_part.to_s.rjust(2, '0')}"
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.120
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-05-26 00:00:00.000000000 Z
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: 040aea6faf028a8399bb3c5d044ca050e41e1b1e
104
+ commit-hash: 4387aae31ecca99d9e8887c65f58aef1e877653d
105
105
  post_install_message:
106
106
  rdoc_options: []
107
107
  require_paths: