Class: Shale::Adapter::REXML::Document Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/adapter/rexml/document.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrapper around REXML API

Instance Method Summary collapse

Constructor Details

#initializeDocument

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object



13
14
15
16
17
# File 'lib/shale/adapter/rexml/document.rb', line 13

def initialize
  context = { attribute_quote: :quote, prologue_quote: :quote }
  @doc = ::REXML::Document.new(nil, context)
  @namespaces = {}
end

Instance Method Details

#add_attribute(element, name, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add attribute to REXML element

Parameters:

  • element (::REXML::Element)

    REXML element

  • name (String)

    Name of the XML attribute

  • value (String)

    Value of the XML attribute



72
73
74
# File 'lib/shale/adapter/rexml/document.rb', line 72

def add_attribute(element, name, value)
  element.add_attribute(name, value || '')
end

#add_element(element, child) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add child element to REXML element

Parameters:

  • element (::REXML::Element)

    REXML parent element

  • child (::REXML::Element)

    REXML child element



82
83
84
# File 'lib/shale/adapter/rexml/document.rb', line 82

def add_element(element, child)
  element.add_element(child)
end

#add_namespace(prefix, namespace) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add XML namespace to document

Parameters:

  • prefix (String)
  • namespace (String)


61
62
63
# File 'lib/shale/adapter/rexml/document.rb', line 61

def add_namespace(prefix, namespace)
  @namespaces[prefix] = namespace if prefix && namespace
end

#add_text(element, text) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add text node to REXML element

Parameters:

  • element (::REXML::Element)

    REXML element

  • text (String)

    Text to add



92
93
94
# File 'lib/shale/adapter/rexml/document.rb', line 92

def add_text(element, text)
  element.add_text(text)
end

#create_cdata(text, parent) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create CDATA node and add it to parent

Parameters:

  • text (String)
  • parent (::REXML::Element)


51
52
53
# File 'lib/shale/adapter/rexml/document.rb', line 51

def create_cdata(text, parent)
  ::REXML::CData.new(text, true, parent)
end

#create_element(name) ⇒ ::REXML::Element

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create REXML element

Parameters:

  • name (String)

    Name of the XML element

Returns:

  • (::REXML::Element)


41
42
43
# File 'lib/shale/adapter/rexml/document.rb', line 41

def create_element(name)
  ::REXML::Element.new(name, nil, attribute_quote: :quote)
end

#doc::REXML::Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return REXML document

Returns:

  • (::REXML::Document)


24
25
26
27
28
29
30
31
32
# File 'lib/shale/adapter/rexml/document.rb', line 24

def doc
  if @doc.root
    @namespaces.each do |prefix, namespace|
      @doc.root.add_namespace(prefix, namespace)
    end
  end

  @doc
end