Class: Oga::XML::XmlDeclaration

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

Overview

Class containing information about an XML declaration tag.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ XmlDeclaration

Returns a new instance of XmlDeclaration

Options Hash (options):

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

28
29
30
31
32
# File 'lib/oga/xml/xml_declaration.rb', line 28

def initialize(options = {})
  @version    = options[:version] || '1.0'
  @encoding   = options[:encoding] || 'UTF-8'
  @standalone = options[:standalone]
end

Instance Attribute Details

#encodingString

The XML document's encoding.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oga/xml/xml_declaration.rb', line 18

class XmlDeclaration
  attr_accessor :version, :encoding, :standalone

  ##
  # @param [Hash] options
  #
  # @option options [String] :version
  # @option options [String] :encoding
  # @option options [String] :standalone
  #
  def initialize(options = {})
    @version    = options[:version] || '1.0'
    @encoding   = options[:encoding] || 'UTF-8'
    @standalone = options[:standalone]
  end

  ##
  # Converts the declaration tag to XML.
  #
  # @return [String]
  #
  def to_xml
    pairs = []

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

      pairs << %Q{#{getter}="#{value}"} if value
    end

    return "<?xml #{pairs.join(' ')} ?>"
  end

  ##
  # @return [String]
  #
  def inspect
    segments = []

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

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

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

#standaloneString

Whether or not the document is a standalone document.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oga/xml/xml_declaration.rb', line 18

class XmlDeclaration
  attr_accessor :version, :encoding, :standalone

  ##
  # @param [Hash] options
  #
  # @option options [String] :version
  # @option options [String] :encoding
  # @option options [String] :standalone
  #
  def initialize(options = {})
    @version    = options[:version] || '1.0'
    @encoding   = options[:encoding] || 'UTF-8'
    @standalone = options[:standalone]
  end

  ##
  # Converts the declaration tag to XML.
  #
  # @return [String]
  #
  def to_xml
    pairs = []

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

      pairs << %Q{#{getter}="#{value}"} if value
    end

    return "<?xml #{pairs.join(' ')} ?>"
  end

  ##
  # @return [String]
  #
  def inspect
    segments = []

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

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

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

#versionString

The XML version.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/oga/xml/xml_declaration.rb', line 18

class XmlDeclaration
  attr_accessor :version, :encoding, :standalone

  ##
  # @param [Hash] options
  #
  # @option options [String] :version
  # @option options [String] :encoding
  # @option options [String] :standalone
  #
  def initialize(options = {})
    @version    = options[:version] || '1.0'
    @encoding   = options[:encoding] || 'UTF-8'
    @standalone = options[:standalone]
  end

  ##
  # Converts the declaration tag to XML.
  #
  # @return [String]
  #
  def to_xml
    pairs = []

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

      pairs << %Q{#{getter}="#{value}"} if value
    end

    return "<?xml #{pairs.join(' ')} ?>"
  end

  ##
  # @return [String]
  #
  def inspect
    segments = []

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

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

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

Instance Method Details

#inspectString


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/oga/xml/xml_declaration.rb', line 54

def inspect
  segments = []

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

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

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

#to_xmlString

Converts the declaration tag to XML.


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/oga/xml/xml_declaration.rb', line 39

def to_xml
  pairs = []

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

    pairs << %Q{#{getter}="#{value}"} if value
  end

  return "<?xml #{pairs.join(' ')} ?>"
end