Module: Nuggets::LogParser
- Extended by:
- LogParser
- Included in:
- LogParser
- Defined in:
- lib/nuggets/log_parser.rb,
lib/nuggets/log_parser/rails.rb,
lib/nuggets/log_parser/apache.rb
Defined Under Namespace
Constant Summary collapse
- GZ_EXT_RE =
%r{\.gz\z}
Class Method Summary collapse
Instance Method Summary collapse
- #parse(input) {|entry| ... } ⇒ Object
- #parse_file(file, &block) ⇒ Object
- #parse_line(line, entry = {}) ⇒ Object
Class Method Details
.register(base, *modules) ⇒ Object
36 37 38 39 |
# File 'lib/nuggets/log_parser.rb', line 36 def self.register(base, *modules) base.send(:include, *modules << self) base.extend(base) end |
Instance Method Details
#parse(input) {|entry| ... } ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# 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 = {}) ⇒ Object
54 55 56 57 |
# 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 |