module RaspbergUptime
RaspbergUptime — VB-style uptime formatting and /proc/uptime reader.
Public Instance Methods
Source
# File lib/raspberg_uptime.rb, line 16 def default_uptime_reader -> { begin File.read("/proc/uptime") rescue StandardError nil end } end
Source
# File lib/raspberg_uptime.rb, line 70 def format_labeled_minutes(label, minutes) formatted = format_minutes_vb(minutes) "#{label}#{formatted}" end
Source
# File lib/raspberg_uptime.rb, line 30 def format_minutes_vb(minutes) uptime = minutes.to_f return "Under one minute" if uptime < 1 caption = String.new case uptime when 1..60 temp = uptime.floor caption << (temp == 1 ? "#{temp} Minute" : "#{temp} Minutes") when 60..1440 temp = (uptime / 60).floor uptime -= temp * 60 caption << (temp == 1 ? "#{temp} Hour and " : "#{temp} Hours and ") temp = uptime.floor caption << (temp == 1 ? "#{temp} Minute" : "#{temp} Minutes") when 1440..10_080 temp = (uptime / 60 / 24).floor uptime -= temp * 24 * 60 caption << (temp == 1 ? "#{temp} Day, " : "#{temp} Days, ") temp = (uptime / 60).floor uptime -= temp * 60 caption << (temp == 1 ? "#{temp} Hour and " : "#{temp} Hours and ") temp = uptime.floor caption << (temp == 1 ? "#{temp} Minute" : "#{temp} Minutes") else temp = (uptime / 60 / 24 / 7).floor uptime -= temp * 60 * 24 * 7 caption << (temp == 1 ? "#{temp} Week, " : "#{temp} Weeks, ") temp = (uptime / 60 / 24).floor uptime -= temp * 24 * 60 caption << (temp == 1 ? "#{temp} Day, " : "#{temp} Days, ") temp = (uptime / 60).floor uptime -= temp * 60 caption << (temp == 1 ? "#{temp} Hour and " : "#{temp} Hours and ") temp = uptime.floor caption << (temp == 1 ? "#{temp} Minute" : "#{temp} Minutes") end caption end
Source
# File lib/raspberg_uptime.rb, line 26 def minutes_from_seconds(seconds) seconds.to_f / 60.0 end
Source
# File lib/raspberg_uptime.rb, line 9 def read_seconds(uptime_reader: default_uptime_reader) text = uptime_reader.call return 0.0 if text.nil? || text.to_s.strip.empty? FartSystem.parse_uptime(text) end