Class: Glark::Criteria
- Inherits:
-
Object
- Object
- Glark::Criteria
- Includes:
- Logue::Loggable
- Defined in:
- lib/glark/util/io/filter/criteria.rb
Direct Known Subclasses
Instance Method Summary collapse
- #add(type, posneg, filter) ⇒ Object
- #find_by_class(type, posneg, cls) ⇒ Object
- #get(type, posneg) ⇒ Object
-
#initialize ⇒ Criteria
constructor
A new instance of Criteria.
- #match?(pn) ⇒ Boolean
- #skipped?(pn) ⇒ Boolean
Constructor Details
#initialize ⇒ Criteria
13 14 15 16 |
# File 'lib/glark/util/io/filter/criteria.rb', line 13 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
18 19 20 21 22 |
# File 'lib/glark/util/io/filter/criteria.rb', line 18 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
29 30 31 32 |
# File 'lib/glark/util/io/filter/criteria.rb', line 29 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
24 25 26 27 |
# File 'lib/glark/util/io/filter/criteria.rb', line 24 def get type, posneg return nil unless posneg_to_filters = @type_to_posneg[type] posneg_to_filters[posneg] end |
#match?(pn) ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/glark/util/io/filter/criteria.rb', line 38 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
34 35 36 |
# File 'lib/glark/util/io/filter/criteria.rb', line 34 def skipped? pn !match? pn end |