Class: Runby::GoldenPaceSet

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paces_hash) ⇒ GoldenPaceSet

An example paces_hash is '15:00':'4:55'

Parameters:

  • paces_hash (Hash)

    is a hash mapping 5K time symbols to times, represented as strings.


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

#pacesObject (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

#eachObject


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

#firstObject 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

#lastObject 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