/tools/Ruby/lib/ruby/1.8/xsd/qname.rb

http://github.com/agross/netopenspace · Ruby · 78 lines · 54 code · 19 blank · 5 comment · 8 complexity · 4d7c75ec21e56acf8c15c79ce1469925 MD5 · raw file

  1. # XSD4R - XML QName definition.
  2. # Copyright (C) 2002, 2003, 2004 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
  3. # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
  4. # redistribute it and/or modify it under the same terms of Ruby's license;
  5. # either the dual license version in 2003, or any later version.
  6. module XSD
  7. class QName
  8. attr_accessor :namespace
  9. attr_accessor :name
  10. attr_accessor :source
  11. def initialize(namespace = nil, name = nil)
  12. @namespace = namespace
  13. @name = name
  14. @source = nil
  15. end
  16. def dup_name(name)
  17. XSD::QName.new(@namespace, name)
  18. end
  19. def dump
  20. ns = @namespace.nil? ? 'nil' : @namespace.dump
  21. name = @name.nil? ? 'nil' : @name.dump
  22. "XSD::QName.new(#{ns}, #{name})"
  23. end
  24. def match(rhs)
  25. if rhs.namespace and (rhs.namespace != @namespace)
  26. return false
  27. end
  28. if rhs.name and (rhs.name != @name)
  29. return false
  30. end
  31. true
  32. end
  33. def ==(rhs)
  34. !rhs.nil? and @namespace == rhs.namespace and @name == rhs.name
  35. end
  36. def ===(rhs)
  37. (self == rhs)
  38. end
  39. def eql?(rhs)
  40. (self == rhs)
  41. end
  42. def hash
  43. @namespace.hash ^ @name.hash
  44. end
  45. def to_s
  46. "{#{ namespace }}#{ name }"
  47. end
  48. def inspect
  49. sprintf("#<%s:0x%x %s>", self.class.name, __id__,
  50. "{#{ namespace }}#{ name }")
  51. end
  52. NormalizedNameRegexp = /^\{([^}]*)\}(.*)$/
  53. def parse(str)
  54. NormalizedNameRegexp =~ str
  55. self.new($1, $2)
  56. end
  57. EMPTY = QName.new.freeze
  58. end
  59. end