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)


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
43
# File 'lib/doing/wwid.rb', line 11

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

#matches_search?(search) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
# File 'lib/doing/wwid.rb', line 45

def matches_search?(search)
  item = self
  text = item['note'] ? item['title'] + item['note'].join(' ') : item['title']
  pattern = if search.strip =~ %r{^/.*?/$}
              search.sub(%r{/(.*?)/}, '\1')
            else
              search.split('').join('.{0,3}')
            end
  text =~ /#{pattern}/i ? true : false
end