line-tree 0.3.2 → 0.3.3

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 +10 -4
  2. metadata +1 -1
data/lib/line-tree.rb CHANGED
@@ -9,9 +9,7 @@ class LineTree
9
9
  attr_reader :to_a
10
10
 
11
11
  def initialize(lines) @to_a = scan_shift(lines) end
12
- def to_xml(options={})
13
- Rexle.new(scan_a(*@to_a)).xml(options)
14
- end
12
+ def to_xml(options={}) Rexle.new(scan_a(*@to_a)).xml(options) end
15
13
 
16
14
  private
17
15
 
@@ -30,10 +28,18 @@ class LineTree
30
28
  end
31
29
 
32
30
  def scan_a(a)
33
- r = a.shift.match(/([^\s]+)\s?(.*)/).captures << {}
31
+ r = a.shift.match(/([^\s]+)\s*(\{[^\}]+\})?\s*(.*)/).captures.values_at(0,-1,1)
32
+ r[-1] = get_attributes(r.last) if r.last
34
33
  a.map {|x| r << scan_a(x.clone) } if a.is_a? Array
35
34
  r
36
35
  end
37
36
 
37
+ def get_attributes(s)
38
+ a = s[/{(.*)}/,1].split(',').map do |attr|
39
+ attr.match(/\s*([^:=]+)[:=]\s*['"]*([a-zA-Z0-9]*)/).captures
40
+ end
41
+
42
+ Hash[*a.flatten]
43
+ end
38
44
 
39
45
  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.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors: []
7
7