Sha256: 267b2dae6c4fe976d6e66379ace8c8f7176961b74a62767608c803075a4ab34a

Contents?: true

Size: 1.42 KB

Versions: 34

Compression:

Stored size: 1.42 KB

Contents

module Runby

  # 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.
  class GoldenPaceSet
    include Enumerable

    attr_reader :paces

    # The fastest 5K time supported by RunbyPace
    @@FASTEST_5K = :'14:00'

    # The slowest 5K time supported by RunbyPace
    @@SLOWEST_5K = :'42:00'

    # @param [Hash] paces_hash is a hash mapping 5K time symbols to times, represented as strings.
    # An example paces_hash is {'14:00':'4:00', '15:00':'4:55'}
    def initialize(paces_hash)
      @paces = {}
      paces_hash.each { |five_k_time, recommended_pace| @paces[five_k_time.to_sym] = Pace.new(recommended_pace) }
    end

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

    # Returns first/fastest recommended pace in the set
    def first
      @paces[@@FASTEST_5K]
    end
    alias :fastest :first

    # Return the last/slowest recommended pace in the set
    def last
      @paces[@@SLOWEST_5K]
    end
    alias :slowest :last

    # Creates and returns a new GoldenPaceSet with only two entries
    def self.new_from_endpoints(fastest, slowest)
      GoldenPaceSet.new({@@FASTEST_5K => fastest, @@SLOWEST_5K => slowest})
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
runby_pace-0.6.132 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.131 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.130 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.128 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.127 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.126 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.125 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.124 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.123 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.122 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.121 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.120 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.119 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.118 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.117 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.116 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.115 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.114 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.113 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.112 lib/runby_pace/golden_pace_set.rb