Module: RaceSplits

Included in:
Calcpace
Defined in:
lib/calcpace/race_splits.rb

Overview

Module for calculating race splits (partial times)

This module provides methods to calculate split times for races, supporting different pacing strategies like even pace, negative splits, etc.

Instance Method Summary collapse

Instance Method Details

#race_splits(race, target_time:, split_distance:, strategy: :even) ⇒ Array<String>

Calculates split times for a race

Examples:

Even pace splits for half marathon

race_splits('half_marathon', target_time: '01:30:00', split_distance: '5k')
#=> ["00:21:20", "00:42:40", "01:03:59", "01:25:19", "01:30:00"]

Negative splits (second half faster)

race_splits('10k', target_time: '00:40:00', split_distance: '5k', strategy: :negative)
#=> ["00:20:48", "00:40:00"] (first 5k slower, second 5k faster)

Parameters:

  • race (Numeric, String, Symbol)

    distance in kilometers (7.79, '7.79') or a standard race name ('5k', '10k', 'half_marathon', 'marathon', '100k', etc.)

  • target_time (String)

    target finish time in HH:MM:SS or MM:SS format

  • split_distance (String, Numeric)

    distance for each split ('5k', '1k', '1mile', or numeric in km)

  • strategy (Symbol) (defaults to: :even)

    pacing strategy - :even (default), :negative, or :positive

Returns:

  • (Array<String>)

    array of cumulative split times in HH:MM:SS format

Raises:



26
27
28
29
30
31
32
33
34
35
# File 'lib/calcpace/race_splits.rb', line 26

def race_splits(race, target_time:, split_distance:, strategy: :even)
  total_distance = race_distance(race)
  target_seconds = target_time.is_a?(String) ? convert_to_seconds(target_time) : target_time
  check_positive(target_seconds, 'Target time')

  split_km = normalize_split_distance(split_distance)
  validate_split_distance(split_km, total_distance)

  calculate_splits(total_distance, target_seconds, split_km, strategy)
end