Calcpace is a Ruby gem designed to assist with calculations related to running and cycling activities. It can calculate pace, total time, and distance, and also convert distances between miles and kilometers. Results are provided in a readable format, with times in HH:MM:SS and distances in X.X format.
gem 'calcpace', '~> 0.2.0'
Then run bundle install.
gem install calcpace
To calculate pace, provide the total time (in HH:MM:SS format) and distance (in X.X format, representing kilometers or miles).
Calcpace.new.pace('01:00:00', 12) # => "00:05:00"
To calculate total time, provide the pace (in HH:MM:SS format) and distance (in X.X format, representing kilometers or miles).
Calcpace.new.total_time('00:05:00', 12) # => "01:00:00"
To calculate distance, provide the running time (in HH:MM:SS format) and pace (in HH:MM:SS format).
Calcpace.new.distance('01:30:00', '00:05:00') # => 18.0
To convert distances, provide the distance and the unit of measurement (either 'km' for kilometers or 'mi' for miles).
Calcpace.new.convert_distance(10, 'km') # => 6.21
Calcpace.new.convert_distance(10, 'mi') # => 16.09
Calcpace also provides other useful methods to convert values and check the validity of input.
calcpace = Calcpace.new
calcpace.convert_to_seconds('01:00:00') # => 3600
calcpace.convert_to_clock_time(3600) # => "01:00:00"
calcpace.check_digits_time('01:00:00') # => nil
calcpace.check_digits_time('01-00-00') # => It must be a XX:XX:XX time (RuntimeError)
If the provided parameters do not meet the expected formats, Calcpace will raise an error detailing the issue. The gem always returns data using the same distance unit (kilometers or miles) that was used as input.
We welcome contributions to Calcpace! To contribute, you can clone this repository and submit a pull request. Please ensure that your code adheres to our style guidelines and includes tests where appropriate.
The gem is available as open source under the terms of the MIT License.