Class: TaskWarrior::Task

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Attributes, Validations
Defined in:
lib/taskwarrior/task.rb

Instance Method Summary collapse

Methods included from Validations

#entry_cannot_be_in_the_future, #must_be_date_or_nil

Methods included from Attributes

included

Constructor Details

#initialize(description) ⇒ Task

Returns a new instance of Task.



38
39
40
41
42
43
44
45
46
47
# File 'lib/taskwarrior/task.rb', line 38

def initialize(description)
  @description = description
  @dependencies = []
  @children = []
  @tags = []
  @annotations = []

  # http://www.ruby-forum.com/topic/164078#722181
  @uuid = %x[uuidgen].strip
end

Instance Method Details

#==(other) ⇒ Object

Tasks are entity objects. They have their identity defined by the uuid. If the uuids are the same, the tasks are identical.



66
67
68
69
# File 'lib/taskwarrior/task.rb', line 66

def ==(other)
  return false unless other.is_a?(Task)
  uuid == other.uuid
end

#eql?(other) ⇒ Boolean

other may have the same uuid, but if its attributes differ, it will not be equal

Returns:

  • (Boolean)


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

def eql?(other)
  self.class.attributes.each do |attr|
    return false unless send(attr).eql?(other.send(attr))
  end
end

#hashObject



60
61
62
# File 'lib/taskwarrior/task.rb', line 60

def hash
  uuid.hash
end

#to_sObject



49
50
51
# File 'lib/taskwarrior/task.rb', line 49

def to_s
  "Task '#{description}'".tap{|result| result << " <#{uuid}>" if uuid}
end