Class: Seconds

Inherits:
Object show all
Defined in:
lib/roebe/time/seconds.rb

Overview

#

Note that this is deliberately defined on the toplevel Object, rather than within the Roebe “namespace”.

This class will convert 27216 into:

27216 seconds are 7 hours, 33 minutes and 36 seconds.
#

Instance Method Summary collapse

Constructor Details

#initialize(i, run_already = true) ⇒ Seconds

#

initialize

#


20
21
22
23
24
25
26
# File 'lib/roebe/time/seconds.rb', line 20

def initialize(
    i, run_already = true
  )
  reset
  set_n_seconds(i)
  run if run_already
end

Instance Method Details

#convert_the_dataObject

#

convert_the_data

#


49
50
51
52
53
54
55
# File 'lib/roebe/time/seconds.rb', line 49

def convert_the_data
  @n_minutes = @n_seconds / 60
  @n_hours   = @n_minutes / 60

  @n_remaining_minutes = @n_minutes - (@n_hours * 60)
  @n_remaining_seconds = @n_seconds - (@n_minutes * 60)
end

#report_our_findingsObject Also known as: report

#

report_our_findings

#


60
61
62
63
64
65
# File 'lib/roebe/time/seconds.rb', line 60

def report_our_findings
  e @n_seconds.to_s+' seconds are '+
    @n_hours.to_s+' hours, '+
    @n_remaining_minutes.to_s+' minutes and '+
    @n_remaining_seconds.to_s+' seconds.'
end

#resetObject

#

reset

#


39
40
41
42
43
44
# File 'lib/roebe/time/seconds.rb', line 39

def reset
  # ======================================================================= #
  # === @n_seconds
  # ======================================================================= #
  @n_seconds = 0 # This is the initial value.
end

#runObject

#

run

#


70
71
72
73
# File 'lib/roebe/time/seconds.rb', line 70

def run
  convert_the_data
  report_our_findings
end

#set_n_seconds(i) ⇒ Object

#

set_n_seconds

#


31
32
33
34
# File 'lib/roebe/time/seconds.rb', line 31

def set_n_seconds(i)
  i = i.first if i.is_a? Array
  @n_seconds = i.to_i
end