Class: TaskWarrior::Tag
- Inherits:
-
Object
- Object
- TaskWarrior::Tag
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/taskwarrior/tag.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
- #<<(task) ⇒ Object
-
#==(other) ⇒ Object
Tags are value objects.
- #hash ⇒ Object
-
#initialize(tag_or_name, tasks = []) ⇒ Tag
constructor
A new instance of Tag.
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/taskwarrior/tag.rb', line 5 def name @name end |
#tasks ⇒ Object (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 |
#hash ⇒ Object
35 36 37 |
# File 'lib/taskwarrior/tag.rb', line 35 def hash name.hash + tasks.hash end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/taskwarrior/tag.rb', line 31 def to_s "Tag: #{name} (#{@tasks.size} tasks)" end |