sys-uptime 0.5.4-x86-mingw32 → 0.6.0-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,101 +0,0 @@
1
- # The Sys module serves as a namespace only.
2
- module Sys
3
-
4
- # The Uptime class encapsulates various bits of information regarding your
5
- # system's uptime, including boot time.
6
- class Uptime
7
-
8
- # Error typically raised in one of the Uptime methods should fail.
9
- class Error < StandardError; end
10
-
11
- # The version of the sys-uptime library.
12
- VERSION = '0.5.4'
13
-
14
- # The file to read uptime information from.
15
- UPTIME_FILE = '/proc/uptime'
16
-
17
- # Returns the total number of seconds of uptime.
18
- #
19
- # Example:
20
- #
21
- # Sys::Uptime.seconds # => 118800
22
- #
23
- def self.seconds
24
- begin
25
- IO.read(UPTIME_FILE).split.first.to_i
26
- rescue Exception => err
27
- raise Error, err
28
- end
29
- end
30
-
31
- # Returns the total number of minutes of uptime.
32
- #
33
- # Example:
34
- #
35
- # Sys::Uptime.minutes # => 678
36
- #
37
- def self.minutes
38
- self.seconds / 60
39
- end
40
-
41
- # Returns the total number of hours of uptime.
42
- #
43
- # Example:
44
- #
45
- # Sys::Uptime.hours # => 31
46
- #
47
- def self.hours
48
- self.minutes / 60
49
- end
50
-
51
- # Returns the total number of days of uptime.
52
- #
53
- # Example:
54
- #
55
- # Sys::Uptime.days # => 2
56
- #
57
- def self.days
58
- self.hours / 24
59
- end
60
-
61
- # Returns the uptime as a colon separated string, including days,
62
- # hours, minutes and seconds.
63
- #
64
- # Example:
65
- #
66
- # Sys::Uptime.uptime # => "1:9:24:57"
67
- #
68
- def self.uptime
69
- seconds = self.seconds
70
- days = seconds / 86400
71
- seconds -= days * 86400
72
- hours = seconds / 3600
73
- seconds -= hours * 3600
74
- minutes = seconds / 60
75
- seconds -= minutes * 60
76
-
77
- "#{days}:#{hours}:#{minutes}:#{seconds}"
78
- end
79
-
80
- # Returns the uptime as a four element array, including days, hours,
81
- # minutes and seconds.
82
- #
83
- # Example:
84
- #
85
- # Sys::Uptime.dhms # => [1,9,24,57]
86
- #
87
- def self.dhms
88
- self.uptime.split(":")
89
- end
90
-
91
- # Returns the time the system was booted as a Time object.
92
- #
93
- # Example:
94
- #
95
- # Sys::Uptime.boot_time
96
- #
97
- def self.boot_time
98
- Time.now - self.seconds
99
- end
100
- end
101
- end