Class: Accessibility::Qualifier
- Inherits:
-
Object
- Object
- Accessibility::Qualifier
- Defined in:
- lib/accessibility/qualifier.rb
Overview
Used in searches to answer whether or not a given element meets the expected criteria.
Instance Method Summary collapse
-
#describe ⇒ String
Return a compact description of the qualifier.
-
#initialize(klass, criteria) { ... } ⇒ Qualifier
constructor
Initialize a qualifier with the kind of object that you want to qualify and a dictionary of filter criteria.
-
#qualifies?(element) ⇒ Boolean
Whether or not a candidate object matches the criteria given at initialization.
Constructor Details
#initialize(klass, criteria) { ... } ⇒ Qualifier
Initialize a qualifier with the kind of object that you want to qualify and a dictionary of filter criteria. You can optionally pass a block if your qualification criteria is too complicated for key/value pairs; the blocks return value will be used to determine if an element qualifies.
30 31 32 33 34 35 |
# File 'lib/accessibility/qualifier.rb', line 30 def initialize klass, criteria @klass = TRANSLATOR.classify(klass) @criteria = criteria @block = Proc.new if block_given? compile! end |
Instance Method Details
#describe ⇒ String
Return a compact description of the qualifier. If the qualifier includes a block then a checkmarked box will be included.
51 52 53 |
# File 'lib/accessibility/qualifier.rb', line 51 def describe "#{@klass}#{@criteria.ax_pp}#{@block ? '[✔]' : ''}" end |
#qualifies?(element) ⇒ Boolean
Whether or not a candidate object matches the criteria given at initialization.
42 43 44 |
# File 'lib/accessibility/qualifier.rb', line 42 def qualifies? element the_right_type?(element) && meets_criteria?(element) end |