Class: REXML::CSSSelector::BaseAdapter
- Inherits:
-
Object
- Object
- REXML::CSSSelector::BaseAdapter
- Defined in:
- lib/rexml/css_selector/base_adapter.rb
Overview
BaseAdapter is a base class of adapters.
An adapter is an abstraction of tree traversal operations for CSS selectors. We need to implement the following methods minimally:
-
element?(node) -
get_tag_name(element) -
get_attribute(element, name, namespace = nil, attribute_name_case = :sensitive) -
get_document_node(element) -
get_parent_node(element) -
get_previous_sibling_node(element) -
each_child_element(element, &)
Direct Known Subclasses
Instance Method Summary collapse
-
#checked?(element) ⇒ Boolean
Checks whether
elementis checked. -
#disabled?(element) ⇒ Boolean
Checks whether
elementis disabled. -
#each_recursive_element(element) ⇒ Object
Enumerates the elements in
element. -
#empty?(element) ⇒ Boolean
Checks whether
elementis empty. -
#get_children_elements(element) ⇒ Object
Returns an array of children elements of
element. -
#get_class_names(element) ⇒ Object
Returns class names of
element. -
#get_element_index(parent, element) ⇒ Object
Returns the index of
elementin the children ofparent. -
#get_id(element) ⇒ Object
Returns the ID name of
element. -
#get_namespace(_element) ⇒ Object
Returns a namespace of
element. -
#root?(element) ⇒ Boolean
Checks whether
elementis the root element.
Instance Method Details
#checked?(element) ⇒ Boolean
Checks whether element is checked.
This method is used for :checked.
36 37 38 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 36 def checked?(element) !!get_attribute(element, "checked") end |
#disabled?(element) ⇒ Boolean
Checks whether element is disabled.
This method is used for :disabled.
43 44 45 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 43 def disabled?(element) !!get_attribute(element, "disabled") end |
#each_recursive_element(element) ⇒ Object
Enumerates the elements in element
80 81 82 83 84 85 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 80 def each_recursive_element(element, &) each_child_element(element) do |child| yield child each_recursive_element(child, &) end end |
#empty?(element) ⇒ Boolean
Checks whether element is empty.
This method is used for :empty.
28 29 30 31 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 28 def empty?(element) each_child_element(element) { return false } true end |
#get_children_elements(element) ⇒ Object
Returns an array of children elements of element.
53 54 55 56 57 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 53 def get_children_elements(element) elements = [] each_child_element(element) { elements << _1 } elements end |
#get_class_names(element) ⇒ Object
Returns class names of element.
70 71 72 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 70 def get_class_names(element) get_attribute(element, "class")&.split(/\s+/) || [] end |
#get_element_index(parent, element) ⇒ Object
Returns the index of element in the children of parent.
60 61 62 63 64 65 66 67 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 60 def get_element_index(parent, element) i = 0 each_child_element(parent) do |child| return i if element == child i += 1 end nil end |
#get_id(element) ⇒ Object
Returns the ID name of element.
75 76 77 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 75 def get_id(element) get_attribute(element, "id") end |
#get_namespace(_element) ⇒ Object
Returns a namespace of element.
48 49 50 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 48 def get_namespace(_element) nil end |
#root?(element) ⇒ Boolean
Checks whether element is the root element.
This method is used for :root.
21 22 23 |
# File 'lib/rexml/css_selector/base_adapter.rb', line 21 def root?(element) get_parent_node(element) == get_document_node(element) end |