Class: OpenxmlDocxTemplater::XmlReader
- Inherits:
-
Object
- Object
- OpenxmlDocxTemplater::XmlReader
- Defined in:
- lib/openxml_docx_templater/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.
5 6 7 |
# File 'lib/openxml_docx_templater/xml_reader.rb', line 5 def initialize(src) @src = src end |
Instance Method Details
#each_node ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/openxml_docx_templater/xml_reader.rb', line 9 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) end last_match_pos = m.end(0) yield node, NodeType::TAG end end |