Class: SAXMachine::NSStack

Inherits:
Hash
  • Object
show all
Defined in:
lib/sax-machine/ns_stack.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, attrs = []) ⇒ NSStack

Returns a new instance of NSStack.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sax-machine/ns_stack.rb', line 3

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

Instance Method Details

#[](name) ⇒ Object

Lookup



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sax-machine/ns_stack.rb', line 21

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

#popObject



34
35
36
# File 'lib/sax-machine/ns_stack.rb', line 34

def pop
  @parent
end