rxraw-lineparser 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rxraw-lineparser.rb +13 -11
  2. metadata +2 -2
@@ -23,7 +23,6 @@ module Enumerable
23
23
  end
24
24
 
25
25
  class RXRawLineParser
26
-
27
26
 
28
27
  def initialize(format_mask)
29
28
  @format_mask = format_mask
@@ -34,7 +33,6 @@ class RXRawLineParser
34
33
  field_names = @format_mask.to_s.scan(/\[!(\w+)\]/).flatten.map(&:to_sym)
35
34
 
36
35
  patterns = possible_patterns(@format_mask)
37
- patterns.each{|x| puts x.inspect }
38
36
 
39
37
  pattern = patterns.detect {|x| line.match(/#{x.join}/)}.join
40
38
  field_values = line.match(/#{pattern}/).captures
@@ -60,6 +58,7 @@ class RXRawLineParser
60
58
  qpattern = %q{(["'][^"']+["'])}
61
59
 
62
60
  a = fmask_delimiters(format_mask)
61
+
63
62
  r = diminishing_permutation(main_fields)
64
63
 
65
64
  if r.length > 2 then
@@ -68,22 +67,26 @@ class RXRawLineParser
68
67
  else
69
68
  r2 = r
70
69
  end
71
-
72
- #puts 'r2'
73
- #r2.each{|x| puts x.inspect}
74
-
70
+
75
71
  rr = r2.map do |x|
76
- x.each_with_index.map do |item, i|
72
+ x2 = x.each_with_index.map do |item, i|
77
73
 
78
74
  d = a[i]
79
75
  case item
80
76
  when 1
81
- i > 0 ? d + qpattern : qpattern
77
+ qpattern
82
78
  when 0
83
- s = "([^%s]+)" % d
79
+ if d.length == 1 then
80
+ s = "([^%s]+)" % d
81
+ else
82
+ s = "(.*)(?=#{d})"
83
+ end
84
84
  i > 0 ? a[i-1] + s : s
85
85
  end
86
+
86
87
  end
88
+ x2.unshift '^' + x2.shift
89
+
87
90
  end
88
91
 
89
92
  rr.each{|x| puts x.inspect}
@@ -97,7 +100,7 @@ class RXRawLineParser
97
100
  else
98
101
  rrr = rr2 + rr[0..count-1] + rr[count..-1]
99
102
  end
100
-
103
+ rrr + [['(.*)']]
101
104
  end
102
105
 
103
106
  def diminishing_permutation(max_fields)
@@ -115,5 +118,4 @@ class RXRawLineParser
115
118
  a = f.split(/(?=\[!\w+\])/)[0..-2].map {|x| x[/\](.*)/,1] }
116
119
  end
117
120
 
118
-
119
121
  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.3
5
+ version: 0.1.4
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-04-25 00:00:00 +01:00
13
+ date: 2012-05-03 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16