Class: AirportEvents::KernelLogParser

Inherits:
Object
  • Object
show all
Includes:
Publisher
Defined in:
lib/airport_events/kernel_log_parser.rb

Instance Method Summary collapse

Methods included from Publisher

included

Constructor Details

#initializeKernelLogParser

Returns a new instance of KernelLogParser.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/airport_events/kernel_log_parser.rb', line 8

def initialize
  Thread.new do
    File.open('/var/log/kernel.log') do |log|
      log.extend(File::Tail)
      log.interval = 10
      log.backward(0)
      log.tail do |line| 

        if event = match_event(line)
          publish event, DateTime.strptime(line[0..15], '%b %d %H:%M:%S')
        end
      end
    end
  end
end

Instance Method Details

#match_event(line) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/airport_events/kernel_log_parser.rb', line 24

def match_event line
  if line.match /AirPort: Link Up.*/
    :connected
  elsif line.match /AirPort: Link Down.*/
    :disconnected
  end
end