Class: Uptime
- Defined in:
- lib/panda_motd/components/uptime.rb
Instance Attribute Summary collapse
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#hours ⇒ Object
readonly
Returns the value of attribute hours.
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
Attributes inherited from Component
#config, #errors, #name, #results
Instance Method Summary collapse
-
#initialize(motd) ⇒ Uptime
constructor
A new instance of Uptime.
- #process ⇒ Object
- #to_s ⇒ Object
Methods inherited from Component
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
#days ⇒ Object (readonly)
Returns the value of attribute days.
4 5 6 |
# File 'lib/panda_motd/components/uptime.rb', line 4 def days @days end |
#hours ⇒ Object (readonly)
Returns the value of attribute hours.
4 5 6 |
# File 'lib/panda_motd/components/uptime.rb', line 4 def hours @hours end |
#minutes ⇒ Object (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
#process ⇒ Object
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_s ⇒ Object
18 19 20 |
# File 'lib/panda_motd/components/uptime.rb', line 18 def to_s "#{@config['prefix'] || 'up'} #{format_uptime}" end |