lineparser 0.1.7 → 0.1.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bffa4fcb7dc33ff28c248289a1f669f0c41df25
4
- data.tar.gz: e3f039972e242d98742b4d3b6c92d6e684079cae
3
+ metadata.gz: eb1cde7692199b61e8fec550b5bd8e62357e3dd0
4
+ data.tar.gz: d22fd12cc1bb39e3fa4bf6dee7a16d9f3b3bf1ba
5
5
  SHA512:
6
- metadata.gz: 3b01f202c57f668abc158afee1d8e1fef7f2940684f0ea00ba2c1a4e1555a0b9e66e210db487485c0ef815d95a3174550c86ca37d158acb8f13220f245f182e1
7
- data.tar.gz: bda8db13c47b1f79c39b6c293323f5351a6218afbd509c475f9e1758013f7bbc3431b67c5f7973f783e5e5394758b0e6f183d729b6a3e349cb71413dd65a9839
6
+ metadata.gz: 648241d722119e937354d4b02e61824932a52b84ea9a54d013054c63ab710fa3432376b6184d3660f3814d1a5899a11daf014122cf47fce66b0b904bcd047f64
7
+ data.tar.gz: ee953ce7b6adc99c187ef1bc9e180e7f1800e0090bbcb637516373e8939504161c41491d97e524ee553644a462a48a1582dd6c605dd4995ef8752dde58284430
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/lineparser.rb CHANGED
@@ -52,12 +52,22 @@ class LineParser
52
52
  @a = scan @tree_patterns, LineTree.new(s).to_a
53
53
  end
54
54
 
55
+ def to_a
56
+ @a
57
+ end
58
+
55
59
  def to_xml
56
- Rexle.new(xmlize(@a)).xml if @a
60
+ Rexle.new(xmlize(@a).inject([:root, '', {}]){|r,x| r << x}).xml if @a
57
61
  end
58
62
 
59
63
  private
60
64
 
65
+ def join(lines, indent='')
66
+ lines.map do |x|
67
+ indent + (x.is_a?(Array) ? join(x, indent + ' ') : x)
68
+ end.join("\n")
69
+ end
70
+
61
71
  def scan(xpatterns, items)
62
72
 
63
73
  records = []
@@ -96,7 +106,9 @@ class LineParser
96
106
 
97
107
  def xmlize(rows)
98
108
 
99
- r = rows.map do |label, h, lines, children|
109
+ r = rows.map do |row|
110
+
111
+ label, h, lines, children = row
100
112
 
101
113
  new_h = h.inject({}) do |r,k|
102
114
 
@@ -110,11 +122,12 @@ class LineParser
110
122
  end
111
123
  end
112
124
 
113
- xml_children = children ? xmlize(children) : nil
114
- [label, join(lines), new_h, xml_children]
125
+ c = children ? xmlize(children) : []
126
+
127
+ [label, join(lines), new_h, *c]
115
128
  end
116
129
 
117
- r.flatten(1)
130
+ r
118
131
  end
119
132
 
120
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lineparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file