Class: Oga::XML::Doctype

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

Overview

Class used for storing information about Doctypes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Doctype

Returns a new instance of Doctype.

Examples:

dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')

Parameters:

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

Options Hash (options):

  • :name (String)
  • :type (String)
  • :public_id (String)
  • :system_id (String)

40
41
42
43
44
45
46
# File 'lib/oga/xml/doctype.rb', line 40

def initialize(options = {})
  @name         = options[:name]
  @type         = options[:type]
  @public_id    = options[:public_id]
  @system_id    = options[:system_id]
  @inline_rules = options[:inline_rules]
end

Instance Attribute Details

#inline_rulesString

The inline doctype rules.

Returns:

  • (String)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oga/xml/doctype.rb', line 26

class Doctype
  attr_accessor :name, :type, :public_id, :system_id, :inline_rules

  ##
  # @example
  #  dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')
  #
  # @param [Hash] options
  #
  # @option options [String] :name
  # @option options [String] :type
  # @option options [String] :public_id
  # @option options [String] :system_id
  #
  def initialize(options = {})
    @name         = options[:name]
    @type         = options[:type]
    @public_id    = options[:public_id]
    @system_id    = options[:system_id]
    @inline_rules = options[:inline_rules]
  end

  ##
  # Converts the doctype back to XML.
  #
  # @return [String]
  #
  def to_xml
    segments = "<!DOCTYPE #{name}"

    segments << " #{type}" if type
    segments << %Q{ "#{public_id}"} if public_id
    segments << %Q{ "#{system_id}"} if system_id
    segments << " [#{inline_rules}]" if inline_rules

    return segments + '>'
  end

  ##
  # Inspects the doctype.
  #
  # @return [String]
  #
  def inspect
    segments = []

    [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
      value = send(attr)

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

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

#nameString

The name of the doctype (e.g. "HTML").

Returns:

  • (String)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oga/xml/doctype.rb', line 26

class Doctype
  attr_accessor :name, :type, :public_id, :system_id, :inline_rules

  ##
  # @example
  #  dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')
  #
  # @param [Hash] options
  #
  # @option options [String] :name
  # @option options [String] :type
  # @option options [String] :public_id
  # @option options [String] :system_id
  #
  def initialize(options = {})
    @name         = options[:name]
    @type         = options[:type]
    @public_id    = options[:public_id]
    @system_id    = options[:system_id]
    @inline_rules = options[:inline_rules]
  end

  ##
  # Converts the doctype back to XML.
  #
  # @return [String]
  #
  def to_xml
    segments = "<!DOCTYPE #{name}"

    segments << " #{type}" if type
    segments << %Q{ "#{public_id}"} if public_id
    segments << %Q{ "#{system_id}"} if system_id
    segments << " [#{inline_rules}]" if inline_rules

    return segments + '>'
  end

  ##
  # Inspects the doctype.
  #
  # @return [String]
  #
  def inspect
    segments = []

    [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
      value = send(attr)

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

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

#public_idString

The public ID of the doctype.

Returns:

  • (String)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oga/xml/doctype.rb', line 26

class Doctype
  attr_accessor :name, :type, :public_id, :system_id, :inline_rules

  ##
  # @example
  #  dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')
  #
  # @param [Hash] options
  #
  # @option options [String] :name
  # @option options [String] :type
  # @option options [String] :public_id
  # @option options [String] :system_id
  #
  def initialize(options = {})
    @name         = options[:name]
    @type         = options[:type]
    @public_id    = options[:public_id]
    @system_id    = options[:system_id]
    @inline_rules = options[:inline_rules]
  end

  ##
  # Converts the doctype back to XML.
  #
  # @return [String]
  #
  def to_xml
    segments = "<!DOCTYPE #{name}"

    segments << " #{type}" if type
    segments << %Q{ "#{public_id}"} if public_id
    segments << %Q{ "#{system_id}"} if system_id
    segments << " [#{inline_rules}]" if inline_rules

    return segments + '>'
  end

  ##
  # Inspects the doctype.
  #
  # @return [String]
  #
  def inspect
    segments = []

    [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
      value = send(attr)

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

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

#system_idString

The system ID of the doctype.

Returns:

  • (String)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oga/xml/doctype.rb', line 26

class Doctype
  attr_accessor :name, :type, :public_id, :system_id, :inline_rules

  ##
  # @example
  #  dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')
  #
  # @param [Hash] options
  #
  # @option options [String] :name
  # @option options [String] :type
  # @option options [String] :public_id
  # @option options [String] :system_id
  #
  def initialize(options = {})
    @name         = options[:name]
    @type         = options[:type]
    @public_id    = options[:public_id]
    @system_id    = options[:system_id]
    @inline_rules = options[:inline_rules]
  end

  ##
  # Converts the doctype back to XML.
  #
  # @return [String]
  #
  def to_xml
    segments = "<!DOCTYPE #{name}"

    segments << " #{type}" if type
    segments << %Q{ "#{public_id}"} if public_id
    segments << %Q{ "#{system_id}"} if system_id
    segments << " [#{inline_rules}]" if inline_rules

    return segments + '>'
  end

  ##
  # Inspects the doctype.
  #
  # @return [String]
  #
  def inspect
    segments = []

    [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
      value = send(attr)

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

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

#typeString

The type of the doctype (e.g. "PUBLIC").

Returns:

  • (String)

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/oga/xml/doctype.rb', line 26

class Doctype
  attr_accessor :name, :type, :public_id, :system_id, :inline_rules

  ##
  # @example
  #  dtd = Doctype.new(:name => 'html', :type => 'PUBLIC')
  #
  # @param [Hash] options
  #
  # @option options [String] :name
  # @option options [String] :type
  # @option options [String] :public_id
  # @option options [String] :system_id
  #
  def initialize(options = {})
    @name         = options[:name]
    @type         = options[:type]
    @public_id    = options[:public_id]
    @system_id    = options[:system_id]
    @inline_rules = options[:inline_rules]
  end

  ##
  # Converts the doctype back to XML.
  #
  # @return [String]
  #
  def to_xml
    segments = "<!DOCTYPE #{name}"

    segments << " #{type}" if type
    segments << %Q{ "#{public_id}"} if public_id
    segments << %Q{ "#{system_id}"} if system_id
    segments << " [#{inline_rules}]" if inline_rules

    return segments + '>'
  end

  ##
  # Inspects the doctype.
  #
  # @return [String]
  #
  def inspect
    segments = []

    [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
      value = send(attr)

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

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

Instance Method Details

#inspectString

Inspects the doctype.

Returns:

  • (String)

69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/oga/xml/doctype.rb', line 69

def inspect
  segments = []

  [:name, :type, :public_id, :system_id, :inline_rules].each do |attr|
    value = send(attr)

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

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

#to_xmlString

Converts the doctype back to XML.

Returns:

  • (String)

53
54
55
56
57
58
59
60
61
62
# File 'lib/oga/xml/doctype.rb', line 53

def to_xml
  segments = "<!DOCTYPE #{name}"

  segments << " #{type}" if type
  segments << %Q{ "#{public_id}"} if public_id
  segments << %Q{ "#{system_id}"} if system_id
  segments << " [#{inline_rules}]" if inline_rules

  return segments + '>'
end