Class: WsdlMapper::Dom::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/wsdl_mapper/dom/name.rb

Overview

Represents a fully qualified name of an XML element, that means, it contains both the namespace, and the local name

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Name) initialize(ns, name)

Initialize a new fully qualified name.

Parameters:

  • ns (String)
  • name (String)


17
18
19
20
# File 'lib/wsdl_mapper/dom/name.rb', line 17

def initialize(ns, name)
  @ns, @name = ns, name
  @hash = [ns, name].hash
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



12
# File 'lib/wsdl_mapper/dom/name.rb', line 12

attr_reader :ns, :name

- (Object) ns (readonly)

Returns the value of attribute ns



# File 'lib/wsdl_mapper/dom/name.rb', line 6

Class Method Details

+ (Name) get(ns, name)

Gets the WsdlMapper::Dom::Name object for the given namespace and local name from the name cache to minimize the number of strings + objects used.

Parameters:

  • ns (String)

    Namespace URI

  • name (String)

    Local name

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'lib/wsdl_mapper/dom/name.rb', line 57

def self.get(ns, name)
  @cache ||= Hash.new do |h, k|
    h[k] = Hash.new do |h2, k2|
      h2[k2] = new k, k2
    end
  end

  name = name.to_s unless name.is_a?(String)
  @cache[ns][name]
end

Instance Method Details

- (Object) ==(other)

See Also:

  • WsdlMapper::Dom::Name.{{#eql?}


30
31
32
# File 'lib/wsdl_mapper/dom/name.rb', line 30

def ==(other)
  eql? other
end

- (true, false) eql?(other)

Check if this fully qualified name is equal to other.

Parameters:

  • other (Name)

    Other name to compare to.

Returns:

  • (true, false)

    true if self and other are equal both in namespace and in local name.



25
26
27
# File 'lib/wsdl_mapper/dom/name.rb', line 25

def eql?(other)
  self.class == other.class && name == other.name && ns == other.ns
end

- (Object) hash



34
35
36
# File 'lib/wsdl_mapper/dom/name.rb', line 34

def hash
  @hash
end

- (Array<String>) to_a

Returns the namespace and local name as elements of a tuple / 2-element array: ["namespace-uri", "local-name"]

Returns:

  • (Array<String>)

    An array containing namespace & local name.



48
49
50
# File 'lib/wsdl_mapper/dom/name.rb', line 48

def to_a
  [ns, name]
end

- (String) to_s

Returns the fully qualified name as string representation in the format "{namespace-uri}/local-name"

Returns:

  • (String)

    String representation of this FQN



41
42
43
# File 'lib/wsdl_mapper/dom/name.rb', line 41

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