Class: Accessibility::Qualifier

Inherits:
Object
  • Object
show all
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

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.

Examples:


Accessibility::Qualifier.new(:standard_window, title: 'Test')
Accessibility::Qualifier.new(:buttons, {})
Accessibility::Qualifier.new(:Table, { row: { title: /Price/ } })
Accessibility::Qualifier.new(:element) do |element|
  element.children.size > 5 && NSContainsRect(element.bounds, rect)
end

Parameters:

  • klass (#to_s)
  • criteria (Hash)

Yields:

  • Optional block that can qualify an element



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

#describeString

Return a compact description of the qualifier. If the qualifier includes a block then a checkmarked box will be included.

Returns:

  • (String)


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.

Parameters:

Returns:

  • (Boolean)


42
43
44
# File 'lib/accessibility/qualifier.rb', line 42

def qualifies? element
  the_right_type?(element) && meets_criteria?(element)
end