Class: Evidence::LogParser
- Inherits:
-
Object
- Object
- Evidence::LogParser
- Defined in:
- lib/evidence/log_parser.rb
Instance Method Summary collapse
- #[](block) ⇒ Object
-
#initialize(pattern, unmatched) ⇒ LogParser
constructor
A new instance of LogParser.
- #single_pattern_parser(block) ⇒ Object
- #to_hash(m) ⇒ Object
Constructor Details
#initialize(pattern, unmatched) ⇒ LogParser
Returns a new instance of LogParser.
3 4 5 |
# File 'lib/evidence/log_parser.rb', line 3 def initialize(pattern, unmatched) @pattern, @unmatched = pattern, unmatched end |
Instance Method Details
#[](block) ⇒ Object
7 8 9 |
# File 'lib/evidence/log_parser.rb', line 7 def [](block) single_pattern_parser(block) end |
#single_pattern_parser(block) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/evidence/log_parser.rb', line 11 def single_pattern_parser(block) lambda do |line| if m = @pattern.match(line) block.call(to_hash(m)) else @unmatched.call(line) end end end |
#to_hash(m) ⇒ Object
21 22 23 |
# File 'lib/evidence/log_parser.rb', line 21 def to_hash(m) Hash[m.names.map(&:to_sym).zip(m.captures)] end |