Class: Dommy::Internal::AccessibilityTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/dommy/internal/accessibility_tree.rb

Overview

One accessible object. A :text node carries its string in name and has no children — it is significant text not folded into an ancestor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, name: "", description: "", states: {}, element: nil) ⇒ Node

Returns a new instance of Node.



23
24
25
26
27
28
29
30
# File 'lib/dommy/internal/accessibility_tree.rb', line 23

def initialize(role:, name: "", description: "", states: {}, element: nil)
  @role = role
  @name = name
  @description = description
  @states = states
  @element = element
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



21
22
23
# File 'lib/dommy/internal/accessibility_tree.rb', line 21

def children
  @children
end

#descriptionObject (readonly)

Returns the value of attribute description.



20
21
22
# File 'lib/dommy/internal/accessibility_tree.rb', line 20

def description
  @description
end

#elementObject (readonly)

Returns the value of attribute element.



20
21
22
# File 'lib/dommy/internal/accessibility_tree.rb', line 20

def element
  @element
end

#nameObject (readonly)

Returns the value of attribute name.



20
21
22
# File 'lib/dommy/internal/accessibility_tree.rb', line 20

def name
  @name
end

#roleObject (readonly)

Returns the value of attribute role.



20
21
22
# File 'lib/dommy/internal/accessibility_tree.rb', line 20

def role
  @role
end

#statesObject (readonly)

Returns the value of attribute states.



20
21
22
# File 'lib/dommy/internal/accessibility_tree.rb', line 20

def states
  @states
end

Instance Method Details

#levelObject

The heading level (or any leveled role) lives in states.



34
# File 'lib/dommy/internal/accessibility_tree.rb', line 34

def level = states[:level]

#text?Boolean

Returns:

  • (Boolean)


32
33
# File 'lib/dommy/internal/accessibility_tree.rb', line 32

def text? = role == :text
# The heading level (or any leveled role) lives in `states`.

#to_hObject



36
37
38
39
40
41
42
43
# File 'lib/dommy/internal/accessibility_tree.rb', line 36

def to_h
  hash = {role: role}
  hash[:name] = name unless name.to_s.empty?
  hash[:description] = description unless description.to_s.empty?
  hash[:states] = states unless states.empty?
  hash[:children] = children.map(&:to_h) unless children.empty?
  hash
end