Class: Runby::GoldenPaceSet
- Inherits:
-
Object
- Object
- Runby::GoldenPaceSet
- Includes:
- Enumerable
- Defined in:
- lib/runby_pace/golden_pace_set.rb
Overview
Maps a set of 5K race times with their pre-calculated pace recommendations. This is useful in testing as well as defining the fastest and slowest supported 5K times. GoldenPaceSet could conceivably be used to pre-compute a large number of recommended paces,
thus reducing runtime CPU overhead.
Constant Summary collapse
- FASTEST_5K =
The fastest 5K time supported by RunbyPace
:'14:00'
- SLOWEST_5K =
The slowest 5K time supported by RunbyPace
:'42:00'
Instance Attribute Summary collapse
-
#paces ⇒ Object
readonly
Returns the value of attribute paces.
Class Method Summary collapse
-
.new_from_endpoints(fastest, slowest) ⇒ Object
Creates and returns a new GoldenPaceSet with only two entries.
Instance Method Summary collapse
- #each ⇒ Object
-
#first ⇒ Object
(also: #fastest)
Returns first/fastest recommended pace in the set.
-
#initialize(paces_hash) ⇒ GoldenPaceSet
constructor
An example paces_hash is ‘15:00’:‘4:55’.
-
#last ⇒ Object
(also: #slowest)
Return the last/slowest recommended pace in the set.
Constructor Details
#initialize(paces_hash) ⇒ GoldenPaceSet
An example paces_hash is ‘15:00’:‘4:55’
22 23 24 25 |
# File 'lib/runby_pace/golden_pace_set.rb', line 22 def initialize(paces_hash) @paces = {} paces_hash.each { |five_k_time, recommended_pace| @paces[five_k_time.to_sym] = Pace.new(recommended_pace) } end |
Instance Attribute Details
#paces ⇒ Object (readonly)
Returns the value of attribute paces.
12 13 14 |
# File 'lib/runby_pace/golden_pace_set.rb', line 12 def paces @paces end |
Class Method Details
.new_from_endpoints(fastest, slowest) ⇒ Object
Creates and returns a new GoldenPaceSet with only two entries
46 47 48 |
# File 'lib/runby_pace/golden_pace_set.rb', line 46 def self.new_from_endpoints(fastest, slowest) GoldenPaceSet.new(FASTEST_5K => fastest, SLOWEST_5K => slowest) end |
Instance Method Details
#each ⇒ Object
27 28 29 30 31 |
# File 'lib/runby_pace/golden_pace_set.rb', line 27 def each @paces.each do |h, v| yield h, v end end |
#first ⇒ Object Also known as: fastest
Returns first/fastest recommended pace in the set
34 35 36 |
# File 'lib/runby_pace/golden_pace_set.rb', line 34 def first @paces[FASTEST_5K] end |
#last ⇒ Object Also known as: slowest
Return the last/slowest recommended pace in the set
40 41 42 |
# File 'lib/runby_pace/golden_pace_set.rb', line 40 def last @paces[SLOWEST_5K] end |