runby_pace 0.6.136 → 0.6.137

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a722ddc36ca17ec4f04c5f47e6b91d70368c09e
4
- data.tar.gz: 41a9f043ba2fabef623a80d1f2a981cef97822e3
3
+ metadata.gz: 81bb614066b9c4b6adeae971f2669d7a7340ae18
4
+ data.tar.gz: 30c45f64bdca980098f74b2d2011d532a87e9bc7
5
5
  SHA512:
6
- metadata.gz: 7e58ff1e1fd7c74791a063f57d0058cfe7d412b1c7aa55435012d682670679ed56aff6f257e8740c99e8e26286165edbb173ae440b89872155a33515ca1dcf00
7
- data.tar.gz: f8e1e2f0a4cc9597b7dad991002d8441c0bdbfb485b1d456e28f0e663ddc89f6b9f652d94f9d66401515bacef88cc21f9c70b646d9df462ea377103f51553834
6
+ metadata.gz: 0adf46b7d38354400d1ac89ad30d3bf797b675aca5874f7b3aa141b4f47154abb6f4ee5e3a3df1cc33c9ac57061531f6555750ff11bdc1493083b6feaf4d6006
7
+ data.tar.gz: e25cb2fe2bbf8051501409453298e7b93383c7ae86569a55f2420853086226fc66cf47eb77ae892f5e5b83e1ea259d0b285fbfe1cf3023f8c7c3f6f9a81260e4
@@ -7,33 +7,33 @@ module Runby
7
7
 
8
8
  def initialize(unit_of_measure)
9
9
  if unit_of_measure.is_a? Symbol
10
- raise "':#{unit_of_measure.to_s}' is an unknown unit of measure" unless DistanceUnit.known_uom? unit_of_measure
10
+ raise "':#{unit_of_measure}' is an unknown unit of measure" unless DistanceUnit.known_uom? unit_of_measure
11
11
  @symbol = unit_of_measure
12
- @conversion_factor = @@_uom_definitions[@symbol][:conversion_factor]
12
+ @conversion_factor = UOM_DEFINITIONS[@symbol][:conversion_factor]
13
13
  elsif unit_of_measure.is_a? String
14
14
  parsed_uom = DistanceUnit.parse(unit_of_measure)
15
15
  @symbol = parsed_uom.symbol
16
- @conversion_factor = @@_uom_definitions[@symbol][:conversion_factor]
16
+ @conversion_factor = UOM_DEFINITIONS[@symbol][:conversion_factor]
17
17
  end
18
18
 
19
- @description = @@_uom_definitions[@symbol][:description]
19
+ @description = UOM_DEFINITIONS[@symbol][:description]
20
20
  end
21
21
 
22
22
  def to_s(format: :long, pluralize: false)
23
23
  case format
24
- when :short then @symbol.to_s
25
- when :long then pluralize ? description_plural : @description
24
+ when :short then @symbol.to_s
25
+ when :long then pluralize ? description_plural : @description
26
26
  end
27
27
  end
28
28
 
29
29
  def description_plural
30
- @@_uom_definitions[@symbol][:description_plural]
30
+ UOM_DEFINITIONS[@symbol][:description_plural]
31
31
  end
32
32
 
33
33
  def self.parse(description)
34
34
  description = description.strip.chomp.downcase
35
35
  found_uom = nil
36
- @@_uom_definitions.each do |uom, details|
36
+ UOM_DEFINITIONS.each do |uom, details|
37
37
  if details[:synonyms].include? description
38
38
  found_uom = uom
39
39
  break
@@ -55,7 +55,7 @@ module Runby
55
55
 
56
56
  def self.known_uom?(symbol)
57
57
  # TODO: test
58
- @@_uom_definitions.key?(symbol)
58
+ UOM_DEFINITIONS.key?(symbol)
59
59
  end
60
60
 
61
61
  def ==(other)
@@ -68,14 +68,19 @@ module Runby
68
68
  end
69
69
  end
70
70
 
