Class: Grok::Match

Inherits:
FFI::Struct
  • Object
show all
Includes:
CGrokMatch
Defined in:
lib/grok/match.rb

Defined Under Namespace

Modules: CGrokMatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatch

Returns a new instance of Match.



31
32
33
34
35
# File 'lib/grok/match.rb', line 31

def initialize
  super

  @captures = nil
end

Instance Attribute Details

#subject_memorypointerObject

Placeholder for the FFI::MemoryPointer that we pass to grok_execn() during Grok#match; this should prevent ruby from garbage collecting us until the GrokMatch goes out of scope. code.google.com/p/logstash/issues/detail?id=47



28
29
30
# File 'lib/grok/match.rb', line 28

def subject_memorypointer
  @subject_memorypointer
end

Instance Method Details

#capturesObject



56
57
58
59
60
61
62
63
64
# File 'lib/grok/match.rb', line 56

def captures
  if @captures.nil?
    @captures = Hash.new { |h,k| h[k] = [] }
    each_capture do |key, val|
      @captures[key] << val
    end
  end
  return @captures
end

#each_captureObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/grok/match.rb', line 38

def each_capture
  @captures = Hash.new { |h, k| h[k] = Array.new }
  grok_match_walk_init(self)
  name_ptr = FFI::MemoryPointer.new(:pointer)
  namelen_ptr = FFI::MemoryPointer.new(:int)
  data_ptr = FFI::MemoryPointer.new(:pointer)
  datalen_ptr = FFI::MemoryPointer.new(:int)
  while grok_match_walk_next(self, name_ptr, namelen_ptr, data_ptr, datalen_ptr) == Grok::GROK_OK
    namelen = namelen_ptr.read_int
    name = name_ptr.get_pointer(0).get_string(0, namelen)
    datalen = datalen_ptr.read_int
    data = data_ptr.get_pointer(0).get_string(0, datalen)
    yield name, data
  end
  grok_match_walk_end(self)
end

#endObject



72
73
74
# File 'lib/grok/match.rb', line 72

def end
  return self[:end]
end

#startObject



67
68
69
# File 'lib/grok/match.rb', line 67

def start
  return self[:start]
end

#subjectObject



77
78
79
# File 'lib/grok/match.rb', line 77

def subject
  return self[:subject]
end