duffy 1.0.3 → 1.0.4

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: 7df1e7242cea2c5d050fd349e3ce7c1e62411748e3d4f2989abb06f556c60d2b
4
- data.tar.gz: a06ca07b4db45a9e22417573050e023f3f4c201baa539102043b5c966026ac16
3
+ metadata.gz: f9786d17563ae9168426b6f8f6ecc2cf9b4f8480789dd51a14f1f86d39d8be64
4
+ data.tar.gz: 3d43f1c5969e3ac08c4abc78339161bfe8368c53fd709fdaabb6395be2458d2b
5
5
  SHA512:
6
- metadata.gz: 5ee65d7c98b2e67b94156235b359e85ab358d17498c32352c4de4577a25b411ab27642406c8ccdd96084f2e9661ac6a1d3534c74e66b84e176f48a2faadd5519
7
- data.tar.gz: 2fd9aa7ce716a12cc82c70692f3ae4f6ef5b208a31d452970f94d648f51a64a4ca8e1f507526c53adef812402d64edb250af64c3012c10abf7f033dde6a76c12
6
+ metadata.gz: 1b95b5a3a177fd400e583e5550d9542780d3aef2e43b95a7764d456008efc697eeacbbe55fc499e5114bdc263c08a8267650d56319ae306202d9d6bff7fc29bd
7
+ data.tar.gz: 735886457662bdbb294bcb4f4b91fa688018698b74a52758e559febac35ba43002c8ce4b0e96477dadcaa2447c28da048f9b8c61efbf684bd21781b1d564a94f
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "duffy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/lib/duffy/system.rb CHANGED
@@ -92,6 +92,20 @@ module Duffy
92
92
  0
93
93
  end
94
94
 
95
+ # The battery percentage 0.0 .. 100.0
96
+ # nil if no battery or error reading value.
97
+ # Darwin: pmset -g batt
98
+ # Linux:
99
+ def battery_percent
100
+ case RUBY_PLATFORM
101
+ when /darwin/ then `pmset -g batt`.scan(/^.*\t(.*%);/)[0][0].to_f
102
+ when /linux/ then File.read("/sys/class/power_supply/BAT0/charge_now").to_i * 100 / File.read("/sys/class/power_supply/BAT0/charge_full").to_i
103
+ else nil
104
+ end
105
+ rescue
106
+ nil
107
+ end
108
+
95
109
  # Memory available for use in Megabytes
96
110
  # Darwin: vm_stat (Pages Free + Pages Inactive)
97
111
  # Linux: Read /proc/meminfo
@@ -119,6 +133,7 @@ module Duffy
119
133
  0
120
134
  end
121
135
 
136
+
122
137
  private
123
138
 
124
139
  # [CPU USE, CPU IDLE]
data/lib/duffy/version.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Duffy
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
4
4
 
5
5
  # History
6
+ # 1.0.4 - Added battery_percent method.
6
7
  # 1.0.3 - to_box methods now accept ANSI colored strings.
7
8
  # 1.0.2 - Added SimpleCov and added some more String tests.
8
9
  # 1.0.1 - Added String.to_box and Array.to_box. Nice for text banners.
data/spec/system_spec.rb CHANGED
@@ -3,10 +3,16 @@ describe Duffy::System do
3
3
 
4
4
  # These methods return per-host settings. Verify the return object type and value within reason.
5
5
  # This generates the documentation more than anything.
6
- describe "cpus" do
7
- it "returns the number of physical cpus" do
8
- expect(Duffy::System.cpus).to be_an(Integer)
9
- expect(Duffy::System.cpus).to be >= 1
6
+
7
+ describe "battery_percent" do
8
+ it "returns the percentage of battery remaining" do
9
+ expect([Float, nil]).to include Duffy::System.battery_percent.class
10
+ end
11
+ end
12
+
13
+ describe "cpu_percent" do
14
+ it "returns the current cpu load percentage" do
15
+ expect(Duffy::System.cpu_percent).to be_a(Float)
10
16
  end
