runby_pace 0.5.86 → 0.6.87

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWJjNGYwMWMzZDVkY2FmNjNiY2Q3NTFiMzg0ODZiMjdkYzJkZDUzYw==
4
+ ODUzOGU5MWZhZGI0NWU2ZGJiMjNmZGEzMjZhNmU2MGU3MWFlMjg1Mw==
5
5
  data.tar.gz: !binary |-
6
- MDI1ZTc2ZDQyM2ZkOTYyNTM5ZDY4OGNjMDJkMmFjNGVmYzgzNWQyOQ==
6
+ NDFlZjBhOTllOWJlYmM3NjA4NzllMWM4MjgxYWZmMmI2Yzc3MDcyZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmUyOGM2ZTE2NTczZDczMjhjM2NkNTViMDg2OGE2N2M2ZDZmMjlkZmJkOGU0
10
- MWFmMzE0NDA3ZDljOWM0ZGE4Mzg0ZjBkMzFhMDliZDQxMGNlOTkxNGQ4MDJl
11
- NDRmMDdlMWFkNWQ5NzQ3ZDNjZjJiOWU1NGNiN2UyYzkxODg4YTQ=
9
+ ODk1NTcwNTEzYTAwNTdhZmRlOTVhNWVkNDhkZDA2YWVmYWRhMDUwODgxNzFh
10
+ ODE0M2ViNzliZmI2YjdmZmI3OGQyMmE5YWFhMDJiYzVmNGQ3ZTg1Yjk5NTRh
11
+ N2QxNmMwMmI5ODMyNjM1NGQzMzhhNTc4ZjhlY2U0OTM5Y2NlZTU=
12
12
  data.tar.gz: !binary |-
13
- ZTRkMGNkZGIyOTFiNWE1MTE0NThlYzk0NzY4NTJiYTU0YzNhZDhhZjFlZGM5
14
- YmJjNzVhZTM4MmZjZGYxOGNmMTIxODc0MmViMDZiZDJlNzY0MDAyN2MyNTdl
15
- NWJhNzViNGU3OTQxYmQxMGU1ZmUxODEyNTNhMWM5NThmOTEyNmY=
13
+ NTQxY2VhZjE0YTAzNDViNDEzYTIzODIzZGRmN2Y1Zjk4NDBiNzFhYjc2YzBj
14
+ YTVhZDUxNzM2YmU0ZGNjYjE4ODUwOWNhNTM1MDg1ZGE3ZTRmNTYwNzI1NjI4
15
+ YjY4NmE2ZGEyMTQyY2JjNzVhNmQ5YWZkMTIyNDA3MzUyMGRkMGY=
@@ -3,21 +3,22 @@ module Runby
3
3
  class Distance
4
4
  attr_reader :uom, :multiplier
5
5
  def initialize(uom = :km, multiplier = 1)
6
- raise 'Invalid multiplier' unless multiplier.is_a?(Numeric)
7
6
  case uom
8
7
  when Distance
9
8
  return init_from_clone uom
9
+ when DistanceUnit
10
+ return init_from_distance_unit uom, multiplier
10
11
  when String
11
12
  return init_from_string uom
12
13
  when Symbol
13
- return init_from_symbol(uom, multiplier)
14
+ return init_from_symbol uom, multiplier
14
15
  else
15
16
  raise 'Invalid distance unit of measure'
16
17
  end
17
18
  end
18
19
 
19
20
  def meters
20
- kilometers = @multiplier * Runby::DistanceUnits.conversion_factor(@uom)
21
+ kilometers = @multiplier * @uom.conversion_factor
21
22
  kilometers * 1000.0
22
23
  end
23
24
 
@@ -27,10 +28,10 @@ module Runby
27
28
  uom = str.scan(/[-_a-z ]+$/).first
28
29
  raise "Unable to find distance unit in '#{str}'" if uom.nil?
29
30
 
