Module: TimerConverter
- Included in:
- Timer
- Defined in:
- tomes/components/timer/timer_converter.rb
Instance Method Summary collapse
-
#calculate_current_time ⇒ Void
Calculates the total #seconds, #minutes and #hours from the frame count.
-
#formatted_time ⇒ String
Shows the time in a standard way.
-
#formatted_time_table ⇒ Hash
Shows the time in a standard format, but as a Hash.
-
#frames_to_seconds(frames) ⇒ Integer
Converts a given amount of frames to seconds.
-
#full_status ⇒ Hash
(also: #status)
Puts the values of each attribute into a hash.
-
#seconds_to_minutes(seconds) ⇒ Integer
(also: #minutes_to_hours)
Divides a given number by 60.
Instance Method Details
#calculate_current_time ⇒ Void
Calculates the total #seconds, #minutes and #hours from the frame count.
49 50 51 52 53 |
# File 'tomes/components/timer/timer_converter.rb', line 49 def calculate_current_time self.seconds = frames_to_seconds(frames) self.minutes = seconds_to_minutes(seconds) self.hours = minutes_to_hours(minutes) end |
#formatted_time ⇒ String
Shows the time in a standard way.
31 32 33 |
# File 'tomes/components/timer/timer_converter.rb', line 31 def formatted_time TIME_FORMAT % formatted_time_table end |
#formatted_time_table ⇒ Hash
Shows the time in a standard format, but as a Hash.
37 38 39 40 41 42 43 44 45 |
# File 'tomes/components/timer/timer_converter.rb', line 37 def formatted_time_table calculate_current_time { frames: frames % 60, seconds: seconds % 60, minutes: minutes % 60, hours: hours } end |
#frames_to_seconds(frames) ⇒ Integer
Note:
This method returns an Integer.
Converts a given amount of frames to seconds.
59 60 61 |
# File 'tomes/components/timer/timer_converter.rb', line 59 def frames_to_seconds(frames) frames / ASSUMED_FRAMES_PER_SECOND end |
#full_status ⇒ Hash Also known as: status
Puts the values of each attribute into a hash.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'tomes/components/timer/timer_converter.rb', line 15 def full_status calculate_current_time { name: name, frames: frames, seconds: seconds.round(2), minutes: minutes.round(2), hours: hours.floor, on: on, state: state } end |
#seconds_to_minutes(seconds) ⇒ Integer Also known as: minutes_to_hours
Divides a given number by 60. This function also doubles as a minutes-to-hours converter.
66 67 68 |
# File 'tomes/components/timer/timer_converter.rb', line 66 def seconds_to_minutes(seconds) seconds / 60 end |