runby_pace 0.6.106 → 0.6.108

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDM4OWZkODZlZTU0ZjFiMTcwMTc0MTJkMTUxMjVhOWQ1MDcxYzNhNg==
5
- data.tar.gz: !binary |-
6
- NTFhMWVjYjUyNTAwMTdhM2ZiNDFkMWEyN2VmMGNkY2MyYmZiYjhmMw==
2
+ SHA1:
3
+ metadata.gz: 05fcd0b6b61a1ddf39929d5599adc170e8d9d01c
4
+ data.tar.gz: 8146a49cc46bac7e57d748c77e96ff77405d863b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjJlNTJiOGZhYmQwMjFlOGQ1OTQ0MTlhNjQyNmFmZTRmZmExOTQzZDJjNTY3
10
- ZjRjMjA5MDQxMDRiNWI0OGY1YjdkMzk0ZjQ1ZGZjYTVhNzYxMGRkOGY0ZmI1
11
- OTkxOThhZmIyODVhODU3MDhlZTkzMDg0YzJmMmFjMGQzNDRjOGE=
12
- data.tar.gz: !binary |-
13
- NmI1N2ZiOGNmZTljMjY1NjUyYWRiMTNkNGZmZDlmYTJmMTA1Yjk3ODAwNDE1
14
- YWY2YzhhMmI0ZmEwZGJmMjY1NDc5MmM5NjJkNmE4NDdhMmJkOTBjYTI1NTc3
15
- MzJkNWVmZmZjZGI5ZjI2OGU4NmU1OGE1NmQ4ODE5MmE2YjQwYzA=
6
+ metadata.gz: 3d58545472843d9e8297ce991a62eae09f570c8811d10931333c89c5cc79daec03e079ceff377d94827a1abcacdca34940acd00a6976cf0877ffd0eefcc6d489
7
+ data.tar.gz: defa3958eead76a0048a22d1133d959d8913e282f048bc7e1b1c215990460991e443e9409c6a69b81372022f86965ce257730a225362b7cdadd7c03d05cd6690
@@ -24,6 +24,12 @@ module Runby
24
24
  end
25
25
  end
26
26
 
27
+ def as_speed
28
+ multiplier = (60 / @time.total_minutes).round(2)
29
+ distance = Runby::Distance.new(@distance.uom, multiplier)
30
+ Runby::Speed.new distance
31
+ end
32
+
27
33
  def <=>(other)
28
34
  if other.is_a? Pace
29
35
  return nil unless @distance == other.distance
@@ -22,6 +22,10 @@ module Runby
22
22
  PaceRange.new fast, slow
23
23
  end
24
24
 
25
+ def as_speed_range
26
+ SpeedRange.new @fast.as_speed, @slow.as_speed
27
+ end
28
+
25
29
  def to_s(format: :long)
26
30
  if @fast == @slow
27
31
  @fast.to_s(format: format)
@@ -2,13 +2,11 @@ module Runby
2
2
  # An assortment of mathematical functions related to running.
3
3
  class RunMath
4
4
  def self.convert_pace_to_speed(pace)
5
- pace = Runby::RunbyTime.new(pace)
6
- (60 / pace.total_minutes).round(2)
5
+ pace.as_speed
7
6
  end
8
7
 
9
- def self.convert_speed_to_pace(units_per_hour)
10
- raise 'units_per_hour must be numeric' unless units_per_hour.is_a? Numeric
11
- Runby::RunbyTime.from_minutes(60.0 / units_per_hour)
8
+ def self.convert_speed_to_pace(speed)
9
+ speed.as_pace
12
10
  end
13
11
 
14
12
  def self.distance_traveled(pace, time)
@@ -9,9 +9,9 @@ module Runby
9
9
  raise 'RunbyRange is a base class for PaceRange and SpeedRange. Instantiate one of them instead.'
10
10
  end
11
11
 
12
- def to_s
12
+ def to_s(format: :long)
13
13
  if @fast == @slow
14
- @fast.to_s
14
+ @fast.to_s(format: format)
15
15
  else
16
16
  "#{@fast}-#{@slow}"
17
17
  end
