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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/lineparser.rb +32 -2
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8dcffd28cdcec9e3e4824331aa1967d01fc3388
|
4
|
+
data.tar.gz: 2a5539f21080d32e4c99044cd9c8df7c4c89ea3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a178971271b4b5180a49356ae7c0f71cf68d6dad73a3da546b459c4657c0d171f9c08c60835b81238c353e2fadd2c1d2ac0530bb892bf8f303a6203f1f16d46
|
7
|
+
data.tar.gz: 0b47f0079fdc3049287cd005b2979c9d0cacf04e7ed672e10cf6472fe8550a39667a7d4ddfb0afb3bd9d59b4be1546061fa7003ca6462f22f160f3d30ca6308b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/lineparser.rb
CHANGED
@@ -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.
|
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-
|
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
|