123456789_123456789_123456789_123456789_123456789_

Module: REXML::Namespace

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, XMLTokens
Defined in: lib/rexml/namespace.rb

Overview

Adds named attributes to an object.

Constant Summary

XMLTokens - Included

NAME, NAMECHAR, NAME_CHAR, NAME_START_CHAR, NAME_STR, NCNAME_STR, NMTOKEN, NMTOKENS, REFERENCE

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#expanded_name (readonly)

The name of the object, valid if set

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 9

attr_reader :name, :expanded_name

#local_name (readonly)

Alias for #name.

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 49

alias :local_name :name

#name (rw) Also known as: #local_name

The name of the object, valid if set

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 9

attr_reader :name, :expanded_name

#name=(name) (rw)

Sets the name and the expanded name

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 16

def name=( name )
  @expanded_name = name
  case name
  when NAMESPLIT
    if $1
      @prefix = $1
    else
      @prefix = ""
      @namespace = ""
    end
    @name = $2
  when ""
    @prefix = nil
    @namespace = nil
    @name = nil
  else
    message = "name must be \#{PREFIX}:\#{LOCAL_NAME} or \#{LOCAL_NAME}: "
    message += "<#{name.inspect}>"
    raise ArgumentError, message
  end
end

#prefix (rw)

The expanded name of the object, valid if name is set

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 11

attr_accessor :prefix

Instance Method Details

#fully_expanded_name

Fully expand the name, even if the prefix wasn’t specified in the source file.

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 53

def fully_expanded_name
  ns = prefix
  return "#{ns}:#@name" if ns.size > 0
  return @name
end

#has_name?(other, ns = nil) ⇒ Boolean

Compares names optionally WITH namespaces

[ GitHub ]

  
# File 'lib/rexml/namespace.rb', line 39

def has_name?( other, ns=nil )
  if ns
    return (namespace() == ns and name() == other)
  elsif other.include? ":"
    return fully_expanded_name == other
  else
    return name == other
  end
end