lib/grok/match.rb in jls-grok-0.4.1 vs lib/grok/match.rb in jls-grok-0.4.2
- old
+ new
@@ -26,12 +26,12 @@
super
@captures = nil
end
- private
- def _get_captures
+ public
+ 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)
@@ -39,20 +39,25 @@
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)
- @captures[name] << data
+ yield name, data
end
grok_match_walk_end(self)
- end
+ end # def each_capture
public
def captures
- _get_captures if @captures.nil?
+ if @captures.nil?
+ @captures = Hash.new { |h,k| h[k] = [] }
+ each_capture do |key, val|
+ @captures[key] << val
+ end
+ end
return @captures
- end
+ end # def captures
public
def start
return self[:start]
end
@@ -63,13 +68,7 @@
end
public
def subject
return self[:subject]
- end
-
- public
- def each_capture
- _get_captures if @captures.nil?
- @captures.each { |k, v| yield([k, v]) }
end
end # Grok::Match