lineparser 0.1.5 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb48f3617f69e4b3d93dc16d98e61e1bdfa3ca24
4
- data.tar.gz: c907b97a9d725b94c2594fc6ab95a819a301f355
3
+ metadata.gz: a8dcffd28cdcec9e3e4824331aa1967d01fc3388
4
+ data.tar.gz: 2a5539f21080d32e4c99044cd9c8df7c4c89ea3e
5
5
  SHA512:
6
- metadata.gz: cd40a63253435f1c219c394d02745d7cffa2fa814913f97ad8204f6c6c3afe5c0bb4d70204d09de0676184da09abb8b0cfe1ad080ca85a272d24428830cfc2d3
7
- data.tar.gz: e2db55c194a8349b9e9d2a137eabf9226f024b0c7c8510d399b5503b81635c6cdca57f759f0bd71f78702d7402022179864fa349b6c0e807e0e2158c1ec129af
6
+ metadata.gz: 7a178971271b4b5180a49356ae7c0f71cf68d6dad73a3da546b459c4657c0d171f9c08c60835b81238c353e2fadd2c1d2ac0530bb892bf8f303a6203f1f16d46
7
+ data.tar.gz: 0b47f0079fdc3049287cd005b2979c9d0cacf04e7ed672e10cf6472fe8550a39667a7d4ddfb0afb3bd9d59b4be1546061fa7003ca6462f22f160f3d30ca6308b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,7 +7,7 @@ require 'line-tree'
7
7
 
8
8
  class LineParser
9
9
 
10
- def initialize(patterns=[])
10
+ def initialize(patterns=[], lines=nil)
11
11
 
12
12
  @h = {
13
13
 
@@ -44,10 +44,16 @@ class LineParser
44
44
 
45
45
  @tree_patterns = hpatterns[:root].reverse
46
46
 
47
+ parse lines if lines
48
+
47
49
  end
48
50
 
49
51
  def parse(s)
50
- scan @tree_patterns, LineTree.new(s).to_a
52
+ @a = scan @tree_patterns, LineTree.new(s).to_a
53
+ end
54
+
55
+ def to_xml
56
+ Rexle.new xmlize(@a) if @a
51
57
  end
52
58
 
53
59
  private
@@ -87,6 +93,30 @@ class LineParser
87
93
 
88
94
  return records
89
95
  end
96
+
97
+ def xmlize(rows)
98
+
99
+ r = rows.map do |label, h, lines, children|
100
+
101
+ new_h = h.inject({}) do |r,k|
102
+
103
+ if k.first == :captures then
104
+
105
+ k[-1].map.with_index.to_a.inject({}) do |r2,x|
106
+ r.merge! ('captures' + x[-1].to_s).to_sym => x[0]
107
+ end
108
+ else
109
+ r.merge k[0][/\w+/] => k[-1]
110
+ end
111
+ end
112
+
113
+ xml_children = children ? xmlize(children) : nil
114
+ [label, join(lines), new_h, xml_children]
115
+ end
116
+
117
+ r.flatten(1)
118
+ end
119
+
90
120
  end
91
121
 
92
122
 
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  91WD0+jYVX++HpUKNCp85+avduv17ztFqGGok26cpRFYNdIIFFu8T4cl2jsqGI2l
32
32
  hT3uS3yIJ12YEQ==
33
33
  -----END CERTIFICATE-----
34
- date: 2014-03-11 00:00:00.000000000 Z
34
+ date: 2014-03-12 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: line-tree
metadata.gz.sig CHANGED
Binary file