Class: XSD::QName

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

Constant Summary collapse

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.



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

def initialize(namespace = nil, name = nil)
  @namespace = namespace ? namespace.to_s : nil
  @name = name ? name.to_s : nil
  @source = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#==(rhs) ⇒ Object



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

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

#===(rhs) ⇒ Object



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

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

#dump(predefined_ns = nil) ⇒ Object



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

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



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

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

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hashObject



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

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

#inspectObject



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

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

#match(rhs) ⇒ Object



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

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



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

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

#to_sObject



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

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