-
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
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