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.



20
21
22
23
# File 'lib/runby_pace/golden_pace_set.rb', line 20

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.



10
11
12
# File 'lib/runby_pace/golden_pace_set.rb', line 10

def paces
  @paces
end

Class Method Details

.new_from_endpoints(fastest, slowest) ⇒ Object

Creates and returns a new GoldenPaceSet with only two entries



44
45
46
# File 'lib/runby_pace/golden_pace_set.rb', line 44

def self.new_from_endpoints(fastest, slowest)
  GoldenPaceSet.new({@@FASTEST_5K => fastest, @@SLOWEST_5K => slowest})
end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
28
29
# File 'lib/runby_pace/golden_pace_set.rb', line 25

def each(&block)
  @paces.each do |h, v|
    block.call(h, v)
  end
end

#firstObject Also known as: fastest

Returns first/fastest recommended pace in the set



32
33
34
# File 'lib/runby_pace/golden_pace_set.rb', line 32

def first
  @paces[@@FASTEST_5K]
end

#lastObject Also known as: slowest

Return the last/slowest recommended pace in the set



38
39
40
# File 'lib/runby_pace/golden_pace_set.rb', line 38

def last
  @paces[@@SLOWEST_5K]
end