source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/xsd/qname.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

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