Module: Converter
- Included in:
- Calcpace
- Defined in:
- lib/calcpace/converter.rb
Instance Method Summary collapse
- #convert(distance, unit, round_limit = 2) ⇒ Object
- #convert_the_distance(distance, unit, round_limit = 2) ⇒ Object
- #convert_to_clocktime(seconds) ⇒ Object
- #convert_to_seconds(time) ⇒ Object
- #to_clocktime(seconds) ⇒ Object
- #to_seconds(time) ⇒ Object
Instance Method Details
#convert(distance, unit, round_limit = 2) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/calcpace/converter.rb', line 14 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 |
#convert_the_distance(distance, unit, round_limit = 2) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/calcpace/converter.rb', line 31 def convert_the_distance(distance, unit, round_limit = 2) case unit when 'km' (distance * 0.621371).round(round_limit) when 'mi' (distance * 1.60934).round(round_limit) end end |
#convert_to_clocktime(seconds) ⇒ Object
26 27 28 29 |
# File 'lib/calcpace/converter.rb', line 26 def convert_to_clocktime(seconds) seconds >= 86_400 ? time = '%d %H:%M:%S' : time = '%H:%M:%S' Time.at(seconds).utc.strftime(time) end |
#convert_to_seconds(time) ⇒ Object
21 22 23 24 |
# File 'lib/calcpace/converter.rb', line 21 def convert_to_seconds(time) hour, minute, seconds = time.split(':').map(&:to_i) (hour * 3600) + (minute * 60) + seconds end |
#to_clocktime(seconds) ⇒ Object
9 10 11 12 |
# File 'lib/calcpace/converter.rb', line 9 def to_clocktime(seconds) check_integer(seconds) convert_to_clocktime(seconds) end |
#to_seconds(time) ⇒ Object
4 5 6 7 |
# File 'lib/calcpace/converter.rb', line 4 def to_seconds(time) check_time(time) convert_to_seconds(time) end |