Class: REXML::CSSSelector::Adapters::PrismAdapter::PrismDOM
- Inherits:
-
Object
- Object
- REXML::CSSSelector::Adapters::PrismAdapter::PrismDOM
- Defined in:
- lib/rexml/css_selector/adapters/prism_adapter.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #attribute(name) ⇒ Object
- #children ⇒ Object
-
#initialize(node, parent: nil, document: nil, index: 0) ⇒ PrismDOM
constructor
A new instance of PrismDOM.
- #previous_sibling ⇒ Object
- #type ⇒ Object
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
#document ⇒ Object (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 |
#node ⇒ Object (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 |
#parent ⇒ Object (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 |
#children ⇒ Object
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_sibling ⇒ Object
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 |
#type ⇒ Object
19 20 21 |
# File 'lib/rexml/css_selector/adapters/prism_adapter.rb', line 19 def type @node.type.to_s.gsub(/_node$/, "") end |