Class: RDF::Literal::XML

Inherits:
RDF::Literal show all
Defined in:
lib/rdf/rdfxml/patches/literal_hacks.rb

Overview

An XML literal.

Instance Method Summary collapse

Constructor Details

#initialize(value, options = {}) ⇒ XML

Returns a new instance of XML.

Parameters:

  • value (Object)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :lexical (String) — default: nil
  • :namespaces (Hash) — default: {}

    Use “” to declare default namespace

  • :language (Symbol) — default: nil
  • :library (:nokogiri, :libxml, or :rexml)

Since:

  • 0.2.1



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rdf/rdfxml/patches/literal_hacks.rb', line 26

def initialize(value, options = {})
  options[:namespaces] ||= {}

  @library = case options[:library]
    when nil
      case
      when defined?(::Nokogiri) then :nokogiri
      when defined?(::LibXML)   then :libxml
      else                           :rexml
      end
    when :nokogiri, :libxml, :rexml
      options[:library]
    else
      raise ArgumentError.new("expected :rexml, :libxml or :nokogiri, but got #{options[:library].inspect}")
  end

  @datatype = options[:datatype] || DATATYPE
  @string   = options[:lexical] if options.has_key?(:lexical)
  @object   = parse_value(value, options)
  @string   = serialize_nodeset(@object)
end

Instance Method Details

#canonicalizeLiteral

Converts the literal into its canonical lexical representation.

Returns:

See Also:

Since:

  • 0.2.1



53
54
55
56
# File 'lib/rdf/rdfxml/patches/literal_hacks.rb', line 53

def canonicalize
  # This is the opportunity to use exclusive canonicalization library
  self
end

#to_sString

Returns the value as a string.

Returns:

  • (String)

Since:

  • 0.2.1



62
63
64
# File 'lib/rdf/rdfxml/patches/literal_hacks.rb', line 62

def to_s
  @string
end