Sha256: 10db8a3a905b27e04101611f980359b97560292bf3fe6d02dff1d7f2f0650779

Contents?: true

Size: 678 Bytes

Versions: 1

Compression:

Stored size: 678 Bytes

Contents

module Stressfactor
  class AveragePaceAccumulator
    attr_accessor :intervals

    def initialize(intervals)
      @intervals = intervals
    end

    def average_pace(strategy: :raw)
      strategy_klass = strategy == :raw ? RawPaceStrategy : GradeAdjustedPaceStrategy
      intervals.inject(0) do |acc, interval|
        weighted_interval = (interval.distance / total_distance) * strategy_klass.calculate_for_interval(interval)
        acc + weighted_interval
      end
    end
    private
    # Total elapsed time in minutes
    def total_distance
      @total_distance ||= intervals.inject(0) do |acc, interval|
        acc + interval.distance
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stressfactor-0.0.1 lib/stressfactor/average_pace_accumulator.rb