linux_stat 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2b9ce6001721fb53594609195cab131b1012257ecc8ec8705d80bbfad10e930
4
- data.tar.gz: 0aeb2d9b11d871ffd82cd48ee8ca08b94620db5fd6e59c1d2b450c906b7da589
3
+ metadata.gz: 01f83a838dcd8dcb7e9a0777a68fbad83284103ddc12e8c1ef9a1358df7c4965
4
+ data.tar.gz: ba699f7a8bcb56469f44ab36e3a48888421dd23295287b56896f4c931c99a6e5
5
5
  SHA512:
6
- metadata.gz: 5d0f539696f3b58aa068c97636517c3f813b3359e8f45ac4a7f08f642d2c3478be5ca8998f2a293919b703900f3e5a8ea7a7b57b72ee0f58e2c6d783760c30cb
7
- data.tar.gz: 769195f4ea410fb4a856344632cd5fd0f191d40e3fb022ce0868c31723cdb203797c20357b9c022e1bb3e21f6c33b3a3275a852ed8abf78dc1cf7b6b1b9c6d80
6
+ metadata.gz: 7350b44b72c7385eb552d029668577c4cda06f1130104437e0baaf853cd119c8eb27aac99e7070a7191110faef4f3ba85773bcadf646485f94856b7ff859564e
7
+ data.tar.gz: 5ae2a2344cdff502a559e4feefd028feb0194fbfe63197f0969a78c87328077dc033acedf78f99844c338082937b3d72270f44666528fec45ee06ca129265431
@@ -17,7 +17,9 @@ module LinuxStat
17
17
  # Returns the total bytes received and transmitted as Hash.
18
18
  #
19
19
  # For example:
20
- # {:received=>56602867, :transmitted=>6940922}
20
+ # LinuxStat::Net.usage
21
+ #
22
+ # => {:received=>56602867, :transmitted=>6940922}
21
23
  #
22
24
  # But if the status isn't available it will return an empty Hash.
23
25
  def total_bytes
@@ -68,7 +70,9 @@ module LinuxStat
68
70
  # The return type is a Hash, containg the current internet usage (received, transmit) in B/s.
69
71
  #
70
72
  # For example:
71
- # {:received=>436060.0, :transmitted=>50350.0}
73
+ # LinuxStat::Net.usage
74
+ #
75
+ # => {:received=>436060.0, :transmitted=>50350.0}
72
76
  #
73
77
  # If the system transmits 100 kb in the interval,
74
78
  #
@@ -3,7 +3,9 @@ module LinuxStat
3
3
  class << self
4
4
  ##
5
5
  # Reads /etc/os-release and returns a Hash. For example:
6
- # {:NAME=>"Arch Linux", :PRETTY_NAME=>"Arch Linux", :ID=>"arch", :BUILD_ID=>"rolling", :ANSI_COLOR=>"38;2;23;147;209", :HOME_URL=>"https://www.archlinux.org/", :DOCUMENTATION_URL=>"https://wiki.archlinux.org/", :SUPPORT_URL=>"https://bbs.archlinux.org/", :BUG_REPORT_URL=>"https://bugs.archlinux.org/", :LOGO=>"archlinux"}
6
+ # LinuxStat::OS.os_release
7
+ #
8
+ # => {:NAME=>"Arch Linux", :PRETTY_NAME=>"Arch Linux", :ID=>"arch", :BUILD_ID=>"rolling", :ANSI_COLOR=>"38;2;23;147;209", :HOME_URL=>"https://www.archlinux.org/", :DOCUMENTATION_URL=>"https://wiki.archlinux.org/", :SUPPORT_URL=>"https://bbs.archlinux.org/", :BUG_REPORT_URL=>"https://bugs.archlinux.org/", :LOGO=>"archlinux"}
7
9
  #
8
10
  # If the info isn't available, it will return an empty Hash.
9
11
  #
@@ -13,13 +15,14 @@ module LinuxStat
13
15
  # Because changing the /etc/lsb-release
14
16
  # isn't expected in runtime.
15
17
  def os_release
16
- # cached (memoized) ; as changing the value in runtime is unexpected
17
18
  @@os_release ||= File.readable?('/etc/os-release') ? release('/etc/os-release') : {}
18
19
  end
19
20
 
20
21
  ##
21
22
  # Reads /etc/lsb-release and returns a Hash. For example:
22
- # {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
23
+ # LinuxStat::OS.lsb_release
24
+ #
25
+ # => {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
23
26
  #
24
27
  # If the info isn't available, it will return an empty Hash.
25
28
  #
@@ -28,7 +31,6 @@ module LinuxStat
28
31
  # The information is also cached, and once loaded, won't change in runtime.
29
32
  # Because changing the /etc/lsb-release isn't expected in runtime.
30
33
  def lsb_release
31
- # cached (memoized) ; as changing the value in runtime is unexpected
32
34
  @@lsb_release ||= File.readable?('/etc/lsb-release') ? release('/etc/lsb-release') : {}
33
35
  end
34
36
 
@@ -104,7 +106,9 @@ module LinuxStat
104
106
 
105
107
  ##
106
108
  # Reads /proc/uptime and returns the system uptime:
107
- # {:hour=>10, :minute=>34, :second=>12.59}
109
+ # LinuxStat::OS.uptime
110
+ #
111
+ # => {:hour=>10, :minute=>34, :second=>12.59}
108
112
  #
109
113
  # If the stat isn't available, an empty hash is returned.
110
114
  def uptime
@@ -158,9 +158,11 @@ module LinuxStat
158
158
  x = file_data[i]
159
159
 
160
160
  _lstripped = x.lstrip
161
- next if _lstripped == ?#.freeze || _lstripped.empty?
161
+ next if _lstripped[0] == ?#.freeze || _lstripped.empty?
162
+
163
+ if x[0] == ?\t.freeze
164
+ next unless vendor_id
162
165
 
163
- if x.start_with?(?\t.freeze)
164
166
  data = x.tap(&:strip!)
165
167
  device_id = data[/\A.*?\s/].to_s.strip
166
168
  device = data[device_id.length..-1].to_s.strip
@@ -173,7 +175,7 @@ module LinuxStat
173
175
  end
174
176
  end
175
177
 
176
- ret.freeze
178
+ ret
177
179
  else
178
180
  {}
179
181
  end
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION ||= "1.0.2"
2
+ VERSION ||= "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_stat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourav Goswami