Class: Achoo::System::Wtmp

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

Instance Method Summary collapse

Methods inherited from Array

#merge!

Constructor Details

#initialize(glob = '/var/log/wtmp*') ⇒ Wtmp

Returns a new instance of Wtmp.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/achoo/system/wtmp.rb', line 8

def initialize(glob='/var/log/wtmp*')
  super()
  chunk_size = UTMPRecord.bin_size
  Dir.glob(glob).sort.reverse.each do |file|
    File.open(file, 'r') do |io|
      while (bytes = io.read(chunk_size)) 
        self << UTMPRecord.new(bytes)
      end
    end
  end
end

Instance Method Details

#to_sObject



20
21
22
# File 'lib/achoo/system/wtmp.rb', line 20

def to_s
  inject('') {|str, e| str << e.to_s << "\n"}
end