Class: Cuporter::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/cuporter/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Filter

Returns a new instance of Filter.



7
8
9
10
11
# File 'lib/cuporter/filter.rb', line 7

def initialize(args = {})
  @all  = to_tag_array(args[:all]) # logical AND
  @any  = to_tag_array(args[:any]) # logical OR
  @none = to_tag_array(args[:none])# logical NOT
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



5
6
7
# File 'lib/cuporter/filter.rb', line 5

def all
  @all
end

#anyObject (readonly)

Returns the value of attribute any.



5
6
7
# File 'lib/cuporter/filter.rb', line 5

def any
  @any
end

#noneObject (readonly)

Returns the value of attribute none.



5
6
7
# File 'lib/cuporter/filter.rb', line 5

def none
  @none
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cuporter/filter.rb', line 33

def empty?
  all.empty? && any.empty? && none.empty?
end

#pass?(other_tags) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cuporter/filter.rb', line 13

def pass?(other_tags)
  pass = true

  # Logical AND: are all of the tags in :all in the tests' tags?
  unless all.empty?
    pass = false unless (other_tags & all).size == all.size
  end

  # Logical OR: are any of the tests' tags in :any?
  unless any.empty?
    pass = false if (other_tags & any).empty?
  end

  unless none.empty?
    pass = false if !(other_tags & none).empty?
  end

  pass
end