Module: TimerConverter

Included in:
Timer
Defined in:
tomes/components/timer/timer_converter.rb

Instance Method Summary collapse

Instance Method Details

#calculate_current_timeVoid

Calculates the total #seconds, #minutes and #hours from the frame count.

Returns:

  • (Void)


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_timeString

Shows the time in a standard way.

Returns:

  • (String)


31
32
33
# File 'tomes/components/timer/timer_converter.rb', line 31

def formatted_time
  TIME_FORMAT % formatted_time_table
end

#formatted_time_tableHash

Shows the time in a standard format, but as a Hash.

Returns:

  • (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.

Parameters:

  • frames (Integer)

Returns:

  • (Integer)


59
60
61
# File 'tomes/components/timer/timer_converter.rb', line 59

def frames_to_seconds(frames)
  frames / ASSUMED_FRAMES_PER_SECOND
end

#full_statusHash Also known as: status

Puts the values of each attribute into a hash.

Returns:

  • (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.

Parameters:

  • seconds (Integer)

Returns:

  • (Integer)


66
67
68
# File 'tomes/components/timer/timer_converter.rb', line 66

def seconds_to_minutes(seconds)
  seconds / 60
end