Class: Nodifier
Instance Method Summary collapse
- #append_child_content(node, child_content) ⇒ Object
-
#initialize(parser = nil) ⇒ Nodifier
constructor
A new instance of Nodifier.
- #nodify(content) ⇒ Object
Methods included from Indentation
Constructor Details
#initialize(parser = nil) ⇒ Nodifier
Returns a new instance of Nodifier.
8 9 10 |
# File 'lib/nodifier.rb', line 8 def initialize(parser = nil) @parser = parser || NodeParser.new end |
Instance Method Details
#append_child_content(node, child_content) ⇒ Object
38 39 40 41 42 |
# File 'lib/nodifier.rb', line 38 def append_child_content(node, child_content) nodify(child_content).each do |child_node| node.children << child_node end end |
#nodify(content) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nodifier.rb', line 12 def nodify(content) nodes = Nodes.new current_node = nil child_content = '' content = unindent content content.lines do |line| if not line.start_with?(' ') if not child_content.empty? append_child_content current_node, child_content child_content = '' end current_node = @parser.parse line.rstrip nodes << current_node else child_content << line end end append_child_content current_node, child_content unless child_content.empty? nodes end |