Sha256: 014fef564d6b672f79b50bceffdc024255198d5ffb29e70229e199cffbfaea80

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

# @private
module Nokogiri
  module XML

    # Nokogiri::Node extensions
    class Node
      # Alias #name to #element_name so we can use #name in an XMPP Stanza context
      alias_method :element_name, :name
      alias_method :element_name=, :name=

      alias_method :attr_set, :[]=
      # Override Nokogiri's attribute setter to add the ability to kill an attribute
      # by setting it to nil and to be able to lookup an attribute by symbol
      #
      # @param [#to_s] name the name of the attribute
      # @param [#to_s, nil] value the new value or nil to remove it
      def []=(name, value)
        name = name.to_s
        if value.nil?
          remove_attribute name
        else
          value = value.is_a?(Array) ? value.join : value
          attr_set name, value.to_s
        end
      end

      alias_method :nokogiri_xpath, :xpath
      # Override Nokogiri's #xpath method to add the ability to use symbols for lookup
      # and namespace designation
      def xpath(*paths)
        paths[0] = paths[0].to_s

        if paths.size > 1 && (namespaces = paths.pop).is_a?(Hash)
          paths << namespaces.inject({}) { |h,v| h[v[0].to_s] = v[1]; h }
        end

        nokogiri_xpath *paths
      end
      alias_method :find, :xpath

      # Return the first element at a specified xpath
      # @see #xpath
      def find_first(*paths)
        xpath(*paths).first
      end
    end

  end # XML
end # Nokogiri

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
niceogiri-1.1.2 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-1.1.1 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-1.1.0 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-1.0.2 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-1.0.1 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-1.0.0 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-0.1.1 lib/niceogiri/core_ext/nokogiri.rb
niceogiri-0.1.0 lib/niceogiri/core_ext/nokogiri.rb