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) ⇒ String
Converts pace from one unit to another.
-
#pace_km_to_mi(pace_per_km) ⇒ String
Converts pace from kilometers to miles.
-
#pace_mi_to_km(pace_per_mi) ⇒ String
Converts pace from miles to kilometers.
Instance Method Details
#convert_pace(pace, conversion) ⇒ String
Converts pace from one unit to another
20 21 22 23 24 25 26 27 28 |
# File 'lib/calcpace/pace_converter.rb', line 20 def convert_pace(pace, conversion) 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) end |
#pace_km_to_mi(pace_per_km) ⇒ String
Converts pace from kilometers to miles
38 39 40 |
# File 'lib/calcpace/pace_converter.rb', line 38 def pace_km_to_mi(pace_per_km) convert_pace(pace_per_km, :km_to_mi) end |
#pace_mi_to_km(pace_per_mi) ⇒ String
Converts pace from miles to kilometers
50 51 52 |
# File 'lib/calcpace/pace_converter.rb', line 50 def pace_mi_to_km(pace_per_mi) convert_pace(pace_per_mi, :mi_to_km) end |