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:18", "00:42:35", "01:03:53", "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 (String, Symbol)

    race distance (‘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:

  • (ArgumentError)

    if race or split_distance is invalid



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

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