Class: Kwaff::DocType

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

Constant Summary collapse

@@instances =
[]
@@registered =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_tag, public_id, system_id, desc = nil) ⇒ DocType

ex.

 root_tag  = 'html'
 public_id = '-//W3C//DTD XHTML 1.0 Transitional//EN'
 system_id = 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
 doctype = DocType.new(root_tag, public_id, system_id)
or
 str = <<END
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
 END
 doctype = DocType.new()
 doctype.doctype = str


35
36
37
38
39
40
41
42
# File 'lib/kwaff/doctype.rb', line 35

def initialize(root_tag, public_id, system_id, desc=nil)
   @root_tag  = root_tag
   @public_id = public_id
   @system_id = system_id
   @desc      = desc
   @_str = nil
   @@instances << self
end

Instance Attribute Details

#descObject

Returns the value of attribute desc.



43
44
45
# File 'lib/kwaff/doctype.rb', line 43

def desc
  @desc
end

#namesObject

Returns the value of attribute names.



45
46
47
# File 'lib/kwaff/doctype.rb', line 45

def names
  @names
end

#public_idObject

Returns the value of attribute public_id.



43
44
45
# File 'lib/kwaff/doctype.rb', line 43

def public_id
  @public_id
end

#root_tagObject

Returns the value of attribute root_tag.



43
44
45
# File 'lib/kwaff/doctype.rb', line 43

def root_tag
  @root_tag
end

#system_idObject

Returns the value of attribute system_id.



43
44
45
# File 'lib/kwaff/doctype.rb', line 43

def system_id
  @system_id
end

Class Method Details

._read_file(filename) ⇒ Object



93
94
95
96
97
98
99
100
101
# File 'lib/kwaff/doctype.rb', line 93

def self._read_file(filename)
   s = ''
   File.open(filename) do |f|
      while line = f.gets()
         s << line.gsub(/([^\t]{8})|([^\t]*)\t/n){[$+].pack("A8")}
      end
   end
   return s
end

.find(&block) ⇒ Object



82
83
84
# File 'lib/kwaff/doctype.rb', line 82

def self.find(&block)
   return @@instances.find(&block)
end

.get(nickname) ⇒ Object



78
79
80
# File 'lib/kwaff/doctype.rb', line 78

def self.get(nickname)
   @@registered[nickname]
end

.instancesObject



64
65
66
# File 'lib/kwaff/doctype.rb', line 64

def self.instances
   @@instances
end

.nickname(doctype) ⇒ Object



86
87
88
89
90
91
# File 'lib/kwaff/doctype.rb', line 86

def self.nickname(doctype)
   @@registered.each do |nickname, dtype|
      return nickname if dtype.public_id == doctype.public_id
   end
   return nil
end

.register(nickname, doctype) ⇒ Object

def self.registered

@@registered

end



74
75
76
# File 'lib/kwaff/doctype.rb', line 74

def self.register(nickname, doctype)
   @@registered[nickname] = doctype
end

Instance Method Details

#to_sObject

convert to “<!DOCTYPE …>”



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kwaff/doctype.rb', line 49

def to_s
   if ! @_str
      @_str    = "<!DOCTYPE #{@root_tag}"
      if @public_id
         @_str << " PUBLIC \"#{@public_id}\"\n\t"
      else
         @_str << " SYSTEM "
      end
      @_str << "\"#{@system_id}\"" if @system_id
      @_str << ">"
   end
   return @_str
end