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)


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

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)


25
26
27
# File 'lib/oga/xml/doctype.rb', line 25

def inline_rules
  @inline_rules
end

#nameString

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

Returns:

  • (String)


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

def name
  @name
end

#public_idString

The public ID of the doctype.

Returns:

  • (String)


17
18
19
# File 'lib/oga/xml/doctype.rb', line 17

def public_id
  @public_id
end

#system_idString

The system ID of the doctype.

Returns:

  • (String)


21
22
23
# File 'lib/oga/xml/doctype.rb', line 21

def system_id
  @system_id
end

#typeString

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

Returns:

  • (String)


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

def type
  @type
end

Instance Method Details

#inspectString

Inspects the doctype.

Returns:

  • (String)


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

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

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

#to_xmlString

Converts the doctype back to XML.

Returns:

  • (String)


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

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

  segments + '>'
end