module Nuggets::LogParser

Constants

GZ_EXT_RE

Public Class Methods

register(base, *modules) click to toggle source
# File lib/nuggets/log_parser.rb, line 36
def self.register(base, *modules)
  base.send(:include, *modules << self)
  base.extend(base)
end

Public Instance Methods

parse(input) { |dup| ... } click to toggle source
# File lib/nuggets/log_parser.rb, line 41
def parse(input)
  entry = {}

  input.each { |line| parse_line(line, entry) {
    unless entry.empty?
      yield entry.dup
      entry.clear
    end
  } }

  yield entry unless entry.empty?
end
parse_file(file, &block) click to toggle source
# File lib/nuggets/log_parser.rb, line 59
def parse_file(file, &block)
  block ||= (entries = []; lambda { |entry| entries << entry })

  (file =~ GZ_EXT_RE ? Zlib::GzipReader : ::File).open(file) { |f|
    block.arity == 1 ? parse(f, &block) : block[f, method(:parse)]
  }

  entries
end
parse_line(line, entry = {}) click to toggle source
# File lib/nuggets/log_parser.rb, line 54
def parse_line(line, entry = {})
  # Yield when entry complete. Preferrably return +entry+.
  raise NotImplementedError, 'must be implemented by type'
end