/tools/Ruby/lib/ruby/1.8/rexml/comment.rb

http://github.com/agross/netopenspace · Ruby · 80 lines · 38 code · 10 blank · 32 comment · 2 complexity · 6b83105f940151c711811e663c06d739 MD5 · raw file

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