Sha256: 195073d03d1231db70d102805414b0c8d201297304887de5756bd17d0b07039f

Contents?: true

Size: 1.4 KB

Versions: 108

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: false

require_relative 'xmltokens'

module REXML
  # Adds named attributes to an object.
  module Namespace
    # The name of the object, valid if set
    attr_reader :name, :expanded_name
    # The expanded name of the object, valid if name is set
    attr_accessor :prefix
    include XMLTokens
    NAMESPLIT = /^(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})/u

    # Sets the name and the expanded name
    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

    # Compares names optionally WITH namespaces
    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

    alias :local_name :name

    # Fully expand the name, even if the prefix wasn't specified in the
    # source file.
    def fully_expanded_name
      ns = prefix
      return "#{ns}:#@name" if ns.size > 0
      return @name
    end
  end
end

Version data entries

108 entries across 101 versions & 23 rubygems

Version Path
brakeman-5.0.2 bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
cloudsmith-api-0.57.1 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/namespace.rb
rexml-3.2.5 lib/rexml/namespace.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
brakeman-4.10.1 bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
zine_brewer-1.5.0 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
zine_brewer-1.3.0 vendor/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rexml-3.2.4/lib/rexml/namespace.rb