30
- parsed_uom = Runby::DistanceUnits.parse uom
31
- raise "'#{uom.strip}' is not recognized as a distance unit" if parsed_uom[:uom].nil?
31
+ parsed_uom = Runby::DistanceUnit.parse uom
32
+ raise "'#{uom.strip}' is not recognized as a distance unit" if parsed_uom.nil?
32
33
 
33
- self.new parsed_uom[:uom], parsed_uom[:factor] * multiplier
34
+ self.new parsed_uom, multiplier
34
35
  end
35
36
 
36
37
  def to_s
@@ -38,7 +39,7 @@ module Runby
38
39
  end
39
40
 
40
41
  def pluralized_uom
41
- uom_description = DistanceUnits.description(@uom).downcase
42
+ uom_description = @uom.description.downcase
42
43
  if @multiplier > 1 then
43
44
  uom_description += 's'
44
45
  end
@@ -52,13 +53,19 @@ module Runby
52
53
  @multiplier = distance.multiplier
53
54
  end
54
55
 
56
+ def init_from_distance_unit(uom, multiplier)
57
+ @uom = uom
58
+ @multiplier = multiplier
59
+ end
60
+
55
61
  def init_from_string(string)
56
62
  init_from_clone Distance.parse string
57
63
  end
58
64
 
59
- def init_from_symbol(distance_uom, multiplier)
60
- raise "Unknown unit of measure #{distance_uom}" unless Runby::DistanceUnits.known_uom? distance_uom
61
- @uom = distance_uom
65
+ def init_from_symbol(distance_uom_symbol, multiplier)
66
+ raise "Unknown unit of measure #{distance_uom_symbol}" unless Runby::DistanceUnit.known_uom? distance_uom_symbol
67
+ raise 'Invalid multiplier' unless multiplier.is_a?(Numeric)
68
+ @uom = DistanceUnit.new distance_uom_symbol
62
69
  @multiplier = multiplier * 1.0
63
70
  end
64
71
  end
@@ -0,0 +1,50 @@
1
+ module Runby
2
+ # Represents the distance units (e.g. kilometers, miles) used in paces
3
+ # including the human-readable description of each unit
4
+ # and the factor used to convert it to kilometers.
5
+ class DistanceUnit
6
+ attr_reader :symbol, :description, :conversion_factor
7
+
8
+ def initialize(unit_of_measure)
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
11
+ @symbol = unit_of_measure
12
+ @conversion_factor = @@_uom_definitions[@symbol][:conversion_factor]
13
+ elsif unit_of_measure.is_a? String
14
+ parsed_uom = DistanceUnit.parse(unit_of_measure)
15
+ @symbol = parsed_uom.symbol
16
+ @conversion_factor = @@_uom_definitions[@symbol][:conversion_factor]
17
+ end
18
+
19
+ @description = @@_uom_definitions[@symbol][:description]
20
+ end
21
+
22
+ def self.parse(description)
23
+ description = description.strip.chomp.downcase
24
+ found_uom = nil
25
+ @@_uom_definitions.each do |uom, details|
26
+ if details[:synonyms].include? description
27
+ found_uom = uom
28
+ break
29
+ end
30
+ end
31
+ raise "Error parsing distance unit '#{description}'" unless found_uom
32
+ return DistanceUnit.new found_uom
33
+ end
34
+
35
+ def self.known_uom?(symbol)
36
+ # TODO: test
37
+ @@_uom_definitions.has_key?(symbol)
38
+ end
39
+
40
+ @@_uom_definitions =
41
+ { km: { description: 'Kilometer', conversion_factor: 1.0, synonyms: %w(k km kms kilometer kilometers) },
42
+ m: { description: 'Meter', conversion_factor: 0.001, synonyms: %w(m meter meters) },
43
+ mi: { description: 'Mile', conversion_factor: 1.609344, synonyms: %w(mi mile miles) },
44
+ ft: { description: 'Feet', conversion_factor: 0.0003048, synonyms: %w(ft foot feet) },
45
+ yd: { description: 'Yards', conversion_factor: 1093.61, synonyms: %w(y yd yds yard yards) },
46
+ # Fun distance unit of measures
47
+ marathon: { description: 'Marathon', conversion_factor: 42.1648128, synonyms: %w(marathon) }
48
+ }
49
+ end
50
+ end
@@ -38,10 +38,11 @@ module Runby
38
38
 
