Class: Oga::XML::XmlDeclaration

Inherits:
ProcessingInstruction show all
Defined in:
lib/oga/xml/xml_declaration.rb

Overview

Class containing information about an XML declaration tag.

Instance Attribute Summary collapse

Attributes inherited from ProcessingInstruction

#name

Attributes inherited from CharacterNode

#text

Attributes inherited from Node

#next, #node_set, #previous

Instance Method Summary collapse

Methods inherited from Node

#after, #before, #children, #children=, #each_ancestor, #html?, #next_element, #parent, #previous_element, #remove, #replace, #root_node, #xml?

Methods included from ToXML

#to_xml

Methods included from Traversal

#each_node

Constructor Details

#initialize(options = {}) ⇒ XmlDeclaration

Returns a new instance of XmlDeclaration

Parameters:

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

Options Hash (options):

  • :version (String)
  • :encoding (String)
  • :standalone (String)


20
21
22
23
24
25
26
27
# File 'lib/oga/xml/xml_declaration.rb', line 20

def initialize(options = {})
  super

  @version    = options[:version] || '1.0'
  @encoding   = options[:encoding] || 'UTF-8'
  @standalone = options[:standalone]
  @name       = 'xml'
end

Instance Attribute Details

#encodingString

Returns:

  • (String)


9
10
11
# File 'lib/oga/xml/xml_declaration.rb', line 9

def encoding
  @encoding
end

#standaloneString

Whether or not the document is a standalone document.

Returns:

  • (String)


13
14
15
# File 'lib/oga/xml/xml_declaration.rb', line 13

def standalone
  @standalone
end

#versionString

Returns:

  • (String)


6
7
8
# File 'lib/oga/xml/xml_declaration.rb', line 6

def version
  @version
end

Instance Method Details

#inspectString

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/oga/xml/xml_declaration.rb', line 30

def inspect
  segments = []

  [:version, :encoding, :standalone].each do |attr|
    value = send(attr)

    if value and !value.empty?
      segments << "#{attr}: #{value.inspect}"
    end
  end

  "XmlDeclaration(#{segments.join(' ')})"
end