line-tree 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/line-tree.rb +18 -0
  2. metadata +1 -1
data/lib/line-tree.rb CHANGED
@@ -15,6 +15,14 @@ class LineTree
15
15
  @a
16
16
  end
17
17
 
18
+ def to_xml()
19
+ d = REXML::Formatters::Default.new
20
+ doc = Document.new '<root/>'
21
+ scan_line doc.root, @a
22
+ d.write(XPath.first(doc.root, '*'), out='')
23
+ out
24
+ end
25
+
18
26
  private
19
27
 
20
28
  def build_tree(a, new_a, prev_indent, history=[])
@@ -51,4 +59,14 @@ class LineTree
51
59
  return [cur_indent, x]
52
60
  end
53
61
  end
62
+
63
+ def scan_line(node, a)
64
+ a.each do |x|
65
+ name, text = x.shift.compact
66
+ element = Element.new(name.gsub(/^[^a-zA-Z][^a-zA-Z0-9]?/,'')).add_text text
67
+ scan_line(element, x) unless x.empty?
68
+ node.add element
69
+ end
70
+ end
71
+
54
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors: []
7
7