Class: Glark::Criteria

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/glark/util/io/filter/criteria.rb

Direct Known Subclasses

CriteriaOpts

Instance Method Summary collapse

Constructor Details

#initializeCriteria



11
12
13
14
# File 'lib/glark/util/io/filter/criteria.rb', line 11

def initialize
  # by type (hash) => by positive/negative (hash) => filter list (array)
  @type_to_posneg = Hash.new
end

Instance Method Details

#add(type, posneg, filter) ⇒ Object



16
17
18
19
20
# File 'lib/glark/util/io/filter/criteria.rb', line 16

def add type, posneg, filter
  posneg_to_filters = (@type_to_posneg[type] ||= Hash.new)
  filters = (posneg_to_filters[posneg] ||= Array.new)
  filters << filter
end

#find_by_class(type, posneg, cls) ⇒ Object



27
28
29
30
# File 'lib/glark/util/io/filter/criteria.rb', line 27

def find_by_class type, posneg, cls
  return unless filters = get(type, posneg)
  filters.detect { |filter| filter.kind_of? cls }
end

#get(type, posneg) ⇒ Object



22
23
24
25
# File 'lib/glark/util/io/filter/criteria.rb', line 22

def get type, posneg
  return nil unless posneg_to_filters = @type_to_posneg[type]
  posneg_to_filters[posneg]
end

#match?(pn) ⇒ Boolean



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/glark/util/io/filter/criteria.rb', line 36

def match? pn
  @type_to_posneg.values.each do |typefilters|
    if (posf = typefilters[:positive]) && !posf.empty?
      return false unless posf.detect { |fl| fl.match? pn }
    end

    if (negf = typefilters[:negative]) && !negf.empty?
      return false if negf.detect { |fl| fl.match? pn }
    end
  end
  true
end

#skipped?(pn) ⇒ Boolean



32
33
34
# File 'lib/glark/util/io/filter/criteria.rb', line 32

def skipped? pn
  !match? pn
end