Class: Evidence::LogParser

Inherits:
Object
  • Object
show all
Defined in:
lib/evidence/log_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, unmatched) ⇒ LogParser



3
4
5
# File 'lib/evidence/log_parser.rb', line 3

def initialize(pattern, unmatched)
  @pattern, @unmatched = pattern, unmatched
end

Instance Method Details

#[](output) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/evidence/log_parser.rb', line 7

def [](output)
  lambda do |line|
    if m = @pattern.match(line)
      output.call(to_hash(m))
    else
      @unmatched.call(line)
    end
  end
end

#to_hash(m) ⇒ Object



17
18
19
# File 'lib/evidence/log_parser.rb', line 17

def to_hash(m)
  Hash[m.names.map(&:to_sym).zip(m.captures)]
end