jls-grok 0.1.3068 → 0.2.3071

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.
Files changed (2) hide show
  1. data/lib/{pile.rb → grok/pile.rb} +14 -2
  2. metadata +4 -4
@@ -1,7 +1,10 @@
1
1
  require "grok"
2
2
 
3
- # A grok pile is an easy way to have multiple patterns together so that
4
- # you can try to match against each one.
3
+ # A grok pile is an easy way to have multiple patterns together so
4
+ # that you can try to match against each one.
5
+ # The API provided should be similar to the normal Grok
6
+ # interface, but you can compile multiple patterns and match will
7
+ # try each one until a match is found.
5
8
  class Grok::Pile
6
9
  def initialize
7
10
  @groks = []
@@ -9,10 +12,12 @@ class Grok::Pile
9
12
  @pattern_files = []
10
13
  end # def initialize
11
14
 
15
+ # see Grok#add_pattern
12
16
  def add_pattern(name, string)
13
17
  @patterns[name] = string
14
18
  end # def add_pattern
15
19
 
20
+ # see Grok#add_patterns_from_file
16
21
  def add_patterns_from_file(path)
17
22
  if !File.exists?(path)
18
23
  raise "File does not exist: #{path}"
@@ -20,6 +25,7 @@ class Grok::Pile
20
25
  @pattern_files << path
21
26
  end # def add_patterns_from_file
22
27
 
28
+ # see Grok#compile
23
29
  def compile(pattern)
24
30
  grok = Grok.new
25
31
  @patterns.each do |name, value|
@@ -32,12 +38,18 @@ class Grok::Pile
32
38
  @groks << grok
33
39
  end # def compile
34
40
 
41
+ # Slight difference from Grok#match in that it returns
42
+ # the Grok instance that matched successfully in addition
43
+ # to the GrokMatch result.
44
+ # See also: Grok#match
35
45
  def match(string)
36
46
  @groks.each do |grok|
37
47
  match = grok.match(string)
48
+ #puts "Trying #{grok.pattern} against #{string}"
38
49
  if match
39
50
  return [grok, match]
40
51
  end
41
52
  end
53
+ return false
42
54
  end # def match
43
55
  end # class Grok::Pile
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 3068
9
- version: 0.1.3068
7
+ - 2
8
+ - 3071
9
+ version: 0.2.3071
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jordan Sissel
@@ -57,7 +57,7 @@ files:
57
57
  - test/patterns/prog.rb
58
58
  - test/run.sh
59
59
  - lib/grok.rb
60
- - lib/pile.rb
60
+ - lib/grok/pile.rb
61
61
  has_rdoc: true
62
62
  homepage: http://code.google.com/p/semicomplete/wiki/Grok
63
63
  licenses: []