Class: SaxStream::Internal::ElementStack

Inherits:
Object
  • Object
show all
Defined in:
lib/sax_stream/internal/element_stack.rb

Defined Under Namespace

Classes: Element, RootElement

Instance Method Summary collapse

Constructor Details

#initializeElementStack

Returns a new instance of ElementStack.



42
43
44
# File 'lib/sax_stream/internal/element_stack.rb', line 42

def initialize
  @elements = []
end

Instance Method Details

#attributesObject



80
81
82
# File 'lib/sax_stream/internal/element_stack.rb', line 80

def attributes
  @elements.last.attributes(path)
end

#contentObject



76
77
78
# File 'lib/sax_stream/internal/element_stack.rb', line 76

def content
  @elements.last.content
end

#empty?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/sax_stream/internal/element_stack.rb', line 64

def empty?
  @elements.length <= 1
end

#lengthObject



68
69
70
# File 'lib/sax_stream/internal/element_stack.rb', line 68

def length
  @elements.length
end

#pathObject



72
73
74
# File 'lib/sax_stream/internal/element_stack.rb', line 72

def path
  @elements.inject(""){|s,e| s += "#{e.name}/" unless e.name.nil?;s }.chop unless @elements.empty?
end

#pop(name = nil) ⇒ Object

Raises:



55
56
57
58
59
60
61
62
# File 'lib/sax_stream/internal/element_stack.rb', line 55

def pop(name = nil)
  raise ProgramError, "attempting to pop an empty ElementStack" if @elements.empty?
  if name && @element_stack.top_name != name
    raise ProgramError "received popping element for #{name.inspect} but currently processing #{path.inspect}"
  end
  # indented_puts "pop element"
  @elements.pop
end

#push(name, attrs) ⇒ Object



46
47
48
49
# File 'lib/sax_stream/internal/element_stack.rb', line 46

def push(name, attrs)
  @elements.push(Element.new(name, attrs))
  # indented_puts "push element #{name}"
end

#push_rootObject



51
52
53
# File 'lib/sax_stream/internal/element_stack.rb', line 51

def push_root
  @elements.push(RootElement.new)
end

#record_characters(string) ⇒ Object



88
89
90
91
92
93
# File 'lib/sax_stream/internal/element_stack.rb', line 88

def record_characters(string)
  # indented_puts "  record: #{string.inspect}"
  if @elements.last
    @elements.last.record_characters(string)
  end
end

#relative_attributesObject



84
85
86
# File 'lib/sax_stream/internal/element_stack.rb', line 84

def relative_attributes
  @elements.last.relative_attributes
end