line-tree 0.2.5 → 0.2.6

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 +13 -2
  2. metadata +2 -2
data/lib/line-tree.rb CHANGED
@@ -4,6 +4,7 @@ class LineTree
4
4
  include REXML
5
5
 
6
6
  def initialize(lines)
7
+ @lines = lines
7
8
  a = lines.split(/\r?\n|\r(?!\n)/)
8
9
  pattern = %r((\s+)?(.*))
9
10
  a.map!{|x| x.match(pattern).captures}
@@ -19,9 +20,18 @@ class LineTree
19
20
  end
20
21
 
21
22
  def to_xml()
23
+
24
+ a = @lines.split(/\r?\n|\r(?!\n)/)
25
+ pattern = %r((\s+)?(((\/|.)[^\s]+)\s)?([^$]+))
26
+ a.map!{|x| x.match(pattern).captures.values_at(0,2,4)}
27
+
28
+ new_a, history = [], []
29
+ history << new_a
30
+ build_tree(a, new_a, 0, history)
31
+
22
32
  d = REXML::Formatters::Default.new
23
33
  doc = Document.new '<root/>'
24
- scan_line doc.root, @a
34
+ scan_line doc.root, new_a
25
35
  d.write(XPath.first(doc.root, '*'), out='')
26
36
  out
27
37
  end
@@ -66,7 +76,8 @@ class LineTree
66
76
  def scan_line(node, a)
67
77
  a.each do |x|
68
78
  name, text = x.shift.compact
69
- element = Element.new(name.gsub(/^[^a-zA-Z][^a-zA-Z0-9]?/,'')).add_text text
79
+ element = Element.new(name.gsub(/^[^a-zA-Z][^a-zA-Z0-9]?/,''))
80
+ element.add_text text
70
81
  scan_line(element, x) unless x.empty?
71
82
  node.add element
72
83
  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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-23 00:00:00 +01:00
12
+ date: 2010-05-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15