Class: Converter
- Inherits:
-
Object
- Object
- Converter
- Defined in:
- lib/converter.rb
Constant Summary collapse
- SecondsPerHour =
3600
- SecondsPerMinute =
60
Instance Method Summary collapse
- #hours_to_seconds(hours) ⇒ Object
- #minutes_to_seconds(minutes) ⇒ Object
- #mps_to_mph(mps) ⇒ Object
- #string_to_seconds(time_string) ⇒ Object
Instance Method Details
#hours_to_seconds(hours) ⇒ Object
5 6 7 |
# File 'lib/converter.rb', line 5 def hours_to_seconds(hours) hours * SecondsPerHour end |
#minutes_to_seconds(minutes) ⇒ Object
9 10 11 |
# File 'lib/converter.rb', line 9 def minutes_to_seconds(minutes) minutes * SecondsPerMinute end |
#mps_to_mph(mps) ⇒ Object
13 14 15 |
# File 'lib/converter.rb', line 13 def mps_to_mph(mps) mps * SecondsPerHour end |
#string_to_seconds(time_string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/converter.rb', line 17 def string_to_seconds(time_string) pace_times = time_string.split(':').map{|string| string.to_i} converter = Converter.new if pace_times.size == 3 @total_pace_in_seconds = converter.hours_to_seconds(pace_times[0]) + converter.minutes_to_seconds(pace_times[1]) + pace_times[2] elsif pace_times.size == 2 @total_pace_in_seconds = converter.minutes_to_seconds(pace_times[0]) + pace_times[1] else @total_pace_in_seconds = pace_times[0] end end |