Sha256: 75ff5ad75ab5144a1de8df6e4beb6a4fb477e9bf6c8fd1fcce32d243184912d7

Contents?: true

Size: 1.42 KB

Versions: 23

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

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

23 entries across 23 versions & 1 rubygems

Version Path
runby_pace-0.62.7 lib/runby_pace/golden_pace_set.rb
runby_pace-0.62.5 lib/runby_pace/golden_pace_set.rb
runby_pace-0.62.4 lib/runby_pace/golden_pace_set.rb
runby_pace-0.62.3 lib/runby_pace/golden_pace_set.rb
runby_pace-0.62.2 lib/runby_pace/golden_pace_set.rb
runby_pace-0.2.50.111 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.160 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.159 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.158 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.157 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.156 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.155 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.154 lib/runby_pace/golden_pace_set.rb
runby_pace-0.61.153 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.152 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.151 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.150 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.149 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.148 lib/runby_pace/golden_pace_set.rb
runby_pace-0.6.147 lib/runby_pace/golden_pace_set.rb