Sha256: dc6ec0e5783fba42b042b9a834209ac36fad284d7bafc064b00620269d509d6c

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 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
      @paces.each do |h, v|
        yield 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

6 entries across 6 versions & 1 rubygems

Version Path
runby_pace-0.6.143 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.142 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.141 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.140 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.139 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.137 lib/runby_pace/golden_pace_set.rb