Sha256: dd73de5a52992f20ad1da93d51379f468c870be51d2eb0f168870578ad7b3a6e

Contents?: true

Size: 684 Bytes

Versions: 15

Compression:

Stored size: 684 Bytes

Contents

module SAXMachine
  class NSStack < Hash
    def initialize(parent=nil, attrs=[])
      # Initialize
      super()
      @parent = parent

      # Parse attributes
      attrs.each do |attr|
        if attr.kind_of?(Array)
          k, v = attr
          case k
          when 'xmlns' then self[''] = v
          when /^xmlns:(.+)/ then self[$1] = v
          end
        end
      end
    end

    # Lookup
    def [](name)
      if (ns = super(name.to_s))
        # I've got it
        ns
      elsif @parent
        # Parent may have it
        @parent[name]
      else
        # Undefined, empty namespace
        ''
      end
    end

    def pop
      @parent
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
astro-sax-machine-0.0.15 lib/sax-machine/ns_stack.rb
astro-sax-machine-0.0.16 lib/sax-machine/ns_stack.rb
astro-sax-machine-0.0.17 lib/sax-machine/ns_stack.rb
astro-sax-machine-0.0.18 lib/sax-machine/ns_stack.rb
astro-sax-machine-0.0.19 lib/sax-machine/ns_stack.rb
astro-sax-machine-0.0.20 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.16 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.17 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.18 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.19 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.20 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.21 lib/sax-machine/ns_stack.rb
superfeedr-sax-machine-0.0.22.2 lib/sax-machine/ns_stack.rb
superfeedr-sax-machine-0.0.22.1 lib/sax-machine/ns_stack.rb
julien51-sax-machine-0.0.22 lib/sax-machine/ns_stack.rb