Class: PseudoXml::XmlString
- Inherits:
-
Object
- Object
- PseudoXml::XmlString
- Defined in:
- lib/pseudo_xml/xml_string.rb
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(xml) ⇒ XmlString
constructor
A new instance of XmlString.
- #parse(collector) ⇒ Object
- #reset! ⇒ Object
- #skip_prolog ⇒ Object
Constructor Details
#initialize(xml) ⇒ XmlString
Returns a new instance of XmlString.
4 5 6 7 |
# File 'lib/pseudo_xml/xml_string.rb', line 4 def initialize(xml) @xml = xml reset! end |
Instance Method Details
#eof? ⇒ Boolean
45 46 47 |
# File 'lib/pseudo_xml/xml_string.rb', line 45 def eof? @offset_start.nil? || @offset_end.nil? end |
#parse(collector) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pseudo_xml/xml_string.rb', line 21 def parse(collector) until(eof?) do @offset_start = @xml.index('<', @offset_end) return nil unless @offset_start if @offset_start > @offset_end + 1 collector.add_text @xml[@offset_end + 1...@offset_start] end @offset_end = @xml.index('>', @offset_start) return nil unless @offset_end element_text = @xml[@offset_start..@offset_end] if element_text[1,1] == '/' collector.end_element else collector.start_element element_text end end end |
#reset! ⇒ Object
9 10 11 |
# File 'lib/pseudo_xml/xml_string.rb', line 9 def reset! @offset_start = @offset_end = skip_prolog end |
#skip_prolog ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pseudo_xml/xml_string.rb', line 13 def skip_prolog if @xml =~ /^(\<\?.*?\?\>(\r?\n)*)/ $1.size else 0 end end |