11
17
  end
12
18
 
@@ -17,6 +23,13 @@ describe Duffy::System do
17
23
  end
18
24
  end
19
25
 
26
+ describe "cpus" do
27
+ it "returns the number of physical cpus" do
28
+ expect(Duffy::System.cpus).to be_an(Integer)
29
+ expect(Duffy::System.cpus).to be >= 1
30
+ end
31
+ end
32
+
20
33
  describe "freespace" do
21
34
  it "returns working directory freespace in megabytes" do
22
35
  expect(Duffy::System.freespace).to be_an(Integer)
@@ -24,23 +37,17 @@ describe Duffy::System do
24
37
  end
25
38
  end
26
39
 
27
-
28
- describe "threads" do
29
- it "returns the total number of threads" do
30
- expect(Duffy::System.threads).to be_an(Integer)
31
- expect(Duffy::System.threads).to be >= 1
32
- end
33
- end
34
-
35
- describe "virtual?" do
36
- it "returns true if in a hypervisor, false otherwise." do
37
- expect(Duffy::System.virtual?).to be_in [true, false]
40
+ describe 'mem_available' do
41
+ it "returns the amount of available memory in Megabytes" do
42
+ expect(Duffy::System.mem_available).to be_an(Integer)
43
+ expect(Duffy::System.mem_available).to be > 0
38
44
  end
39
45
  end
40
46
 
41
- describe "cpu_percent" do
42
- it "returns the current cpu load percentage" do
43
- expect(Duffy::System.cpu_percent).to be_a(Float)
47
+ describe 'mem_percent' do
48
+ it "returns the amount of used memory as a percentage of total" do
49
+ expect(Duffy::System.mem_percent).to be_a(Float)
50
+ expect(Duffy::System.mem_percent).to be > 0
44
51
  end
45
52
  end
46
53
 
@@ -51,13 +58,6 @@ describe Duffy::System do
51
58
  end
52
59
  end
53
60
 
54
- describe 'mem_available' do
55
- it "returns the amount of available memory in Megabytes" do
56
- expect(Duffy::System.mem_available).to be_an(Integer)
57
- expect(Duffy::System.mem_available).to be > 0
58
- end
59
- end
60
-
61
61
  describe 'mem_used' do
62
62
  it "returns the amount of used memory in Megabytes" do
63
63
  expect(Duffy::System.mem_used).to be_an(Integer)
@@ -65,12 +65,17 @@ describe Duffy::System do
65
65
  end
66
66
  end
67
67
 
68
- describe 'mem_percent' do
69
- it "returns the amount of used memory as a percentage of total" do
70
- expect(Duffy::System.mem_percent).to be_a(Float)
71
- expect(Duffy::System.mem_percent).to be > 0
68
+ describe "threads" do
69
+ it "returns the total number of threads" do
70
+ expect(Duffy::System.threads).to be_an(Integer)
71
+ expect(Duffy::System.threads).to be >= 1
72
72
  end
73
73
  end
74
74
 
75
+ describe "virtual?" do
76
+ it "returns true if in a hypervisor, false otherwise." do
77
+ expect(Duffy::System.virtual?).to be_in [true, false]
78
+ end
79
+ end
75
80
 
76
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -97,7 +97,8 @@ dependencies:
97
97
  description: Random collection of useful things.
98
98
  email:
99
99
  - duffy.jp@gmail.com
100
- executables: []
100
+ executables:
101
+ - console
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
@@ -109,6 +110,7 @@ files:
109
110
  - LICENSE.txt
110
111
  - README.md
111
112
  - Rakefile
113
+ - bin/console
112
114
  - doc/abc.png
113
115
  - doc/abc123.png
114
116
  - duffy.gemspec
@@ -152,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  - !ruby/object:Gem::Version
153
155
  version: '0'
154
156
  requirements: []
155
- rubygems_version: 3.0.1
157
+ rubygems_version: 3.0.3
156
158
  signing_key:
157
159
  specification_version: 4
158
160
  summary: Library of things