71
- @@_uom_definitions =
72
- { km: { description: 'kilometer', description_plural: 'kilometers', conversion_factor: 1.0, synonyms: %w(k km kms kilometer kilometers) },
73
- m: { description: 'meter', description_plural: 'meters', conversion_factor: 0.001, synonyms: %w(m meter meters) },
74
- mi: { description: 'mile', description_plural: 'miles', conversion_factor: 1.609344, synonyms: %w(mi mile miles) },
75
- ft: { description: 'foot', description_plural: 'feet', conversion_factor: 0.0003048, synonyms: %w(ft foot feet) },
76
- yd: { description: 'yard', description_plural: 'yards', conversion_factor: 1093.61, synonyms: %w(y yd yds yard yards) },
71
+ UOM_DEFINITIONS =
72
+ { km: { description: 'kilometer', description_plural: 'kilometers', conversion_factor: 1.0,
73
+ synonyms: %w[k km kms kilometer kilometers] },
74
+ m: { description: 'meter', description_plural: 'meters', conversion_factor: 0.001,
75
+ synonyms: %w[m meter meters] },
76
+ mi: { description: 'mile', description_plural: 'miles', conversion_factor: 1.609344,
77
+ synonyms: %w[mi mile miles] },
78
+ ft: { description: 'foot', description_plural: 'feet', conversion_factor: 0.0003048,
79
+ synonyms: %w[ft foot feet] },
80
+ yd: { description: 'yard', description_plural: 'yards', conversion_factor: 1093.61,
81
+ synonyms: %w[y yd yds yard yards] },
77
82
  # Fun distance unit of measures
78
- marathon: { description: 'marathon', description_plural: 'marathons', conversion_factor: 42.1648128, synonyms: %w(marathon) }
79
- }
83
+ marathon: { description: 'marathon', description_plural: 'marathons', conversion_factor: 42.1648128,
84
+ synonyms: %w[marathon] } }.freeze
80
85
  end
81
86
  end
@@ -10,10 +10,10 @@ module Runby
10
10
  attr_reader :paces
11
11
 
12
12
  # The fastest 5K time supported by RunbyPace
13
- @@FASTEST_5K = :'14:00'
13
+ FASTEST_5K = :'14:00'
14
14
 
15
15
  # The slowest 5K time supported by RunbyPace
16
- @@SLOWEST_5K = :'42:00'
16
+ SLOWEST_5K = :'42:00'
17
17
 
18
18
  # @param [Hash] paces_hash is a hash mapping 5K time symbols to times, represented as strings.
19
19
  # An example paces_hash is {'14:00':'4:00', '15:00':'4:55'}
@@ -30,19 +30,19 @@ module Runby
30
30
 
31
31
  # Returns first/fastest recommended pace in the set
32
32
  def first
33
- @paces[@@FASTEST_5K]
33
+ @paces[FASTEST_5K]
34
34
  end
35
- alias :fastest :first
35
+ alias fastest first
36
36
 
37
37
  # Return the last/slowest recommended pace in the set
38
38
  def last
39
- @paces[@@SLOWEST_5K]
39
+ @paces[SLOWEST_5K]
40
40
  end
41
- alias :slowest :last
41
+ alias slowest last
42
42
 
43
43
  # Creates and returns a new GoldenPaceSet with only two entries
44
44
  def self.new_from_endpoints(fastest, slowest)
45
- GoldenPaceSet.new({@@FASTEST_5K => fastest, @@SLOWEST_5K => slowest})
45
+ GoldenPaceSet.new(FASTEST_5K => fastest, SLOWEST_5K => slowest)
46
46
  end
47
47
  end
48
48
  end
@@ -27,11 +27,25 @@ module Runby
27
27
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
28
28
  class GoldenPaces
29
29
  def self.fast
30
- GoldenPaceSet.new({ '14:00': '03:44', '15:00': '03:58', '20:00': '05:09', '25:00': '06:18', '30:00': '07:24', '35:00': '08:29', '40:00': '09:33', '42:00': '09:58' })
30
+ GoldenPaceSet.new('14:00': '03:44',
31
+ '15:00': '03:58',
32
+ '20:00': '05:09',
33
+ '25:00': '06:18',
34
+ '30:00': '07:24',
35
+ '35:00': '08:29',
36
+ '40:00': '09:33',
37
+ '42:00': '09:58')
31
38
  end
32
39
 
33
40
  def self.slow
