Class: Achoo::System::UTMPRecord

Inherits:
CStruct
  • Object
show all
Defined in:
lib/achoo/system/utmp_record.rb

Constant Summary collapse

TYPE_MAP =
[:empty,
 :run_lvl,
 :boot,
 :new_time,
 :old_time,
 :init,
 :login,
 :normal,
 :term,
 :account,
]

Instance Method Summary collapse

Methods inherited from CStruct

bin_size, char, inherited, #initialize, long, #pack, quad, short, string, #unpack

Constructor Details

This class inherits a constructor from Achoo::System::CStruct

Instance Method Details

#boot_event?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/achoo/system/utmp_record.rb', line 54

def boot_event?
  record_type_symbol == :boot
end

#halt_event?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/achoo/system/utmp_record.rb', line 58

def halt_event?
  record_type_symbol == :run_lvl && username == 'shutdown'
end

#record_type_symbolObject



42
43
44
# File 'lib/achoo/system/utmp_record.rb', line 42

def record_type_symbol
  TYPE_MAP[record_type]
end

#record_type_symbol=(sym) ⇒ Object



46
47
48
# File 'lib/achoo/system/utmp_record.rb', line 46

def record_type_symbol=(sym)
  @values[0] = (TYPE_MAP.find_index(sym))
end

#timeObject



37
38
39
40
# File 'lib/achoo/system/utmp_record.rb', line 37

def time
  return nil if seconds.nil?
  @time ||= Time.at(seconds, milliseconds)
end

#to_sObject



50
51
52
# File 'lib/achoo/system/utmp_record.rb', line 50

def to_s
  sprintf "%s  %-7s  %-8s %s", time.strftime('%F_%T'), record_type_symbol, username, device_name
end