Class: TaskwarriorWeb::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/taskwarrior-web/model/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



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

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

  @_errors = []
  @tags = [] if @tags.nil?
end

Instance Attribute Details

#_errorsObject

Returns the value of attribute _errors.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def _errors
  @_errors
end

#annotationsObject

Returns the value of attribute annotations.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def annotations
  @annotations
end

#dependsObject

Returns the value of attribute depends.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def depends
  @depends
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def description
  @description
end

#dueObject

Returns the value of attribute due.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def due
  @due
end

#endObject

Returns the value of attribute end.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def end
  @end
end

#entryObject

Returns the value of attribute entry.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def entry
  @entry
end

#priorityObject

Returns the value of attribute priority.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def priority
  @priority
end

#projectObject

Returns the value of attribute project.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def project
  @project
end

#startObject

Returns the value of attribute start.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def start
  @start
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def status
  @status
end

#tagsObject

Returns the value of attribute tags.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def tags
  @tags
end

#uuidObject

Returns the value of attribute uuid.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def uuid
  @uuid
end

#waitObject

Returns the value of attribute wait.



8
9
10
# File 'lib/taskwarrior-web/model/task.rb', line 8

def wait
  @wait
end

Class Method Details

.count(*args) ⇒ Object

Get the number of tasks for some paramters



61
62
63
# File 'lib/taskwarrior-web/model/task.rb', line 61

def self.count(*args)
  self.query(*args).count
end

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

Define method_missing to implement dynamic finder methods



66
67
68
69
70
71
72
73
# File 'lib/taskwarrior-web/model/task.rb', line 66

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

.query(*args) ⇒ Object

Run queries on tasks.



53
54
55
56
57
58
# File 'lib/taskwarrior-web/model/task.rb', line 53

def self.query(*args)
  tasks = []
  results = Command.new(:query, nil, *args).run
  Parser.parse(results).each { |result| tasks << Task.new(result) }
  tasks
end

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

Implement respond_to? so that our dynamic finders are declared

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'lib/taskwarrior-web/model/task.rb', line 76

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

Instance Method Details

#complete!Object



30
31
32
# File 'lib/taskwarrior-web/model/task.rb', line 30

def complete!
  Command.new(:complete, self.uuid).run
end

#is_valid?Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/taskwarrior-web/model/task.rb', line 39

def is_valid?
  @_errors << 'You must provide a description' if self.description.blank?
  @_errors.empty?
end

#save!Object



26
27
28
# File 'lib/taskwarrior-web/model/task.rb', line 26

def save!
  Command.new(:add, nil, self.to_hash).run
end

#to_hashObject



44
45
46
# File 'lib/taskwarrior-web/model/task.rb', line 44

def to_hash
  Hash[instance_variables.select { |var| !var.to_s.start_with?('@_') }.map { |var| [var[1..-1].to_sym, instance_variable_get(var)] }]
end