Class: QName

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

Overview

Defines QName and AttributeName classes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, name) ⇒ QName



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/r4x/qname.rb', line 32

def initialize( namespace, name )
  @name = name.local_name.to_s # to_String
  case namespace
  when nil, ''
    namespace = (name == '*' ? nil : get_default_namespace )
  end
  @local_name = name
  unless namespace
    @uri = nil
    @prefix = nil
  else
    namespace = Namespace.new( namespace )
    @uri = namespace.uri
    @prefix = namespace.prefix
  end
end

Instance Attribute Details

#local_nameObject (readonly)

Returns the value of attribute local_name.



28
29
30
# File 'lib/r4x/qname.rb', line 28

def local_name
  @local_name
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/r4x/qname.rb', line 27

def name
  @name
end

#prefixObject (readonly)

Returns the value of attribute prefix.



30
31
32
# File 'lib/r4x/qname.rb', line 30

def prefix
  @prefix
end

#uriObject (readonly)

Returns the value of attribute uri.



29
30
31
# File 'lib/r4x/qname.rb', line 29

def uri
  @uri
end

Class Method Details

.__newObject



8
# File 'lib/r4x/qname.rb', line 8

alias :__new :new

.new(name_or_namespace, name = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/r4x/qname.rb', line 10

def new( name_or_namespace, name=nil )
  case name_or_namespace
  when QName
    return name_or_namespace
  when nil
    if QName === name or name.class == "QName"
      return name.dup
    else
      __new(name_or_namespace, name)
    end
  else
    __new(name_or_namespace, name )
  end
end

Instance Method Details

#get_namespace(in_scope_namespaces = nil) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/r4x/qname.rb', line 63

def get_namespace( in_scope_namespaces=nil )
  raise 'no uri [should not have occured]' unless uri
  in_scope_namespaces ||= []
  ns = in_scope_namespaces.find { |n| uri == n.uri }  # prefix == n.prefix ?
  ns = Namespace.new( uri ) unless ns  # or ns = Namespace.new( prefix, uri ) ?
  ns
end

#to_sObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/r4x/qname.rb', line 50

def to_s
  s = ''
  if uri != ''
    unless uri
      s = '*::'
    else
      s = "#{uri}::"
    end
  end
  "#{s}#{local_name}"
end