Module: PaceCalculator
- Included in:
- Calcpace
- Defined in:
- lib/calcpace/pace_calculator.rb
Overview
Module for calculating race times and paces for standard distances
This module provides convenience methods for calculating finish times and paces for common race distances like 5K, 10K, half-marathon, marathon, and 100K.
Constant Summary collapse
- RACE_DISTANCES =
Standard race distances in kilometers
{ '5k' => 5.0, '10k' => 10.0, 'half_marathon' => 21.0975, 'marathon' => 42.195, '100k' => 100.0, '1mile' => 1.60934, '5mile' => 8.04672, '10mile' => 16.0934 }.freeze
Instance Method Summary collapse
-
#list_races ⇒ Hash
Lists all available standard race distances.
-
#race_pace(target_time, race) ⇒ Float
Calculates the required pace per kilometer to finish a race in a target time.
-
#race_pace_clock(target_time, race) ⇒ String
Calculates the required pace and returns it as a clock time string.
-
#race_time(pace_per_km, race) ⇒ Float
Calculates the finish time for a race given a pace per kilometer.
-
#race_time_clock(pace_per_km, race) ⇒ String
Calculates the finish time for a race and returns it as a clock time string.
Instance Method Details
#list_races ⇒ Hash
Lists all available standard race distances
84 85 86 |
# File 'lib/calcpace/pace_calculator.rb', line 84 def list_races RACE_DISTANCES.dup end |
#race_pace(target_time, race) ⇒ Float
Calculates the required pace per kilometer to finish a race in a target time
59 60 61 62 63 64 |
# File 'lib/calcpace/pace_calculator.rb', line 59 def race_pace(target_time, race) distance = race_distance(race) time_seconds = target_time.is_a?(String) ? convert_to_seconds(target_time) : target_time check_positive(time_seconds, 'Time') time_seconds / distance end |
#race_pace_clock(target_time, race) ⇒ String
Calculates the required pace and returns it as a clock time string
74 75 76 |
# File 'lib/calcpace/pace_calculator.rb', line 74 def race_pace_clock(target_time, race) convert_to_clocktime(race_pace(target_time, race)) end |
#race_time(pace_per_km, race) ⇒ Float
Calculates the finish time for a race given a pace per kilometer
30 31 32 33 34 35 |
# File 'lib/calcpace/pace_calculator.rb', line 30 def race_time(pace_per_km, race) distance = race_distance(race) pace_seconds = pace_per_km.is_a?(String) ? convert_to_seconds(pace_per_km) : pace_per_km check_positive(pace_seconds, 'Pace') distance * pace_seconds end |
#race_time_clock(pace_per_km, race) ⇒ String
Calculates the finish time for a race and returns it as a clock time string
46 47 48 |
# File 'lib/calcpace/pace_calculator.rb', line 46 def race_time_clock(pace_per_km, race) convert_to_clocktime(race_time(pace_per_km, race)) end |