Class: Uptime

Inherits:
Component show all
Defined in:
lib/panda_motd/components/uptime.rb

Instance Attribute Summary collapse

Attributes inherited from Component

#config, #errors, #name, #results

Instance Method Summary collapse

Methods inherited from Component

#lines_after, #lines_before

Constructor Details

#initialize(motd) ⇒ Uptime

Returns a new instance of Uptime.



6
7
8
# File 'lib/panda_motd/components/uptime.rb', line 6

def initialize(motd)
  super(motd, 'uptime')
end

Instance Attribute Details

#daysObject (readonly)

Returns the value of attribute days.



4
5
6
# File 'lib/panda_motd/components/uptime.rb', line 4

def days
  @days
end

#hoursObject (readonly)

Returns the value of attribute hours.



4
5
6
# File 'lib/panda_motd/components/uptime.rb', line 4

def hours
  @hours
end

#minutesObject (readonly)

Returns the value of attribute minutes.



4
5
6
# File 'lib/panda_motd/components/uptime.rb', line 4

def minutes
  @minutes
end

Instance Method Details

#processObject



10
11
12
13
14
15
16
# File 'lib/panda_motd/components/uptime.rb', line 10

def process
  uptime = SysInfo.new.uptime

  @days = (uptime / 24).floor
  @hours = (uptime - @days * 24).floor
  @minutes = ((uptime - @days * 24 - hours) * 60).floor
end

#to_sObject



18
19
20
# File 'lib/panda_motd/components/uptime.rb', line 18

def to_s
  "#{@config['prefix'] || 'up'} #{format_uptime}"
end