Class: TaskWarrior::Tag

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_or_name, tasks = []) ⇒ Tag

Returns a new instance of Tag.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/taskwarrior/tag.rb', line 11

def initialize(tag_or_name, tasks = [])
  if tag_or_name.respond_to?(:name)
    @name = tag_or_name.name
    @tasks = tag_or_name.tasks
  else
    @name = tag_or_name
    @tasks = []
  end

  tasks.each do |task|
    self << task
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/taskwarrior/tag.rb', line 5

def name
  @name
end

#tasksObject (readonly)

Returns the value of attribute tasks.



29
30
31
# File 'lib/taskwarrior/tag.rb', line 29

def tasks
  @tasks
end

Instance Method Details

#<<(task) ⇒ Object



25
26
27
# File 'lib/taskwarrior/tag.rb', line 25

def <<(task)
  @tasks << task unless @tasks.include?(task)
end

#==(other) ⇒ Object

Tags are value objects. They have no identity. If name and tasks are the same, the tags are identical.



41
42
43
44
# File 'lib/taskwarrior/tag.rb', line 41

def ==(other)
  return false unless other.is_a?(Tag)
  name.eql?(other.name) && tasks.eql?(other.tasks)
end

#hashObject



35
36
37
# File 'lib/taskwarrior/tag.rb', line 35

def hash
  name.hash + tasks.hash
end

#to_sObject



31
32
33
# File 'lib/taskwarrior/tag.rb', line 31

def to_s
  "Tag: #{name} (#{@tasks.size} tasks)"
end