Class: REXML::CSSSelector::Adapters::PrismAdapter::PrismDOM

Inherits:
Object
  • Object
show all
Defined in:
lib/rexml/css_selector/adapters/prism_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, parent: nil, document: nil, index: 0) ⇒ PrismDOM

Returns a new instance of PrismDOM.



10
11
12
13
14
15
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 10

def initialize(node, parent: nil, document: nil, index: 0)
  @node = node
  @parent = parent
  @document = document || self
  @index = index
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



17
18
19
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 17

def document
  @document
end

#nodeObject (readonly)

Returns the value of attribute node.



17
18
19
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 17

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent.



17
18
19
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 17

def parent
  @parent
end

Instance Method Details

#attribute(name) ⇒ Object



23
24
25
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 23

def attribute(name)
  @node.deconstruct_keys([])[name.intern]&.to_s
end

#childrenObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 27

def children
  @children ||=
    begin
      children = []
      @node.compact_child_nodes.each_with_index do |child, index|
        children << PrismDOM.new(child, parent: self, document:, index:)
      end
      children
    end
end

#previous_siblingObject



38
39
40
41
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 38

def previous_sibling
  return if index.zero?
  parent.children[index - 1]
end

#typeObject



19
20
21
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 19

def type
  @node.type.to_s.gsub(/_node$/, "")
end