rxraw-lineparser 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rxraw-lineparser.rb +25 -1
- metadata +3 -5
data/lib/rxraw-lineparser.rb
CHANGED
@@ -35,7 +35,11 @@ class RXRawLineParser
|
|
35
35
|
|
36
36
|
patterns = possible_patterns(@format_mask)
|
37
37
|
#patterns.each{|x| puts x.inspect}
|
38
|
+
if field_names.map{|x| "[!%s]" % x}.join(' ') == @format_mask then
|
39
|
+
insert2space_patterns(field_names.length, patterns)
|
40
|
+
end
|
38
41
|
|
42
|
+
#patterns.each{|x| puts x.inspect}
|
39
43
|
pattern = patterns.detect {|x| line.match(/#{x.join}/)}.join
|
40
44
|
end_part = @format_mask[/[^\]]+$/].to_s
|
41
45
|
pattern += end_part
|
@@ -55,6 +59,26 @@ class RXRawLineParser
|
|
55
59
|
|
56
60
|
private
|
57
61
|
|
62
|
+
def insert2space_patterns(field_count, patterns)
|
63
|
+
|
64
|
+
a = (field_count-2).times.inject([2]) do |r,x|
|
65
|
+
v = 2 ** (x + 3)
|
66
|
+
diff = field_count - 2
|
67
|
+
r << (diff >= x+1 ? v-1 : v)
|
68
|
+
end
|
69
|
+
|
70
|
+
unit = ['([^\s]+)\s{2,}']
|
71
|
+
|
72
|
+
space2_patterns = a.map.with_index do |x,i|
|
73
|
+
[x,(['^'] + Array.new(i+1,unit).concat(['(.*)'])).flatten]
|
74
|
+
end
|
75
|
+
|
76
|
+
space2_patterns.each_with_index do |x_line, i|
|
77
|
+
x, line = x_line
|
78
|
+
patterns = patterns.insert(patterns.length - x-i-2, line)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
58
82
|
def possible_patterns(format_mask)
|
59
83
|
|
60
84
|
part1 = format_mask[/^[^\[]+/].to_s
|
@@ -81,7 +105,7 @@ class RXRawLineParser
|
|
81
105
|
d = a[i]
|
82
106
|
case item
|
83
107
|
when 1
|
84
|
-
qpattern
|
108
|
+
qpattern #+ d
|
85
109
|
when 0
|
86
110
|
if d.length == 1 then
|
87
111
|
if i < x.length - 1 then
|
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.10
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
14
|
-
default_executable:
|
13
|
+
date: 2012-11-15 00:00:00 Z
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description:
|
@@ -24,7 +23,6 @@ extra_rdoc_files: []
|
|
24
23
|
|
25
24
|
files:
|
26
25
|
- lib/rxraw-lineparser.rb
|
27
|
-
has_rdoc: true
|
28
26
|
homepage:
|
29
27
|
licenses: []
|
30
28
|
|
@@ -48,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
46
|
requirements: []
|
49
47
|
|
50
48
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.
|
49
|
+
rubygems_version: 1.8.23
|
52
50
|
signing_key:
|
53
51
|
specification_version: 3
|
54
52
|
summary: rxraw-lineparser
|