@@ -0,0 +1,80 @@
1
+ module Runby
2
+ # Represents a speed consisting of a distance and a unit of time in which that distance was covered
3
+ class Speed
4
+ include Comparable
5
+
6
+ attr_reader :distance
7
+
8
+ def initialize(distance_or_multiplier, units = :km)
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'
20
+ end
21
+ end
22
+
23
+ def to_s(format: :long)
24
+ distance = @distance.to_s(format: format)
25
+ case format
26
+ when :short then "#{distance}/ph"
27
+ when :long then "#{distance} per hour"
28
+ end
29
+ end
30
+
31
+ def as_pace
32
+ time = Runby::RunbyTime.from_minutes(60.0 / @distance.multiplier)
33
+ Runby::Pace.new(time, @distance.uom)
34
+ end
35
+
36
+ def self.try_parse(description)
37
+ # TODO: hard coding
38
+ distance = Distance.new(:mi, 7)
39
+ speed = Speed.new distance
40
+ { speed: speed }
41
+ end
42
+
43
+ def <=>(other)
44
+ if other.is_a? Speed
45
+ @distance <=> other.distance
46
+ elsif other.is_a? String
47
+ # TODO: Parse as Speed when Speed.parse is available
48
+ to_s(format: :short) <=> other || to_s(format: :long) <=> other
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def init_from_clone(other_speed)
55
+ @distance = Distance.new(other_speed.distance)
56
+ end
57
+
58
+ def init_from_distance(distance)
59
+ @distance = distance
60
+ end
61
+
62
+ def init_from_multiplier(multiplier, uom)
63
+ @distance = Distance.new(uom, multiplier)
64
+ end
65
+
66
+ def init_from_string(str)
67
+ results = Speed.try_parse(str)
68
+ unless results[:error]
69
+ init_from_clone results[:speed]
70
+ return
71
+ end
72
+ results = Distance.try_parse(str)
73
+ unless results[:error]
74
+ init_from_distance results[:distance]
75
+ return
76
+ end
77
+ raise "'#{str}' is not recognized as a Speed"
78
+ end
79
+ end
80
+ end
@@ -4,17 +4,29 @@ module Runby
4
4
  # Represents a range of speeds, from fast to slow.
5
5
  class SpeedRange < RunbyRange
6
6
  def initialize(fast, slow)
7
- raise 'Invalid speed values' unless fast.is_a?(Numeric) && slow.is_a?(Numeric)
8
- @fast = fast.round(2)
9
- @slow = slow.round(2)
7
+ raise "Invalid fast speed value: #{fast}" unless fast.is_a?(Numeric) || fast.is_a?(Speed)
8
+ raise "Invalid slow speed value: #{slow}" unless slow.is_a?(Numeric) || slow.is_a?(Speed)
9
+ @fast = Runby::Speed.new(fast)
10
+ @slow = Runby::Speed.new(slow)
10
11
  end
11
12
 
12
13
  # Create a new speed range from an existing pace range.
13
14
  def self.from_pace_range(pace_range)
14
- # TODO: We need a Speed class with Distance_units included
15
- fast = Runby::RunMath.convert_pace_to_speed pace_range.fast.time
16
- slow = Runby::RunMath.convert_pace_to_speed pace_range.slow.time
17
- SpeedRange.new fast, slow
15
+ pace_range.as_speed_range
16
+ end
17
+
18
+ def as_pace_range
19
+ Runby::PaceRange.new @fast.as_pace, @slow.as_pace
20
+ end
21
+
22
+ def to_s(format: :long)
23
+ if @fast == @slow
24
+ @fast.to_s(format: format)
25
+ else
26
+ fast_multiplier = format('%g', @fast.distance.multiplier.round(2))
27
+ slow_multiplier = format('%g', @slow.distance.multiplier.round(2))
28
+ @fast.to_s(format: format).sub("#{fast_multiplier}", "#{fast_multiplier}-#{slow_multiplier}")
29
+ end
18
30
  end
19
31
  end
20
32
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runby_pace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.106
4
+ version: 0.6.108
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-10-25 00:00:00.000000000 Z
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  description:
@@ -59,10 +59,10 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
64
- - .rubocop.yml
65
- - .travis.yml
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
66
  - Gemfile
67
67
  - Guardfile
68
68
  - LICENSE.txt
@@ -92,6 +92,7 @@ files:
92
92
  - lib/runby_pace/run_types/tempo_run.rb
93
93
  - lib/runby_pace/runby_range.rb
94
94
  - lib/runby_pace/runby_time.rb
95
+ - lib/runby_pace/speed.rb
95
96
  - lib/runby_pace/speed_range.rb
96
97
  - lib/runby_pace/version.rb
97
98
  - misc/rubymine.png
@@ -100,24 +101,24 @@ homepage: https://github.com/tygerbytes/runby-pace
100
101
  licenses:
101
102
  - MIT
102
103
  metadata:
103
- commit-hash: 04d742e1b7c187763822443747659507ef89b555
104
+ commit-hash: 96f98250ad3dd63f0d01f88a5542e5a6a329e0c4
104
105
  post_install_message:
105
106
  rdoc_options: []
106
107
  require_paths:
107
108
  - lib
108
109
  required_ruby_version: !ruby/object:Gem::Requirement
109
110
  requirements:
110
- - - ! '>='
111
+ - - ">="
111
112
  - !ruby/object:Gem::Version
112
113
  version: 2.2.0
113
114
  required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  requirements:
115
- - - ! '>='
116
+ - - ">="
116
117
  - !ruby/object:Gem::Version
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.4.5
121
+ rubygems_version: 2.4.8
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Runby Pace is the core logic which simplifies the calculation of target paces