39
39
  # Calculate the prescribed pace for the given 5K time
40
40
  def calc(five_k_time, distance_units = :km)
41
- five_k_time = Runby::RunbyTime.new(five_k_time)
41
+ five_k_time = Runby::RunbyTime.new five_k_time
42
+ distance_units = Runby::DistanceUnit.new distance_units
42
43
  x2 = ((five_k_time.total_minutes * 2) - (MIDPOINT_X - 1)) - 1
43
44
  minutes_per_km = slope * x2 + @fastest_pace_km.total_minutes + curve_minutes(x2)
44
- minutes_per_unit = minutes_per_km * Runby::DistanceUnits.conversion_factor(distance_units)
45
+ minutes_per_unit = minutes_per_km * distance_units.conversion_factor
45
46
  Runby::RunbyTime.from_minutes(minutes_per_unit)
46
47
  end
47
48
 
@@ -1,3 +1,3 @@
1
1
  module Runby
2
- VERSION = "0.5.#{`git rev-list --count HEAD`}".freeze
2
+ VERSION = "0.6.#{`git rev-list --count HEAD`}".freeze
3
3
  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.5.86
4
+ version: 0.6.87
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-09-11 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,7 @@ files:
74
74
  - bin/setup
75
75
  - lib/runby_pace.rb
76
76
  - lib/runby_pace/distance.rb
77
- - lib/runby_pace/distance_units.rb
77
+ - lib/runby_pace/distance_unit.rb
78
78
  - lib/runby_pace/pace.rb
79
79
  - lib/runby_pace/pace_data.rb
80
80
  - lib/runby_pace/pace_range.rb
@@ -99,7 +99,7 @@ homepage: https://github.com/tygerbytes/runby-pace
99
99
  licenses:
100
100
  - MIT
101
101
  metadata:
102
- commit-hash: 0c6578c58d5e0a05921d05bb064583d5426a6b80
102
+ commit-hash: deb794e87cde1dc18d24e06c18190216cf6ef404
103
103
  post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths:
@@ -1,46 +0,0 @@
1
- module Runby
2
- # Represents the distance units (e.g. kilometers, miles) used in paces
3
- # including the human-readable description of each unit
4
- # and the factor used to convert it to kilometers.
5
- class DistanceUnits
6
- def self.description(uom)
7
- @@_uom_definitions[uom][:description]
8
- end
9
-
10
- def self.parse(description)
11
- description = description.strip.chomp
12
- found_uom = nil
13
- found_uom_factor = 1
14
- @@_uom_definitions.each do |uom, details|
15
- if details[:synonyms].include? description
16
- if details.has_key? :uom
17
- found_uom = details[:uom]
18
- found_uom_factor = details[:factor]
19
- else
20
- found_uom = uom
21
- end
22
- break
23
- end
24
- end
25
- { uom: found_uom, factor: found_uom_factor }
26
- end
27
-
28
- def self.conversion_factor(units)
29
- @@_uom_definitions[units][:conversion_factor]
30
- end
31
-
32
- def self.known_uom?(symbol)
33
- # TODO: test
34
- @@_uom_definitions.has_key?(symbol)
35
- end
36
-
37
- @@_uom_definitions =
38
- { km: { description: 'Kilometer', conversion_factor: 1.0, synonyms: %w(k km kms kilometer kilometers) },
39
- m: { description: 'Meter', conversion_factor: 0.001, synonyms: %w(m meter meters) },
40
- mi: { description: 'Mile', conversion_factor: 1.609344, synonyms: %w(mi mile miles) },
41
- ft: { description: 'Feet', conversion_factor: 0.0003048, synonyms: %w(ft foot feet) },
42
- # Special UOMs, which just point to "real" UOMs in this hash table
43
- marathon: { description: 'Marathon', synonyms: %w(marathon), uom: :mi, factor: 26.2 }
44
- }
45
- end
46
- end