Module: PaceConverter
- Included in:
- Calcpace
- Defined in:
- lib/calcpace/pace_converter.rb
Overview
Module for converting pace between different distance units
This module provides methods to convert running pace between kilometers and miles, maintaining the time per distance unit format.
Instance Method Summary collapse
-
#convert_pace(pace, conversion, compact: false) ⇒ String
Converts pace from one unit to another.
-
#pace_km_to_mi(pace_per_km, compact: false) ⇒ String
Converts pace from kilometers to miles.
-
#pace_mi_to_km(pace_per_mi, compact: false) ⇒ String
Converts pace from miles to kilometers.
Instance Method Details
#convert_pace(pace, conversion, compact: false) ⇒ String
Converts pace from one unit to another
The pace comes back in the same two formats #convert_to_clocktime offers: the padded HH:MM:SS by default, and the compact display format a runner reads on a screen with compact: true.
29 30 31 32 33 34 35 36 37 |
# File 'lib/calcpace/pace_converter.rb', line 29 def convert_pace(pace, conversion, compact: false) pace_seconds = pace.is_a?(String) ? convert_to_seconds(pace) : pace check_positive(pace_seconds, 'Pace') conversion_type = normalize_conversion(conversion) converted_seconds = apply_pace_conversion(pace_seconds, conversion_type) convert_to_clocktime(converted_seconds, compact: compact) end |
#pace_km_to_mi(pace_per_km, compact: false) ⇒ String
Converts pace from kilometers to miles
49 50 51 |
# File 'lib/calcpace/pace_converter.rb', line 49 def pace_km_to_mi(pace_per_km, compact: false) convert_pace(pace_per_km, :km_to_mi, compact: compact) end |
#pace_mi_to_km(pace_per_mi, compact: false) ⇒ String
Converts pace from miles to kilometers
63 64 65 |
# File 'lib/calcpace/pace_converter.rb', line 63 def pace_mi_to_km(pace_per_mi, compact: false) convert_pace(pace_per_mi, :mi_to_km, compact: compact) end |