-
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.
26 rename and built in inputs checks in methods to convert distances …
…and time (#27) * 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
- Loading branch information
Showing
11 changed files
with
123 additions
and
74 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 @@ | ||
3.0.5 | ||
3.2.1 |
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
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
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,22 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Converter | ||
def to_seconds(time) | ||
check_time(time) | ||
convert_to_seconds(time) | ||
end | ||
|
||
def to_clocktime(seconds) | ||
check_integer(seconds) | ||
convert_to_clocktime(seconds) | ||
end | ||
|
||
def convert(distance, unit, round_limit = 2) | ||
check_distance(distance) | ||
check_unit(unit) | ||
check_integer(round_limit) | ||
convert_the_distance(distance, unit, round_limit) | ||
end | ||
|
||
def convert_to_seconds(time) | ||
hour, minute, seconds = time.split(':').map(&:to_i) | ||
(hour * 3600) + (minute * 60) + seconds | ||
end | ||
|
||
def convert_to_clocktime(seconds) | ||
Time.at(seconds).utc.strftime('%H:%M:%S') | ||
seconds >= 86_400 ? time = '%d %H:%M:%S' : time = '%H:%M:%S' | ||
Time.at(seconds).utc.strftime(time) | ||
end | ||
|
||
# tem que chamar as checagens de digitos antes de chamar o convert_distance | ||
def convert(distance, unit) | ||
def convert_the_distance(distance, unit, round_limit = 2) | ||
case unit | ||
when 'km' | ||
(distance * 0.621371).round(2) | ||
(distance * 0.621371).round(round_limit) | ||
when 'mi' | ||
(distance * 1.60934).round(2) | ||
(distance * 1.60934).round(round_limit) | ||
end | ||
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