Class: TaskwarriorWeb::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/taskwarrior-web/task.rb

Overview

MAIN TASK CLASS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Task

MODEL METHODS FOR INDIVIDUAL TASKS



18
19
20
21
22
# File 'lib/taskwarrior-web/task.rb', line 18

def initialize(attributes = {})
  attributes.each do |attr, value|
    send("#{attr}=", value) if respond_to?(attr.to_sym)
  end  
end

Instance Attribute Details

#annotationsObject

Returns the value of attribute annotations.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def annotations
  @annotations
end

#dependsObject

Returns the value of attribute depends.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def depends
  @depends
end

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def description
  @description
end

#dueObject

Returns the value of attribute due.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def due
  @due
end

#endObject

Returns the value of attribute end.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def end
  @end
end

#entryObject

Returns the value of attribute entry.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def entry
  @entry
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def id
  @id
end

#priorityObject

Returns the value of attribute priority.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def priority
  @priority
end

#projectObject

Returns the value of attribute project.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def project
  @project
end

#startObject

Returns the value of attribute start.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def start
  @start
end

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def status
  @status
end

#tagsObject

Returns the value of attribute tags.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def tags
  @tags
end

#uuidObject

Returns the value of attribute uuid.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def uuid
  @uuid
end

#waitObject

Returns the value of attribute wait.



10
11
12
# File 'lib/taskwarrior-web/task.rb', line 10

def wait
  @wait
end

Class Method Details

.complete!(task_id) ⇒ Object

Mark a task as complete TODO: Make into instance method when ‘task` supports finding by UUID.



107
108
109
# File 'lib/taskwarrior-web/task.rb', line 107

def self.complete!(task_id)
  TaskwarriorWeb::Runner.run("#{task_id} done")
end

.count(*args) ⇒ Object

Get the number of tasks for some paramters



90
91
92
93
94
95
96
97
98
# File 'lib/taskwarrior-web/task.rb', line 90

def self.count(*args)
  command = 'count'
  args.each do |param|
    param.each do |attr, value|
      command << " #{attr.to_s}:#{value}"
    end
  end
  return TaskwarriorWeb::Runner.run(command).strip!
end

.method_missing(method_sym, *arguments, &block) ⇒ Object

Define method_missing to implement dynamic finder methods



71
72
73
74
75
76
77
78
# File 'lib/taskwarrior-web/task.rb', line 71

def self.method_missing(method_sym, *arguments, &block)
  match = TaskDynamicFinderMatch.new(method_sym)
  if match.match? 
    self.query(match.attribute => arguments.first)
  else
    super
  end
end

.query(*args) ⇒ Object

Run queries on tasks.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/taskwarrior-web/task.rb', line 45

def self.query(*args)
  tasks = []
  count = 1
  
  command =  '_query'
  args.each do |param|
    param.each do |attr, value|
      command << " #{attr.to_s}:#{value}"
    end
  end

  # Process the JSON data.
  json = TaskwarriorWeb::Runner.run(command)
  json.strip!
  json = '[' + json + ']'
  results = json == '[No matches.]' ? [] : JSON.parse(json)

  results.each do |result|
    result[:id] = count
    tasks << Task.new(result)
    count = count + 1
  end
  return tasks
end

.respond_to?(method_sym, include_private = false) ⇒ Boolean

Implement respond_to? so that our dynamic finders are declared

Returns:

  • (Boolean)


81
82
83
84
85
86
87
# File 'lib/taskwarrior-web/task.rb', line 81

def self.respond_to?(method_sym, include_private = false)
  if TaskDynamicFinderMatch.new(method_sym).match?
    true
  else
    super
  end
end

Instance Method Details

#save!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/taskwarrior-web/task.rb', line 24

def save!
  exclude = ['@description', '@tags']
  command = 'add'
  command << " '#{description}'"
  instance_variables.each do |ivar|
    subbed = ivar.to_s.gsub('@', '')
    command << " #{subbed}:#{send(subbed.to_sym)}" unless exclude.include?(ivar.to_s)
  end
  unless tags.nil?
    tags.gsub(', ', ',').split(',').each do |tag|
      command << " +#{tag}"
    end
  end
  TaskwarriorWeb::Runner.run(command)
end