Class: MiniAether::XmlParser
- Inherits:
-
REXML::Parsers::PullParser
- Object
- REXML::Parsers::PullParser
- MiniAether::XmlParser
- Defined in:
- lib/mini_aether/xml_parser.rb
Overview
Simple helper methods around REXML pull parser.
Defined Under Namespace
Classes: NotFoundError
Instance Method Summary collapse
-
#pull_text_until_end ⇒ Object
Pull all text nodes until the next
end_element
event. -
#pull_to_path(*names) ⇒ Object
Pull events to the start of each name, following a path of
name1/name2/...
. -
#pull_to_start(name) ⇒ Object
Pull events until the start of an element of tag name
name
is reached.
Instance Method Details
#pull_text_until_end ⇒ Object
Pull all text nodes until the next end_element
event. Return the concatenation of text nodes.
29 30 31 32 33 34 35 36 37 |
# File 'lib/mini_aether/xml_parser.rb', line 29 def pull_text_until_end texts = [] loop do res = pull break unless res.text? texts << res[0] end texts.join end |
#pull_to_path(*names) ⇒ Object
Pull events to the start of each name, following a path of name1/name2/...
.
23 24 25 |
# File 'lib/mini_aether/xml_parser.rb', line 23 def pull_to_path(*names) names.each { |name| pull_to_start name } end |
#pull_to_start(name) ⇒ Object
Pull events until the start of an element of tag name name
is reached.
13 14 15 16 17 18 19 |
# File 'lib/mini_aether/xml_parser.rb', line 13 def pull_to_start(name) loop do res = pull raise NotFoundError if res.event_type == :end_document next if res.start_element? && res[0] == name.to_s end end |