Class: ATSPI::Accessible::Descendants
- Inherits:
-
Object
- Object
- ATSPI::Accessible::Descendants
- Extended by:
- Forwardable
- Defined in:
- lib/atspi/accessible/descendants.rb,
lib/atspi/accessible/descendants/options.rb,
lib/atspi/accessible/descendants/name_filter.rb,
lib/atspi/accessible/descendants/role_filter.rb,
lib/atspi/accessible/descendants/state_filter.rb,
lib/atspi/accessible/descendants/attribute_filter.rb,
lib/atspi/accessible/descendants/interface_filter.rb
Overview
A collection of all descendants in the tree below the accessible it belongs to. It can be filtered by state, attribute, role, interface and name using #where. The number of descendants to return can be set by #limit_to. Recursive search of the tree can be turned on and off by #recursive.
All methods can be chained together:
descendants = ATSPI.applications.first.descendants
descendants.where(role: :page_tab, state: :selected).recursive(false).limit_to(1)
# => #<ATSPI::Accessible::Descendants:0x101c51014 @state=all:[:selected] @role=any:[:page_tab] @limit=1 @recursive?=false … >
To get the actual collection as an array call #to_a. Methods not defined here are automatically delegated to #to_a, so instances of this class can be directly treated like an array.
descendants.where(interface: :Action).map{ |d| d.actions.map(&:name) }
# => [["click"], [], ["click"], [], …]
In essence, it wraps libatspi’s AtspiCollection and AtspiMatchRule
Filter collapse
-
#invert(invert = true) ⇒ Descendants
Inverts the conditions set by #where.
-
#where(filters) ⇒ Descendants
A copy of this instance with the modified filters.
Options collapse
-
#limit_to(limit) ⇒ Descendants
Limits the number of descendants to return.
-
#recursive(recursive = true) ⇒ Descendants
Turns recursive search on and off.
-
#sort_by(order) ⇒ Descendants
Sorts the collection of descendants.
Access collapse
-
#method_missing(m, *args, &block) ⇒ Object
Delegates missing methods to #to_a.
-
#to_a ⇒ Array<Accessible>
The descendants according to the configured filters and options.
Selection collapse
-
#deselect_all ⇒ true, false
Tries to deselect all descendants in the collection.
-
#select_all ⇒ true, false
Tries to select all descendants in the collection.
-
#selected ⇒ Array<Accessible>
Its selected subset.
Representations collapse
-
#inspect ⇒ String
Itself as an inspectable string.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Delegates missing methods to #to_a
264 265 266 |
# File 'lib/atspi/accessible/descendants.rb', line 264 def method_missing(m, *args, &block) to_a.__send__(m, *args, &block) end |
Instance Method Details
#deselect_all ⇒ true, false
Tries to deselect all descendants in the collection
285 286 287 |
# File 'lib/atspi/accessible/descendants.rb', line 285 def deselect_all map(&:deselect).all? end |
#inspect ⇒ String
Returns itself as an inspectable string.
292 293 294 295 |
# File 'lib/atspi/accessible/descendants.rb', line 292 def inspect filter_inspect = @filters.map{ |n,f| "@#{n}=#{f.inspect}" }.join(' ') "#<#{self.class.name}:0x#{'%x14' % __id__} #{filter_inspect} #{@options.inspect}>" end |
#invert(invert = true) ⇒ Descendants
Seems to be not considered by libatspi?!
Inverts the conditions set by #where.
199 200 201 |
# File 'lib/atspi/accessible/descendants.rb', line 199 def invert(invert = true) dup(options: @options.invert(invert)) end |
#limit_to(limit) ⇒ Descendants
Limits the number of descendants to return.
229 230 231 |
# File 'lib/atspi/accessible/descendants.rb', line 229 def limit_to(limit) dup(options: @options.limit_to(limit)) end |
#recursive(recursive = true) ⇒ Descendants
Turns recursive search on and off.
244 245 246 |
# File 'lib/atspi/accessible/descendants.rb', line 244 def recursive(recursive = true) dup(options: @options.recursive(recursive)) end |
#select_all ⇒ true, false
Tries to select all descendants in the collection
278 279 280 |
# File 'lib/atspi/accessible/descendants.rb', line 278 def select_all map(&:select).all? end |
#selected ⇒ Array<Accessible>
Returns its selected subset.
271 272 273 |
# File 'lib/atspi/accessible/descendants.rb', line 271 def selected select(&:selected?) end |
#sort_by(order) ⇒ Descendants
Sorts the collection of descendants.
217 218 219 |
# File 'lib/atspi/accessible/descendants.rb', line 217 def sort_by(order) dup(options: @options.order_by(order)) end |
#to_a ⇒ Array<Accessible>
Returns the descendants according to the configured filters and options. The collection will be empty if the accessible does not implement the collection interface.
253 254 255 256 257 258 259 260 |
# File 'lib/atspi/accessible/descendants.rb', line 253 def to_a return [] unless @native.collection_iface match_rule = Libatspi::MatchRule.new(*@filters[:state], *@filters[:attributes], *@filters[:role], *@filters[:interface], @options.inverted?) matches = @native.matches(match_rule, *@options).to_a matches = matches.select{ |native| native.name =~ @filters[:name].match } if @filters[:name].match matches.map{ |native| Accessible.new(native) } end |
#where(state: ) ⇒ Descendants #where(attributes: ) ⇒ Descendants #where(role: ) ⇒ Descendants #where(interface: ) ⇒ Descendants #where(name: ) ⇒ Descendants #where(filters) ⇒ Descendants
Filtering sometimes felt rocky on libatspi’s side during testing. See the notes in the following sections for details.
Returns a copy of this instance with the modified filters.
182 183 184 185 186 187 |
# File 'lib/atspi/accessible/descendants.rb', line 182 def where(filters) dup(filters: @filters.map do |name, filter| extended_filter = filters[name] ? filter.extend(*filters[name]) : filter [name, extended_filter] end.to_h) end |