34
- GoldenPaceSet.new({ '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:42', '42:00': '11:10' })
41
+ GoldenPaceSet.new('14:00': '04:17',
42
+ '15:00': '04:33',
43
+ '20:00': '05:53',
44
+ '25:00': '07:09',
45
+ '30:00': '08:23',
46
+ '35:00': '09:33',
47
+ '40:00': '10:42',
48
+ '42:00': '11:10')
35
49
  end
36
50
  end
37
51
  end
@@ -26,11 +26,25 @@ module Runby
26
26
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
27
27
  class GoldenPaces
28
28
  def self.fast
29
- GoldenPaceSet.new({ '14:00': '04:17', '15:00': '04:33', '20:00': '05:53', '25:00': '07:09', '30:00': '08:23', '35:00': '09:33', '40:00': '10:41', '42:00': '11:08' })
29
+ GoldenPaceSet.new('14:00': '04:17',
30
+ '15:00': '04:33',
31
+ '20:00': '05:53',
32
+ '25:00': '07:09',
33
+ '30:00': '08:23',
34
+ '35:00': '09:33',
35
+ '40:00': '10:41',
36
+ '42:00': '11:08')
30
37
  end
31
38
 
32
39
  def self.slow
33
- GoldenPaceSet.new({ '14:00': '05:01', '15:00': '05:20', '20:00': '06:51', '25:00': '08:17', '30:00': '09:38', '35:00': '10:56', '40:00': '12:10', '42:00': '12:39' })
40
+ GoldenPaceSet.new('14:00': '05:01',
41
+ '15:00': '05:20',
42
+ '20:00': '06:51',
43
+ '25:00': '08:17',
44
+ '30:00': '09:38',
45
+ '35:00': '10:56',
46
+ '40:00': '12:10',
47
+ '42:00': '12:39')
34
48
  end
35
49
  end
36
50
  end
@@ -27,11 +27,25 @@ module Runby
27
27
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
28
28
  class GoldenPaces
29
29
  def self.fast
30
- GoldenPaceSet.new({ '14:00': '04:00', '15:00': '04:16', '20:00': '05:31', '25:00': '06:44', '30:00': '07:54', '35:00': '09:01', '40:00': '10:07', '42:00': '10:32' })
30
+ GoldenPaceSet.new('14:00': '04:00',
31
+ '15:00': '04:16',
32
+ '20:00': '05:31',
33
+ '25:00': '06:44',
34
+ '30:00': '07:54',
35
+ '35:00': '09:01',
36
+ '40:00': '10:07',
37
+ '42:00': '10:32')
31
38
  end
32
39
 
33
40
  def self.slow
34
- GoldenPaceSet.new({ '14:00': '04:39', '15:00': '04:57', '20:00': '06:22', '25:00': '07:43', '30:00': '09:00', '35:00': '10:15', '40:00': '11:26', '42:00': '11:53' })
41
+ GoldenPaceSet.new('14:00': '04:39',
42
+ '15:00': '04:57',
43
+ '20:00': '06:22',
44
+ '25:00': '07:43',
45
+ '30:00': '09:00',
46
+ '35:00': '10:15',
47
+ '40:00': '11:26',
48
+ '42:00': '11:53')
35
49
  end
36
50
  end
37
51
  end
@@ -26,11 +26,25 @@ module Runby
26
26
  # Used in testing, contains hashes mapping 5K race times with the recommended pace-per-km for this run type.
27
27
  class GoldenPaces
28
28
  def self.fast
29
- GoldenPaceSet.new({ '14:00': '03:07', '15:00': '03:20', '20:00': '04:21', '25:00': '05:20', '30:00': '06:19', '35:00': '07:16', '40:00': '08:12', '42:00': '08:35' })
29
+ GoldenPaceSet.new('14:00': '03:07',
30
+ '15:00': '03:20',
31
+ '20:00': '04:21',
32
+ '25:00': '05:20',
33
+ '30:00': '06:19',
34
+ '35:00': '07:16',
35
+ '40:00': '08:12',
36
+ '42:00': '08:35')
30
37
  end
31
38
 
32
39
  def self.slow
