Class: SaxStream::Internal::ElementStack
- Inherits:
-
Object
- Object
- SaxStream::Internal::ElementStack
show all
- Defined in:
- lib/sax_stream/internal/element_stack.rb
Defined Under Namespace
Classes: Element, RootElement
Instance Method Summary
collapse
Constructor Details
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
#attributes ⇒ Object
80
81
82
|
# File 'lib/sax_stream/internal/element_stack.rb', line 80
def attributes
@elements.last.attributes(path)
end
|
#content ⇒ Object
76
77
78
|
# File 'lib/sax_stream/internal/element_stack.rb', line 76
def content
@elements.last.content
end
|
#empty? ⇒ Boolean
64
65
66
|
# File 'lib/sax_stream/internal/element_stack.rb', line 64
def empty?
@elements.length <= 1
end
|
#length ⇒ Object
68
69
70
|
# File 'lib/sax_stream/internal/element_stack.rb', line 68
def length
@elements.length
end
|
#path ⇒ Object
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
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
@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))
end
|
#push_root ⇒ Object
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)
if @elements.last
@elements.last.record_characters(string)
end
end
|
#relative_attributes ⇒ Object
84
85
86
|
# File 'lib/sax_stream/internal/element_stack.rb', line 84
def relative_attributes
@elements.last.relative_attributes
end
|