Class: XSD::QName

Inherits:
Object show all
Defined in:
lib/xsd/qname.rb

Constant Summary

NormalizedNameRegexp =
/^\{([^}]*)\}(.*)$/
EMPTY =
QName.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = nil, name = nil) ⇒ QName

Returns a new instance of QName



17
18
19
20
21
# File 'lib/xsd/qname.rb', line 17

def initialize(namespace = nil, name = nil)
  @namespace = namespace
  @name = name
  @source = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



14
15
16
# File 'lib/xsd/qname.rb', line 14

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace



13
14
15
# File 'lib/xsd/qname.rb', line 13

def namespace
  @namespace
end

#sourceObject

Returns the value of attribute source



15
16
17
# File 'lib/xsd/qname.rb', line 15

def source
  @source
end

Instance Method Details

#==(rhs) ⇒ Object



44
45
46
# File 'lib/xsd/qname.rb', line 44

def ==(rhs)
  !rhs.nil? and @namespace == rhs.namespace and @name == rhs.name
end

#===(rhs) ⇒ Object



48
49
50
# File 'lib/xsd/qname.rb', line 48

def ===(rhs)
  (self == rhs)
end

#dump(predefined_ns = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/xsd/qname.rb', line 27

def dump(predefined_ns = nil)
  ns = predefined_ns
  ns ||= @namespace.nil? ? 'nil' : @namespace.dump
  name = @name.nil? ? 'nil' : @name.dump
  "XSD::QName.new(#{ns}, #{name})"
end

#dup_name(name) ⇒ Object



23
24
25
# File 'lib/xsd/qname.rb', line 23

def dup_name(name)
  XSD::QName.new(@namespace, name)
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/xsd/qname.rb', line 52

def eql?(rhs)
  (self == rhs)
end

#hashObject



56
57
58
# File 'lib/xsd/qname.rb', line 56

def hash
  @namespace.hash ^ @name.hash
end

#inspectObject



64
65
66
67
# File 'lib/xsd/qname.rb', line 64

def inspect
  sprintf("#<%s:0x%x %s>", self.class.name, __id__,
    "{#{ namespace }}#{ name }")
end

#match(rhs) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/xsd/qname.rb', line 34

def match(rhs)
  if rhs.namespace and (rhs.namespace != @namespace)
    return false
  end
  if rhs.name and (rhs.name != @name)
    return false
  end
  true
end

#parse(str) ⇒ Object



70
71
72
73
# File 'lib/xsd/qname.rb', line 70

def parse(str)
  NormalizedNameRegexp =~ str
  self.new($1, $2)
end

#to_sObject



60
61
62
# File 'lib/xsd/qname.rb', line 60

def to_s
  "{#{ namespace }}#{ name }"
end