runby_pace 0.5.85 → 0.5.86

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
- M2Y0Y2I0Zjg3ZjYzZjc4NGNkYjBiN2NmODQwYTYyNTQ3MDkwMTZkNg==
4
+ MWJjNGYwMWMzZDVkY2FmNjNiY2Q3NTFiMzg0ODZiMjdkYzJkZDUzYw==
5
5
  data.tar.gz: !binary |-
6
- ZmE5ZDdkZTgyNTdkOWI3YjVhYjc1NTg0NzE5ZjhhZmJhM2JkOTZiZA==
6
+ MDI1ZTc2ZDQyM2ZkOTYyNTM5ZDY4OGNjMDJkMmFjNGVmYzgzNWQyOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NWEwZmIwNjM3YWUzMTNhYmQ1YjcwODdmM2YwODhmMjc3OGI4ZTE4NWRjZDQ1
10
- ZjZhYWQ0NjJkNTE5NDM4MTg1NDk4MDFjYTViZDMyNjY0ZTcyNmIzYjE5ODVj
11
- YWZlOTk2NmQxODFmYjI0MWVkNDA2YjA4MmQxNTk5ZGM0NjIyN2Q=
9
+ YmUyOGM2ZTE2NTczZDczMjhjM2NkNTViMDg2OGE2N2M2ZDZmMjlkZmJkOGU0
10
+ MWFmMzE0NDA3ZDljOWM0ZGE4Mzg0ZjBkMzFhMDliZDQxMGNlOTkxNGQ4MDJl
11
+ NDRmMDdlMWFkNWQ5NzQ3ZDNjZjJiOWU1NGNiN2UyYzkxODg4YTQ=
12
12
  data.tar.gz: !binary |-
13
- YTZmY2ZhOGUxYTNjZDM1MDY4M2NiZWQyODRjY2I3ODEyMDNhYWMxNWUwMjM5
14
- ZTk0Mzc4NTNlNzJjNTZiOTA3NGQ2MzA2YTM1MGRlZjI1MTQ1OTU1MGJmZTk5
15
- NzMzZDU4NTk1MjUzMzM4YzE1NmYzNTBiMDM1YTUxNjQxMDQ5NWE=
13
+ ZTRkMGNkZGIyOTFiNWE1MTE0NThlYzk0NzY4NTJiYTU0YzNhZDhhZjFlZGM5
14
+ YmJjNzVhZTM4MmZjZGYxOGNmMTIxODc0MmViMDZiZDJlNzY0MDAyN2MyNTdl
15
+ NWJhNzViNGU3OTQxYmQxMGU1ZmUxODEyNTNhMWM5NThmOTEyNmY=
@@ -2,25 +2,18 @@ module Runby
2
2
  # Represents a distance (distance UOM and multiplier)
3
3
  class Distance
4
4
  attr_reader :uom, :multiplier
5
- def initialize(distance_uom = :km, multiplier = 1)
6
- # TODO: Test and cleanup
7
- if distance_uom.is_a? Distance
8
- return init_from_clone distance_uom
9
- end
10
-
11
- raise 'Invalid distance unit of measure' unless [String, Symbol].include? distance_uom.class
5
+ def initialize(uom = :km, multiplier = 1)
12
6
  raise 'Invalid multiplier' unless multiplier.is_a?(Numeric)
13
-
14
- if distance_uom.is_a? Symbol
15
- raise "Unknown unit of measure #{distance_uom}" unless Runby::DistanceUnits.known_uom? distance_uom
16
- @uom = distance_uom
17
- @multiplier = multiplier * 1.0
18
- return
7
+ case uom
8
+ when Distance
9
+ return init_from_clone uom
10
+ when String
11
+ return init_from_string uom
12
+ when Symbol
13
+ return init_from_symbol(uom, multiplier)
14
+ else
15
+ raise 'Invalid distance unit of measure'
19
16
  end
20
-
21
- distance = Distance.parse distance_uom
22
- @uom = distance.uom
23
- @multiplier = distance.multiplier
24
17
  end
25
18
 
26
19
  def meters
@@ -30,15 +23,12 @@ module Runby
30
23
 
31
24
  def self.parse(str)
32
25
  str = str.strip.chomp.downcase
33
- # TODO: handle multipliers with commas/spaces
34
26
  multiplier = str.scan(/[\d,.]+/).first.to_f
35
27
  uom = str.scan(/[-_a-z ]+$/).first
36
- # TODO: test V
37
- raise "Unable to find distance unit in #{str}" if uom.nil?
28
+ raise "Unable to find distance unit in '#{str}'" if uom.nil?
38
29
 
39
30
  parsed_uom = Runby::DistanceUnits.parse uom
40
- # TODO: test
41
- raise "#{uom} is not recognized as a distance unit" if parsed_uom[:uom].nil?
31
+ raise "'#{uom.strip}' is not recognized as a distance unit" if parsed_uom[:uom].nil?
42
32
 
43
33
  self.new parsed_uom[:uom], parsed_uom[:factor] * multiplier
44
34
  end
@@ -56,9 +46,20 @@ module Runby
56
46
  end
57
47
 
58
48
  private
49
+
59
50
  def init_from_clone(distance)
60
51
  @uom = distance.uom
61
52
  @multiplier = distance.multiplier
62
53
  end
54
+
55
+ def init_from_string(string)
56
+ init_from_clone Distance.parse string
57
+ end
58
+
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
62
+ @multiplier = multiplier * 1.0
63
+ end
63
64
  end
64
65
  end
@@ -4,14 +4,14 @@ module Runby
4
4
  # and the factor used to convert it to kilometers.
5
5
  class DistanceUnits
6
6
  def self.description(uom)
7
- @@_uom_definition[uom][:description]
7
+ @@_uom_definitions[uom][:description]
8
8
  end
9
9
 
10
10
  def self.parse(description)
11
11
  description = description.strip.chomp
12
12
  found_uom = nil
13
13
  found_uom_factor = 1
14
- @@_uom_definition.each do |uom, details|
14
+ @@_uom_definitions.each do |uom, details|
15
15
  if details[:synonyms].include? description
16
16
  if details.has_key? :uom
17
17
  found_uom = details[:uom]
@@ -26,15 +26,15 @@ module Runby
26
26
  end
27
27
 
28
28
  def self.conversion_factor(units)
29
- @@_uom_definition[units][:conversion_factor]
29
+ @@_uom_definitions[units][:conversion_factor]
30
30
  end
31
31
 
32
32
  def self.known_uom?(symbol)
33
33
  # TODO: test
34
- @@_uom_definition.has_key?(symbol)
34
+ @@_uom_definitions.has_key?(symbol)
35
35
  end
36
36
 
37
- @@_uom_definition =
37
+ @@_uom_definitions =
38
38
  { km: { description: 'Kilometer', conversion_factor: 1.0, synonyms: %w(k km kms kilometer kilometers) },
39
39
  m: { description: 'Meter', conversion_factor: 0.001, synonyms: %w(m meter meters) },
40
40
  mi: { description: 'Mile', conversion_factor: 1.609344, synonyms: %w(mi mile miles) },
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.85
4
+ version: 0.5.86
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-06 00:00:00.000000000 Z
11
+ date: 2016-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,7 @@ homepage: https://github.com/tygerbytes/runby-pace
99
99
  licenses:
100
100
  - MIT
101
101
  metadata:
102
- commit-hash: b7e91031243d197b78a140542c04b9089c35f47c
102
+ commit-hash: 0c6578c58d5e0a05921d05bb064583d5426a6b80
103
103
  post_install_message:
104
104
  rdoc_options: []
105
105
  require_paths: