Class: Achoo::System::PMSuspend

Inherits:
Array
  • Object
show all
Defined in:
lib/achoo/system/pm_suspend.rb

Instance Method Summary collapse

Methods inherited from Array

#merge!

Constructor Details

#initialize(glob = '/var/log/pm-suspend.log*') ⇒ PMSuspend

Returns a new instance of PMSuspend.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/achoo/system/pm_suspend.rb', line 9

def initialize(glob='/var/log/pm-suspend.log*')
  super()
  Dir.glob(glob).sort.reverse.each do |file|
    next if file =~ /\.gz$/ # FIX uncompress?
    File.open(file, 'r') do |fh|
      fh.readlines.each do |l|
        l.chop!
        next unless l =~ /Awake|performing suspend/
        time, event = *l.split(': ')
        time = Time.parse(time)
        self << LogEntry.new(time, event == 'Awake.' ? :awake : :suspend)
      end
    end
  end
end