module Nuggets::LogParser
Constants
- GZ_EXT_RE
Public Class Methods
register(base, *modules)
click to toggle source
# File lib/nuggets/log_parser.rb 36 def self.register(base, *modules) 37 base.send(:include, *modules << self) 38 base.extend(base) 39 end
Public Instance Methods
parse(input) { |dup| ... }
click to toggle source
# File lib/nuggets/log_parser.rb 41 def parse(input) 42 entry = {} 43 44 input.each { |line| parse_line(line, entry) { 45 unless entry.empty? 46 yield entry.dup 47 entry.clear 48 end 49 } } 50 51 yield entry unless entry.empty? 52 end
parse_file(file, &block)
click to toggle source
# File lib/nuggets/log_parser.rb 59 def parse_file(file, &block) 60 block ||= (entries = []; lambda { |entry| entries << entry }) 61 62 (file =~ GZ_EXT_RE ? Zlib::GzipReader : ::File).open(file) { |f| 63 block.arity == 1 ? parse(f, &block) : block[f, method(:parse)] 64 } 65 66 entries 67 end
parse_line(line, entry = {})
click to toggle source
# File lib/nuggets/log_parser.rb 54 def parse_line(line, entry = {}) 55 # Yield when entry complete. Preferrably return +entry+. 56 raise NotImplementedError, 'must be implemented by type' 57 end