Class: Serenity::XmlReader
- Inherits:
-
Object
- Object
- Serenity::XmlReader
- Defined in:
- lib/serenity/serenity/xml_reader.rb
Instance Method Summary collapse
- #each_node ⇒ Object
-
#initialize(src) ⇒ XmlReader
constructor
A new instance of XmlReader.
- #node_type(text) ⇒ Object
Constructor Details
#initialize(src) ⇒ XmlReader
Returns a new instance of XmlReader.
4 5 6 |
# File 'lib/serenity/serenity/xml_reader.rb', line 4 def initialize src @src = src.force_encoding("UTF-8") end |
Instance Method Details
#each_node ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/serenity/serenity/xml_reader.rb', line 8 def each_node last_match_pos = 0 @src.scan(/<.*?>/) do |node| m = Regexp.last_match if m.begin(0) > last_match_pos text = @src[last_match_pos...m.begin(0)] yield text, node_type(text) if text.gsub(/\s+/, '') != '' end last_match_pos = m.end(0) yield node, NodeType::TAG end end |