Module: RDF::TriX::Writer::Nokogiri

Defined in:
vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb

Overview

Nokogiri implementation of the TriX writer.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.librarySymbol

Returns the name of the underlying XML library.

Returns:



12
13
14
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 12

def self.library
  :nokogiri
end

Instance Method Details

#create_comment(text) ⇒ Nokogiri::XML::Comment

Creates an XML comment element with the given text.

Parameters:

Returns:

  • (Nokogiri::XML::Comment)


69
70
71
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 69

def create_comment(text)
  ::Nokogiri::XML::Comment.new(@xml, text.to_s)
end

#create_element(name, content = nil, attributes = {}) {|element| ... } ⇒ Nokogiri::XML::Element

Creates an XML element of the given name, with optional given content and attributes.

Parameters:

Yields:

  • (element)

Yield Parameters:

Returns:



83
84
85
86
87
88
89
90
91
92
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 83

def create_element(name, content = nil, attributes = {}, &block)
  element = @xml.create_element(name.to_s)
  if xmlns = attributes.delete(:xmlns)
    element.default_namespace = xmlns
  end
  attributes.each { |k, v| element[k.to_s] = v }
  element.content = content.to_s unless content.nil?
  block.call(element) if block_given?
  element
end

#create_graph(name = nil) {|element| ... } ⇒ Nokogiri::XML::Element

Creates an XML graph element with the given name.

Parameters:

Yields:

  • (element)

Yield Parameters:

Returns:



53
54
55
56
57
58
59
60
61
62
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 53

def create_graph(name = nil, &block)
  @trix << (graph = create_element(:graph))
  case name
    when nil then nil
    when RDF::Node then graph << create_element(:id, name.to_s) # non-standard
    else graph << create_element(:uri, name.to_s)
  end
  block.call(graph) if block_given?
  graph
end

#initialize_xml(options = {})

This method returns an undefined value.

Initializes the underlying XML library.

Parameters:



21
22
23
24
25
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 21

def initialize_xml(options = {})
  require 'nokogiri' unless defined?(::Nokogiri)
  @xml = ::Nokogiri::XML::Document.new
  @xml.encoding = @encoding
end

#write_epilogue

This method returns an undefined value.

Outputs the TriX document.



40
41
42
43
44
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 40

def write_epilogue
  puts @xml.to_xml
  @xml = @trix = nil
  super
end

#write_prologue

This method returns an undefined value.

Generates the TriX root element.



31
32
33
34
# File 'vendor/bundler/ruby/2.4.0/bundler/gems/rdf-trix-7d61d2cef93b/lib/rdf/trix/writer/nokogiri.rb', line 31

def write_prologue
  @xml << (@trix = create_element(:TriX, nil, :xmlns => Format::XMLNS))
  super
end