PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.9.1/rexml/namespace.rb

#
Ruby | 47 lines | 35 code | 5 blank | 7 comment | 6 complexity | 587f159fc07337037d810558778bf6ea MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. require 'rexml/xmltokens'
  2. module REXML
  3. # Adds named attributes to an object.
  4. module Namespace
  5. # The name of the object, valid if set
  6. attr_reader :name, :expanded_name
  7. # The expanded name of the object, valid if name is set
  8. attr_accessor :prefix
  9. include XMLTokens
  10. NAMESPLIT = /^(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})/u
  11. # Sets the name and the expanded name
  12. def name=( name )
  13. @expanded_name = name
  14. name =~ NAMESPLIT
  15. if $1
  16. @prefix = $1
  17. else
  18. @prefix = ""
  19. @namespace = ""
  20. end
  21. @name = $2
  22. end
  23. # Compares names optionally WITH namespaces
  24. def has_name?( other, ns=nil )
  25. if ns
  26. return (namespace() == ns and name() == other)
  27. elsif other.include? ":"
  28. return fully_expanded_name == other
  29. else
  30. return name == other
  31. end
  32. end
  33. alias :local_name :name
  34. # Fully expand the name, even if the prefix wasn't specified in the
  35. # source file.
  36. def fully_expanded_name
  37. ns = prefix
  38. return "#{ns}:#@name" if ns.size > 0
  39. return @name
  40. end
  41. end
  42. end