Class: Pomo::Task

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

Direct Known Subclasses

Break, GithubTask

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, options = {}) ⇒ Task

Initialize with name and options.



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

def initialize(name = nil, options = {})
  @name = name or raise '<task> required'
  @description = options.delete :description
  @length = options.fetch :length, 25
  @running = false
  @complete = false
end

Instance Attribute Details

#completeObject

Task completion bool.



29
30
31
# File 'lib/pomo/task.rb', line 29

def complete
  @complete
end

#descriptionObject

Verbose task description.



19
20
21
# File 'lib/pomo/task.rb', line 19

def description
  @description
end

#lengthObject

Length in minutes.



14
15
16
# File 'lib/pomo/task.rb', line 14

def length
  @length
end

#nameObject

Task name.



9
10
11
# File 'lib/pomo/task.rb', line 9

def name
  @name
end

#runningObject

Task currently running bool.



24
25
26
# File 'lib/pomo/task.rb', line 24

def running
  @running
end

Instance Method Details

#complete?Boolean

Check if the task has been completed.

Returns:

  • (Boolean)


59
60
61
# File 'lib/pomo/task.rb', line 59

def complete?
  complete
end

#running?Boolean

Check if the task currently running.

Returns:

  • (Boolean)


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

def running?
  running
end

#start(config, options = {}) ⇒ Object

Start timing the task.



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pomo/task.rb', line 76

def start(config, options = {})
  list = options[:list]
  progress = options[:progress]

  @running = true
  list.save unless list.nil?

  if progress
    foreground_progress(config)
  else
    background_progress(config)
  end
end

#to_sObject

Quoted task name.



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

def to_s
  name
end

#verbose_output(format) ⇒ Object

Output verbose task information



66
67
68
69
70
71
# File 'lib/pomo/task.rb', line 66

def verbose_output(format)
  say format % ['name', self]
  say format % ['length', "#{length} minutes"]
  say format % ['description', description] if description and not description.empty?
  say format % ['complete', complete ? '[✓]' : '[ ]']
end