rxraw-lineparser 0.1.4 → 0.1.5
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.
- data/lib/rxraw-lineparser.rb +25 -14
- metadata +2 -2
data/lib/rxraw-lineparser.rb
CHANGED
@@ -23,6 +23,7 @@ module Enumerable
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class RXRawLineParser
|
26
|
+
|
26
27
|
|
27
28
|
def initialize(format_mask)
|
28
29
|
@format_mask = format_mask
|
@@ -33,9 +34,10 @@ class RXRawLineParser
|
|
33
34
|
field_names = @format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
|
34
35
|
|
35
36
|
patterns = possible_patterns(@format_mask)
|
36
|
-
|
37
|
+
#patterns.each{|x| puts x.inspect}
|
38
|
+
|
37
39
|
pattern = patterns.detect {|x| line.match(/#{x.join}/)}.join
|
38
|
-
field_values = line.match(/#{pattern}/).captures
|
40
|
+
field_values = line.match(/#{pattern}/).captures.map(&:strip)
|
39
41
|
|
40
42
|
found_quotes = find_qpattern(pattern)
|
41
43
|
|
@@ -51,9 +53,11 @@ class RXRawLineParser
|
|
51
53
|
private
|
52
54
|
|
53
55
|
def possible_patterns(format_mask)
|
54
|
-
|
56
|
+
|
57
|
+
part1 = format_mask[/^[^\[]+/].to_s
|
58
|
+
|
55
59
|
tot_fields = format_mask.scan(/\[!\w+\]/).length
|
56
|
-
return [['(.*)']] if tot_fields <= 1
|
60
|
+
return [[part1 + '(.*)']] if tot_fields <= 1
|
57
61
|
main_fields = tot_fields - 1
|
58
62
|
qpattern = %q{(["'][^"']+["'])}
|
59
63
|
|
@@ -74,25 +78,31 @@ class RXRawLineParser
|
|
74
78
|
d = a[i]
|
75
79
|
case item
|
76
80
|
when 1
|
77
|
-
|
81
|
+
qpattern
|
78
82
|
when 0
|
79
83
|
if d.length == 1 then
|
80
|
-
|
84
|
+
if i < x.length - 1 then
|
85
|
+
s = "([^%s]+)%s" % ([d]*2)
|
86
|
+
else
|
87
|
+
s = "([^%s]+)" % d
|
88
|
+
end
|
81
89
|
else
|
82
|
-
s = "(.*)(?=#{d})"
|
90
|
+
s = i < x.length - 1 ? "(.*)(?=#{d})#{d}" : "(.*)"
|
83
91
|
end
|
84
|
-
|
92
|
+
s
|
85
93
|
end
|
86
94
|
|
87
95
|
end
|
88
|
-
|
96
|
+
|
97
|
+
r = x2.unshift '^' + part1 + x2.shift
|
89
98
|
|
90
99
|
end
|
91
100
|
|
92
|
-
rr.each{|x| puts x.inspect}
|
101
|
+
#rr.each{|x| puts x.inspect}
|
93
102
|
|
94
103
|
count = 2**main_fields
|
95
|
-
|
104
|
+
|
105
|
+
rr2 = rr.take(count+1).map {|x| x + ['(.*)']}
|
96
106
|
|
97
107
|
if rr.length > 2 then
|
98
108
|
wild_r = rr2.slice!(-1)
|
@@ -100,7 +110,7 @@ class RXRawLineParser
|
|
100
110
|
else
|
101
111
|
rrr = rr2 + rr[0..count-1] + rr[count..-1]
|
102
112
|
end
|
103
|
-
rrr + [['(.*)']]
|
113
|
+
rrr + [[part1 + '(.*)']]
|
104
114
|
end
|
105
115
|
|
106
116
|
def diminishing_permutation(max_fields)
|
@@ -110,12 +120,13 @@ class RXRawLineParser
|
|
110
120
|
end
|
111
121
|
|
112
122
|
def find_qpattern(s)
|
113
|
-
s.split(/(?=\([
|
123
|
+
s.split(/(?=\(\?=)|(?=\(\[")/).map.with_index\
|
114
124
|
.select{|x,i| x[/\["'\]\[\^"'\]\+\["'\]/] }.map(&:last)
|
115
125
|
end
|
116
126
|
|
117
127
|
def fmask_delimiters(f)
|
118
|
-
a = f.split(/(?=\[!\w+\])/)[0..-2].map {|x| x[/\](.*)/,1] }
|
128
|
+
a = f.split(/(?=\[!\w+\])/)[0..-2].map {|x| x[/\](.*)/,1] }.compact
|
119
129
|
end
|
120
130
|
|
131
|
+
|
121
132
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rxraw-lineparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-06 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|