Class: Controller

Inherits:
SimpleConsole::Controller
  • Object
show all
Defined in:
lib/task.rb

Instance Method Summary collapse

Instance Method Details

#addObject

Modifies the elapsed time for some task. Options for this are required.



68
69
70
# File 'lib/task.rb', line 68

def add
  modify_elapsed time_join(params[:hours], params[:minutes], params[:seconds])
end

#defaultObject

Lists all tasks with their respective status and elapsed time.



26
27
28
29
30
31
# File 'lib/task.rb', line 26

def default
  redirect_to(:action => :help) if @tasks.empty?
  @list = @tasks.map do |name, task|
    [name, task, time_split(task[:elapsed]), time_split(last_elapsed(task))]
  end.sort
end

#deleteObject

Deletes the selected task.



63
64
65
# File 'lib/task.rb', line 63

def delete
  @tasks.delete(@task)
end

#helpObject

Shows the usage reference and examples.



73
74
# File 'lib/task.rb', line 73

def help
end

#infoObject

Shows elapsed time for the selected task.



34
35
36
37
38
39
40
# File 'lib/task.rb', line 34

def info
  @elapsed = last_elapsed
  @hours, @minutes, @seconds = time_split @elapsed
  @daily = task[:daily].sort.reverse.map do |day, elapsed|
    [day, time_split(elapsed)]
  end
end

#resetObject

Reverts the status to the last saved elapsed time (ignores the latest start command).



57
58
59
60
# File 'lib/task.rb', line 57

def reset
  task[:started_at] = nil
  task[:running] = false
end

#startObject

Starts the time tracking for the selected task.



43
44
45
46
47
# File 'lib/task.rb', line 43

def start
  redirect_to(:action => :info) if task[:running]
  task[:started_at] = @time
  task[:running] = true
end

#stopObject

Stops the time tracking for the selected task.



50
51
52
53
54
# File 'lib/task.rb', line 50

def stop
  return unless task[:running]
  modify_elapsed(last_elapsed)
  reset
end