Class: TaskwarriorWeb::Task
- Inherits:
-
Object
- Object
- TaskwarriorWeb::Task
- Defined in:
- lib/taskwarrior-web/task.rb
Overview
MAIN TASK CLASS
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#depends ⇒ Object
Returns the value of attribute depends.
-
#description ⇒ Object
Returns the value of attribute description.
-
#due ⇒ Object
Returns the value of attribute due.
-
#end ⇒ Object
Returns the value of attribute end.
-
#entry ⇒ Object
Returns the value of attribute entry.
-
#id ⇒ Object
Returns the value of attribute id.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#project ⇒ Object
Returns the value of attribute project.
-
#start ⇒ Object
Returns the value of attribute start.
-
#status ⇒ Object
Returns the value of attribute status.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
-
#wait ⇒ Object
Returns the value of attribute wait.
Class Method Summary collapse
-
.complete!(task_id) ⇒ Object
Mark a task as complete TODO: Make into instance method when ‘task` supports finding by UUID.
-
.count(*args) ⇒ Object
Get the number of tasks for some paramters.
-
.method_missing(method_sym, *arguments, &block) ⇒ Object
Define method_missing to implement dynamic finder methods.
-
.query(*args) ⇒ Object
Run queries on tasks.
-
.respond_to?(method_sym, include_private = false) ⇒ Boolean
Implement respond_to? so that our dynamic finders are declared.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Task
constructor
MODEL METHODS FOR INDIVIDUAL TASKS.
- #save! ⇒ Object
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
#annotations ⇒ Object
Returns the value of attribute annotations.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def annotations @annotations end |
#depends ⇒ Object
Returns the value of attribute depends.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def depends @depends end |
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def description @description end |
#due ⇒ Object
Returns the value of attribute due.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def due @due end |
#end ⇒ Object
Returns the value of attribute end.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def end @end end |
#entry ⇒ Object
Returns the value of attribute entry.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def entry @entry end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def id @id end |
#priority ⇒ Object
Returns the value of attribute priority.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def priority @priority end |
#project ⇒ Object
Returns the value of attribute project.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def project @project end |
#start ⇒ Object
Returns the value of attribute start.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def start @start end |
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def status @status end |
#tags ⇒ Object
Returns the value of attribute tags.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def @tags end |
#uuid ⇒ Object
Returns the value of attribute uuid.
10 11 12 |
# File 'lib/taskwarrior-web/task.rb', line 10 def uuid @uuid end |
#wait ⇒ Object
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
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 .nil? .gsub(', ', ',').split(',').each do |tag| command << " +#{tag}" end end TaskwarriorWeb::Runner.run(command) end |