Class: Timert::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/timert/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(today) ⇒ Timer

Returns a new instance of Timer.



5
6
7
# File 'lib/timert/timer.rb', line 5

def initialize(today)
  @today = today
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/timert/timer.rb', line 3

def path
  @path
end

#todayObject (readonly)

Returns the value of attribute today.



3
4
5
# File 'lib/timert/timer.rb', line 3

def today
  @today
end

Instance Method Details

#add_task(task) ⇒ Object



25
26
27
# File 'lib/timert/timer.rb', line 25

def add_task(task)
  today.add_task(task)
end

#start(time = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/timert/timer.rb', line 9

def start(time = nil)
  if !on?
    started = true
    today.add_start(time || now)
  end
  {time: today.last_start, started: started}
end

#stop(time = nil) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/timert/timer.rb', line 17

def stop(time = nil)
  if on?
    stopped = true
    today.add_stop(time || now)
  end
  {time: today.last_stop, stopped: stopped}
end