Class: Array

Inherits:
Object show all
Defined in:
lib/dooby/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#only_tags(*wanted_tags) ⇒ Object



16
17
18
19
20
# File 'lib/dooby/core_ext.rb', line 16

def only_tags(*wanted_tags)
  wanted_tags = '#' if wanted_tags.empty?
  tags = self.grep(/[#{wanted_tags}]./)
  tags.flatten
end

#only_tags!(*wanted_tags) ⇒ Object



12
13
14
# File 'lib/dooby/core_ext.rb', line 12

def only_tags!(*wanted_tags)
  replace(only_tags(wanted_tags))
end

#tasks_by_tag(*tags) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dooby/core_ext.rb', line 22

def tasks_by_tag(*tags)
  unless self.empty?
    tasks = []
    items = self.dup
    tags.each do |tag|
      matches = items.grep(/#{tag}/)
      items = items - matches
      unless matches.empty?
        separator = "\n==================== #{tag[1..-1].upcase} ====================".white_on_red
        tasks << separator unless tasks.include? separator
        tasks << matches
      end
    end
    tasks.unshift items
    tasks.flatten
  else
    nil
  end
end