Sha256: 4f552254336999edc5114c1a7d5329a9a1db65680951379781173916427ae7ad

Contents?: true

Size: 1.72 KB

Versions: 95

Compression:

Stored size: 1.72 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module Nokogiri
  module XML
    class Namespace
      include Nokogiri::XML::PP::Node
      attr_reader :document

      #
      #  :call-seq: deconstruct_keys(array_of_names) → Hash
      #
      #  Returns a hash describing the Namespace, to use in pattern matching.
      #
      #  Valid keys and their values:
      #  - +prefix+ → (String, nil) The namespace's prefix, or +nil+ if there is no prefix (e.g., default namespace).
      #  - +href+ → (String) The namespace's URI
      #
      #  *Example*
      #
      #    doc = Nokogiri::XML.parse(<<~XML)
      #      <?xml version="1.0"?>
      #      <root xmlns="http://nokogiri.org/ns/default" xmlns:noko="http://nokogiri.org/ns/noko">
      #        <child1 foo="abc" noko:bar="def"/>
      #        <noko:child2 foo="qwe" noko:bar="rty"/>
      #      </root>
      #    XML
      #
      #    doc.root.elements.first.namespace
      #    # => #(Namespace:0x35c { href = "http://nokogiri.org/ns/default" })
      #
      #    doc.root.elements.first.namespace.deconstruct_keys([:prefix, :href])
      #    # => {:prefix=>nil, :href=>"http://nokogiri.org/ns/default"}
      #
      #    doc.root.elements.last.namespace
      #    # => #(Namespace:0x370 {
      #    #      prefix = "noko",
      #    #      href = "http://nokogiri.org/ns/noko"
      #    #      })
      #
      #    doc.root.elements.last.namespace.deconstruct_keys([:prefix, :href])
      #    # => {:prefix=>"noko", :href=>"http://nokogiri.org/ns/noko"}
      #
      #  Since v1.14.0
      #
      def deconstruct_keys(keys)
        { prefix: prefix, href: href }
      end

      private

      def inspect_attributes
        [:prefix, :href]
      end
    end
  end
end

Version data entries

95 entries across 95 versions & 6 rubygems

Version Path
nokogiri-1.16.7 lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x86_64-linux lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x86_64-darwin lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x86-mingw32 lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x86-linux lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x64-mingw32 lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-x64-mingw-ucrt lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-java lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-arm64-darwin lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-arm-linux lib/nokogiri/xml/namespace.rb
nokogiri-1.16.7-aarch64-linux lib/nokogiri/xml/namespace.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/nokogiri-1.16.6-arm64-darwin/lib/nokogiri/xml/namespace.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/xml/namespace.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/xml/namespace.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/nokogiri-1.16.5-x86_64-linux/lib/nokogiri/xml/namespace.rb
nokogiri-1.16.6 lib/nokogiri/xml/namespace.rb
nokogiri-1.16.6-x86_64-linux lib/nokogiri/xml/namespace.rb
nokogiri-1.16.6-x86_64-darwin lib/nokogiri/xml/namespace.rb
nokogiri-1.16.6-x86-mingw32 lib/nokogiri/xml/namespace.rb
nokogiri-1.16.6-x86-linux lib/nokogiri/xml/namespace.rb