Class: MiniAether::XmlParser

Inherits:
REXML::Parsers::PullParser
  • Object
show all
Defined in:
lib/mini_aether/xml_parser.rb

Overview

Simple helper methods around REXML pull parser.

Author:

Since:

  • 0.0.1, 1-June-2012

Defined Under Namespace

Classes: NotFoundError

Instance Method Summary collapse

Instance Method Details

#pull_text_until_endObject

Pull all text nodes until the next end_element event. Return the concatenation of text nodes.

Since:

  • 0.0.1, 1-June-2012



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/....

Since:

  • 0.0.1, 1-June-2012



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.

Since:

  • 0.0.1, 1-June-2012



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