line-tree 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/line-tree.rb +12 -6
  2. metadata +13 -4
data/lib/line-tree.rb CHANGED
@@ -2,15 +2,14 @@
2
2
 
3
3
  # file: line-tree.rb
4
4
 
5
+ require 'rexle'
6
+
5
7
  class LineTree
6
8
 
7
- def initialize(lines)
8
- @a = scan_shift(lines)
9
- end
9
+ attr_reader :to_a
10
10
 
11
- def to_a()
12
- @a
13
- end
11
+ def initialize(lines) @to_a = scan_shift(lines) end
12
+ def to_xml() Rexle.new(scan_a(*@to_a)).xml end
14
13
 
15
14
  private
16
15
 
@@ -28,4 +27,11 @@ class LineTree
28
27
  end
29
28
  end
30
29
 
30
+ def scan_a(a)
31
+ r = a.shift.match(/([^\s]+)\s?(.*)/).captures << {}
32
+ a.map {|x| r << scan_a(x.clone) } if a.is_a? Array
33
+ r
34
+ end
35
+
36
+
31
37
  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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-06 00:00:00 +01:00
12
+ date: 2011-02-06 00:00:00 +00:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rexle
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: Line-tree parses indented lines of text and returns an array representing a tree structure.
17
26
  email:
18
27
  executables: []