33
- GoldenPaceSet.new({ '14:00': '03:18', '15:00': '03:31', '20:00': '04:35', '25:00': '05:37', '30:00': '06:38', '35:00': '07:38', '40:00': '08:36', '42:00': '08:59' })
40
+ GoldenPaceSet.new('14:00': '03:18',
41
+ '15:00': '03:31',
42
+ '20:00': '04:35',
43
+ '25:00': '05:37',
44
+ '30:00': '06:38',
45
+ '35:00': '07:38',
46
+ '40:00': '08:36',
47
+ '42:00': '08:59')
34
48
  end
35
49
  end
36
50
  end
@@ -83,16 +83,16 @@ module Runby
83
83
  rescue StandardError => ex
84
84
  error_message = "#{ex.message} (#{str})"
85
85
  end
86
-
87
- # Break out these sanity checks into their own class if we add any more.
88
- if !time.nil? && is_five_k
89
- warning_message = '5K times of less than 14:00 are unlikely' if time.minutes_part < 14
90
- warning_message = '5K times of greater than 42:00 are not fully supported' if time.total_seconds > (42 * 60)
91
- end
92
-
86
+ warning_message = check_5k_sanity(time) if !time.nil? && is_five_k
93
87
  { time: time, error: error_message, warning: warning_message }
94
88
  end
95
89
 
90
+ def self.check_5k_sanity(time)
91
+ return unless time.is_a? RunbyTime
92
+ return '5K times of less than 14:00 are unlikely' if time.minutes_part < 14
93
+ return '5K times of greater than 42:00 are not fully supported' if time.total_seconds > (42 * 60)
94
+ end
95
+
96
96
  def to_s
97
97
  @time_s.sub(/^0/, '')
98
98
  end
@@ -133,10 +133,10 @@ module Runby
133
133
  def /(other)
134
134
  raise "Cannot divide Runby::RunbyTime by #{other.class}" unless other.is_a?(RunbyTime) || other.is_a?(Numeric)
135
135
  case other
136
- when RunbyTime
137
- total_seconds / other.total_seconds
138
- when Numeric
139
- RunbyTime.from_seconds(total_seconds / other)
136
+ when RunbyTime
137
+ total_seconds / other.total_seconds
138
+ when Numeric
139
+ RunbyTime.from_seconds(total_seconds / other)
140
140
  end
141
141
  end
142
142
 
@@ -7,24 +7,24 @@ module Runby
7
7
 
8
8
  def initialize(distance_or_multiplier, units = :km)
9
9
  case distance_or_multiplier
10
- when Distance
11
- init_from_distance distance_or_multiplier
12
- when String
13
- init_from_string distance_or_multiplier
14
- when Numeric
15
- init_from_multiplier(distance_or_multiplier, units)
16
- when Speed
17
- init_from_clone distance_or_multiplier
18
- else
19
- raise 'Unable to initialize Runby::Speed'
10
+ when Distance
11
+ init_from_distance distance_or_multiplier
12
+ when String
13
+ init_from_string distance_or_multiplier
14
+ when Numeric
15
+ init_from_multiplier(distance_or_multiplier, units)
16
+ when Speed
17
+ init_from_clone distance_or_multiplier
18
+ else
19
+ raise 'Unable to initialize Runby::Speed'
20
20
  end
21
21
  end
22
22
 
23
23
  def to_s(format: :short)
24
24
  distance = @distance.to_s(format: format)
25
25
  case format
26
- when :short then "#{distance}/ph"
27
- when :long then "#{distance} per hour"
26
+ when :short then "#{distance}/ph"
27
+ when :long then "#{distance} per hour"
28
28
  end
29
29
  end
30
30
 
@@ -43,7 +43,9 @@ module Runby
43
43
  end
44
44
 
45
45
  def self.try_parse(str)
46
- speed, error_message = nil, warning_message = nil
46
+ speed = nil
47
+ error_message = nil
48
+ warning_message = nil
47
49
  begin
48
50
  speed = Speed.parse str
49
51
  rescue StandardError => ex
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.136
4
+ version: 0.6.137
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ty Walls
@@ -104,7 +104,7 @@ homepage: https://github.com/tygerbytes/runby-pace
104
104
  licenses:
105
105
  - MIT
106
106
  metadata:
107
- commit-hash: 22a673e6be3cf165c83b3502488130076f07ec8c
107
+ commit-hash: f7d50b31ac41c3995620d6627c563c9723701bed
108
108
  post_install_message:
109
109
  rdoc_options: []
110
110
  require_paths: