internalize rexml
[booh] / lib / booh / rexml / comment.rb
1 require "booh/rexml/child"
2
3 module REXML
4         ##
5         # Represents an XML comment; that is, text between \<!-- ... -->
6         class Comment < Child
7                 include Comparable
8                 START = "<!--"
9                 STOP = "-->"
10
11                 # The content text
12
13                 attr_accessor :string
14
15                 ##
16                 # Constructor.  The first argument can be one of three types:
17                 # @param first If String, the contents of this comment are set to the 
18                 # argument.  If Comment, the argument is duplicated.  If
19                 # Source, the argument is scanned for a comment.
20                 # @param second If the first argument is a Source, this argument 
21                 # should be nil, not supplied, or a Parent to be set as the parent 
22                 # of this object
23                 def initialize( first, second = nil )
24                         #puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}"
25                         super(second)
26                         if first.kind_of? String
27                                 @string = first
28                         elsif first.kind_of? Comment
29                                 @string = first.string
30                         end
31                 end
32
33                 def clone
34                         Comment.new self
35                 end
36
37                 # output::
38                 #        Where to write the string
39                 # indent::
40                 #        An integer.    If -1, no indenting will be used; otherwise, the
41                 #        indentation will be this number of spaces, and children will be
42                 #        indented an additional amount.
43                 # transitive::
44                 #        Ignored by this class. The contents of comments are never modified.
45                 # ie_hack::
46                 #        Needed for conformity to the child API, but not used by this class.
47                 def write( output, indent=-1, transitive=false, ie_hack=false )
48                         indent( output, indent )
49                         output << START
50                         output << @string
51                         output << STOP
52                 end
53
54                 alias :to_s :string
55
56                 ##
57                 # Compares this Comment to another; the contents of the comment are used
58                 # in the comparison.
59                 def <=>(other)
60                         other.to_s <=> @string
61                 end
62
63                 ##
64                 # Compares this Comment to another; the contents of the comment are used
65                 # in the comparison.
66                 def ==( other )
67                         other.kind_of? Comment and
68                         (other <=> self) == 0
69                 end
70
71     def node_type
72       :comment
73     end
74         end
75 end
76 #vim:ts=2 sw=2 noexpandtab: