-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update ruby version to 3.2.1 * add method to check seconds * add name friendly methods to convert distance, clocktime and seconds * add handle to more than 24h in conversions of seconds * add round option to user in convert * update Readme and gemspec * update readme and gemspec * Add bigdecimal option and methods to receive result in seconds or bigdecimal * Rubocop lint adjusts * update gitignore * update gem version in readme
- Loading branch information
Showing
8 changed files
with
101 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/calcpace-* | ||
/calcpace-* | ||
calcpace.gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "minitest/test_task" | ||
require 'minitest/test_task' | ||
|
||
Minitest::TestTask.create(:test) do |t| | ||
t.libs << "test" | ||
t.libs << "lib" | ||
t.libs << 'test' | ||
t.libs << 'lib' | ||
t.warning = false | ||
end | ||
|
||
task :default => :test | ||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
|
||
Gem::Specification.new do |s| | ||
s.name = 'calcpace' | ||
s.version = '1.0.0' | ||
s.summary = 'Calcpace: calculate time and distances for activities such as running and cycling.' | ||
s.description = 'Calculate pace, total time, distance and easily convert distances (kilometers and miles) for activities like running and cycling. Get readable results in HH:MM:SS or X.X format for time and distance calculations.' | ||
s.version = '1.1.1' | ||
s.summary = 'Calcpace: calculate time, distance, pace, velocity and convert distances in an easy and precise way.' | ||
s.description = 'Calcpace is a Ruby gem that helps with calculations related to running/cycling activities or general purposes involving distance and time. It can calculate pace, total time, and distance. It also converts distances between miles and kilometers and check formats of time and distance. The results are provided in a readable format, with times in HH:MM:SS or seconds and distances in X.X format. If you need, the gem supports BigDecimal to handle the calculations, ' | ||
s.authors = ['Joao Gilberto Saraiva'] | ||
s.email = '[email protected]' | ||
s.files = ['lib/calcpace.rb', 'lib/calcpace/calculator.rb', 'lib/calcpace/checker.rb', 'lib/calcpace/converter.rb'] | ||
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s| | |
s.add_development_dependency 'rubocop', '~> 0.79' | ||
s.add_development_dependency 'rubocop-minitest', '~> 0.11' | ||
s.required_ruby_version = '>= 2.7.0' | ||
s.post_install_message = "It's time to grab your sneakers or hop on your bike and start exercising! Thank you for installing Calcpace!" | ||
s.post_install_message = "It's time to calculate! Thank you for installing Calcpace." | ||
s.metadata = { 'source_code_uri' => 'https://github.com/0jonjo/calcpace' } | ||
s.homepage = 'https://github.com/0jonjo/calcpace' | ||
s.license = 'MIT' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bigdecimal' | ||
|
||
module Calculator | ||
def pace(time, distance) | ||
def pace(time, distance, bigdecimal = false) | ||
pace_in_seconds = pace_seconds(time, distance, bigdecimal) | ||
convert_to_clocktime(pace_in_seconds) | ||
end | ||
|
||
def pace_seconds(time, distance, bigdecimal = false) | ||
check_time(time) | ||
check_distance(distance) | ||
convert_to_clocktime(convert_to_seconds(time) / distance.to_f) | ||
seconds = convert_to_seconds(time) | ||
bigdecimal ? seconds / BigDecimal(distance.to_s) : seconds / distance | ||
end | ||
|
||
def total_time(pace, distance, bigdecimal = false) | ||
total_time_in_seconds = total_time_seconds(pace, distance, bigdecimal) | ||
convert_to_clocktime(total_time_in_seconds) | ||
end | ||
|
||
def total_time(pace, distance) | ||
def total_time_seconds(pace, distance, bigdecimal = false) | ||
check_time(pace) | ||
check_distance(distance) | ||
convert_to_clocktime(convert_to_seconds(pace) * distance.to_f) | ||
pace_seconds = convert_to_seconds(pace) | ||
bigdecimal ? pace_seconds * BigDecimal(distance.to_s) : pace_seconds * distance | ||
end | ||
|
||
def distance(time, pace) | ||
def distance(time, pace, bigdecimal = false) | ||
check_time(time) | ||
check_time(pace) | ||
convert_to_seconds(time).to_f / convert_to_seconds(pace).round(2) | ||
if bigdecimal | ||
time_seconds = BigDecimal(convert_to_seconds(time).to_s) | ||
pace_seconds = BigDecimal(convert_to_seconds(pace).to_s) | ||
else | ||
time_seconds = convert_to_seconds(time) | ||
pace_seconds = convert_to_seconds(pace) | ||
end | ||
time_seconds / pace_seconds | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters