Sha256: f9106ada3e37cf94ae26bee40cd8e32749f56c52be4609452ae4fa4c2d1250cc

Contents?: true

Size: 960 Bytes

Versions: 4

Compression:

Stored size: 960 Bytes

Contents

require 'nokogiri'
class Nokogiri::XML::Node
  # URI of namespace + node_name
  def uri
    ns = self.namespace ? self.namespace.href : RDF::XML.to_s
    RDF::URI.intern(ns + self.node_name)
  end

  def display_path
    @display_path ||= case self
    when Nokogiri::XML::Document then ""
    when Nokogiri::XML::Element then parent ? "#{parent.display_path}/#{name}" : name
    when Nokogiri::XML::Attr then "#{parent.display_path}@#{name}"
    end
  end
  
  alias_method :attribute_with_ns_without_ffi_null, :attribute_with_ns
  ##
  # Monkey patch attribute_with_ns, to insure nil is returned for #null?
  #
  # Get the attribute node with name and namespace
  #
  # @param [String] name
  # @param [String] namespace
  # @return [Nokogiri::XML::Attr]
  def attribute_with_ns(name, namespace)
    a = attribute_with_ns_without_ffi_null(name, namespace)
    
    (a.respond_to?(:null?) && a.null?) ? nil : a # to ensure FFI Pointer compatibility
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
rdf-rdfxml-0.3.5 lib/rdf/rdfxml/patches/nokogiri_hacks.rb
rdf-rdfxml-0.3.4 lib/rdf/rdfxml/patches/nokogiri_hacks.rb
rdf-rdfxml-0.3.3.1 lib/rdf/rdfxml/patches/nokogiri_hacks.rb
the-experimenters-rdf-rdfxml-0.3.4 lib/rdf/rdfxml/patches/nokogiri_hacks.rb