class Nokogiri::XML::Node

def deconstruct_keys(keys)


Since v1.14.0

# })]}
# value = "def"
# }),
# href = "http://nokogiri.org/ns/noko"
# prefix = "noko",
# namespace = #(Namespace:0x398 {
# name = "bar",
# #(Attr:0x384 {
# [#(Attr:0x370 { name = "foo", value = "abc" }),
# => {:attributes=>
doc.root.elements.first.deconstruct_keys([:attributes])

# " Second\n"}
# " First\n" +
# "\n" +
# :inner_html=>
# => {:content=>"\n" + " First\n" + " Second\n",
doc.root.deconstruct_keys([:inner_html, :content])

# #(Namespace:0x35c { href = "http://nokogiri.org/ns/default" })}
# :namespace=>
# => {:name=>"parent",
doc.root.deconstruct_keys([:name, :namespace])

XML

Second
First


doc = Nokogiri::XML.parse(<<~XML)

*Example*

- +inner_html+ → (String) The inner markup for the children of this node. See #inner_html.
- +content+ → (String) The contents of all the text nodes in this node's subtree. See #content.
- +elements+ → (Array) The child elements of this node. 💡 Note this does not include text nodes.
- +children+ → (Array) The children of this node. 💡 Note this includes text nodes.
- +attributes+ → (Array) The attributes of this node.
- +namespace+ → (Namespace, nil) The namespace of this node, or nil if there is no namespace.
- +name+ → (String) The name of this node, or "text" if it is a Text node.
Valid keys and their values:

Returns a hash describing the Node, to use in pattern matching.

:call-seq: deconstruct_keys(array_of_names) → Hash
def deconstruct_keys(keys)
  requested_keys = DECONSTRUCT_KEYS & keys
  {}.tap do |values|
    requested_keys.each do |key|
      method = DECONSTRUCT_METHODS[key] || key
      values[key] = send(method)
    end
  end
end