Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/doing/wwid.rb

Instance Method Summary collapse

Instance Method Details

#has_tags?(tags, bool = 'AND') ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/doing/wwid.rb', line 10

def has_tags?(tags, bool = 'AND')
  tags = tags.split(/ *, */) if tags.is_a? String
  item = self
  case bool
  when 'AND'
    result = true
    tags.each do |tag|
      unless item['title'] =~ /@#{tag}/
        result = false
        break
      end
    end
    result
  when 'NOT'
    result = true
    tags.each do |tag|
      if item['title'] =~ /@#{tag}/
        result = false
        break
      end
    end
    result
  else
    result = false
    tags.each do |tag|
      if item['title'] =~ /@#{tag}/
        result = true
        break
      end
    end
    result
  end
end