Module: Accessibility::PPInspector
- Included in:
- AX::Element
- Defined in:
- lib/accessibility/pp_inspector.rb
Overview
Convenience methods to use when building an #inspect
method for
AX::Element and its descendants.
The module only expects three methods in order to operate:
#attributes
returns a list of available attributes#attribute
returns the value of a given attribute#size_of
returns the size for an attribute
Instance Method Summary collapse
-
#pp_checkbox(attr) ⇒ String
Create a string that looks like a labeled check box.
-
#pp_children ⇒ String
Create a string that nicely presents the number of children that the receiver has.
-
#pp_identifier ⇒ String
Create an identifier for the receiver by using various attributes that should make it very easy to identify the element.
-
#pp_position ⇒ String
Create a string that succinctly encodes the screen coordinates of the receiver.
Instance Method Details
#pp_checkbox(attr) ⇒ String
Create a string that looks like a labeled check box. The label is the given attribute, and the check box value will be determined by the value of the attribute.
93 94 95 |
# File 'lib/accessibility/pp_inspector.rb', line 93 def pp_checkbox attr " #{attr}[#{attribute(attr) ? CHECKMARK : CROSS }]" end |
#pp_children ⇒ String
Create a string that nicely presents the number of children that the receiver has.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/accessibility/pp_inspector.rb', line 75 def pp_children child_count = size_of :children if child_count > 1 " #{child_count} children" elsif child_count == 1 ONE_CHILD else # there are some odd edge cases EMPTY_STRING end end |
#pp_identifier ⇒ String
Create an identifier for the receiver by using various attributes that should make it very easy to identify the element.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/accessibility/pp_inspector.rb', line 20 def pp_identifier # @note use, or lack of use, of #inspect is intentional for visual effect if attributes.include? :value val = attribute :value if val.kind_of? NSString return " #{val.inspect}" unless val.empty? else # we assume that nil is not a legitimate value return " value=#{val.inspect}" unless val.nil? end end if attributes.include? :title val = attribute(:title) return " #{val.inspect}" if val && !val.empty? end if attributes.include? :title_ui_element val = attribute :title_ui_element return " #{val.inspect}" if val end if attributes.include? :description val = attribute(:description).to_s return " #{val}" unless val.empty? end if attributes.include? :identifier return " id=#{attribute(:identifier)}" end # @todo should we have other fallbacks? return EMPTY_STRING end |
#pp_position ⇒ String
Create a string that succinctly encodes the screen coordinates of the receiver.
61 62 63 64 65 66 67 68 |
# File 'lib/accessibility/pp_inspector.rb', line 61 def pp_position position = attribute :position if position " (#{position.x}, #{position.y})" else EMPTY_STRING end end |