battery_growl 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/battery_growl.gemspec +25 -0
- data/bin/battery_growl +15 -0
- data/lib/battery_growl.rb +2 -0
- data/lib/battery_growl/battery_growl.rb +44 -0
- data/lib/battery_growl/version.rb +3 -0
- data/spec/battery_growl_spec.rb +149 -0
- data/spec/spec_helper.rb +2 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64457f91b044d64beec0dc779f78a3cca538cfc7
|
4
|
+
data.tar.gz: 9326460212d7aef54167dc55f4355bfa8158ea70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e86520e60713c90095201560330d6b460eb416623ae8474d446726884ef3bc744ad38b4081812ac929494b68782da5d4229fc934f78056f82d6be11d0eb2a03f
|
7
|
+
data.tar.gz: 3c31e81768a2457c270d47409571cf4fc4e4d7671b04bf99d56d891c40b093422acbd8ba7d43e0649b43bb3c6ab90ef60767cc72695d530aaf8c849cbb15bdef
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 youyo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# BatteryGrowl
|
2
|
+
|
3
|
+
When the MacBookAir's battery is running low, notify the growl.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'battery_growl'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install battery_growl
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
$ battery_growl [num]
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'battery_growl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "battery_growl"
|
8
|
+
spec.version = BatteryGrowl::VERSION
|
9
|
+
spec.authors = ["youyo"]
|
10
|
+
spec.email = ["1003ni2@gmail.com"]
|
11
|
+
spec.description = %q{When the MacBookAir's battery is running low, notify the growl.}
|
12
|
+
spec.summary = %q{When the MacBookAir's battery is running low, notify the growl.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_dependency "ruby-growl"
|
25
|
+
end
|
data/bin/battery_growl
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ruby-growl'
|
2
|
+
|
3
|
+
class BatteryGrowl
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def run(percent=10,host='localhost')
|
9
|
+
num_check(percent)
|
10
|
+
battery_usage = check_battery
|
11
|
+
subject = 'バッテリー容量低下'
|
12
|
+
message = "残り#{battery_usage}%です。充電してください。"
|
13
|
+
post_growl(subject,message,host) if battery_usage <= percent
|
14
|
+
return true
|
15
|
+
rescue => e
|
16
|
+
raise "#{e}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def num_check(num)
|
22
|
+
raise 'Parameter is less than 1.' if num < 1
|
23
|
+
raise 'Parameter is greater than 100.' if num > 100
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_battery
|
28
|
+
cmd = "pmset -g batt|grep 'InternalBattery'|awk '{print $2}'|cut -d'%' -f1"
|
29
|
+
usage = `#{cmd}`.to_i
|
30
|
+
return usage
|
31
|
+
rescue => e
|
32
|
+
raise "#{e}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_growl(subject,message,host)
|
36
|
+
g = Growl.new host, "ruby-growl"
|
37
|
+
g.add_notification("notification", "ruby-growl Notification")
|
38
|
+
g.notify "notification", subject, message
|
39
|
+
return true
|
40
|
+
rescue => e
|
41
|
+
raise "#{e}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
describe BatteryGrowl do
|
2
|
+
|
3
|
+
describe 'VERSION' do
|
4
|
+
|
5
|
+
it 'should be 0.0.1' do
|
6
|
+
expect( BatteryGrowl::VERSION ).to eql('0.0.1')
|
7
|
+
end
|
8
|
+
it 'should be a String' do
|
9
|
+
expect( BatteryGrowl::VERSION ).to be_a(String)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'public method' do
|
15
|
+
|
16
|
+
describe '#run' do
|
17
|
+
|
18
|
+
context 'When the battery level was 20% or less, ' do
|
19
|
+
|
20
|
+
context 'growl is not running' do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
@battery_growl = BatteryGrowl.new
|
24
|
+
@battery_growl.stub(:check_battery).and_return(10)
|
25
|
+
@battery_growl.stub(:post_growl).with('バッテリー容量低下',"残り10%です。充電してください。",'localhost').and_raise
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'return RuntimeError' do
|
29
|
+
expect{ @battery_growl.run(20) }.to raise_error(RuntimeError)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'growl is running' do
|
35
|
+
|
36
|
+
before(:each) do
|
37
|
+
@battery_growl = BatteryGrowl.new
|
38
|
+
@battery_growl.stub(:check_battery).and_return(10)
|
39
|
+
@battery_growl.stub(:post_growl).with('バッテリー容量低下',"残り10%です。充電してください。",'localhost').and_return(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'return true' do
|
43
|
+
expect( @battery_growl.run(20) ).to be(true)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'When the battery level was more than 20%, ' do
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
@battery_growl = BatteryGrowl.new
|
54
|
+
@battery_growl.stub(:check_battery).and_return(30)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'return true' do
|
58
|
+
expect( @battery_growl.run(20) ).to be(true)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'private method' do
|
68
|
+
|
69
|
+
describe '#num_check' do
|
70
|
+
|
71
|
+
before(:each) do
|
72
|
+
@battery_growl = BatteryGrowl.new
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when the number is less than 1, ' do
|
76
|
+
it 'raise RuntimeError' do
|
77
|
+
expect{ @battery_growl.send(:num_check, 0) }.to raise_error(RuntimeError,'Parameter is less than 1.')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when the number is greater than 100, ' do
|
83
|
+
it 'raise RuntimeError' do
|
84
|
+
expect{ @battery_growl.send(:num_check, 101) }.to raise_error(RuntimeError,'Parameter is greater than 100.')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when the number is between 1 and 100, ' do
|
89
|
+
it 'return true' do
|
90
|
+
expect( @battery_growl.send(:num_check, 1) ).to be(true)
|
91
|
+
expect( @battery_growl.send(:num_check, 100) ).to be(true)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#check_battery' do
|
98
|
+
|
99
|
+
before(:each) do
|
100
|
+
@battery_growl = BatteryGrowl.new
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'return Integer from 1 to 100' do
|
104
|
+
expect( @battery_growl.send(:check_battery) ).to be_within(100).of(1)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#post_growl' do
|
110
|
+
|
111
|
+
context 'when growl is not running, ' do
|
112
|
+
|
113
|
+
before(:each) do
|
114
|
+
allow_message_expectations_on_nil
|
115
|
+
Growl.stub(:new).with('localhost',"ruby-growl")
|
116
|
+
@g = Growl.new('localhost','ruby-growl')
|
117
|
+
@g.stub(:add_notification).with("notification","ruby-growl Notification")
|
118
|
+
@g.stub(:notify).with('notification','test-subject','test-message').and_raise
|
119
|
+
@battery_growl = BatteryGrowl.new
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'raise RuntimeError' do
|
123
|
+
expect{ @battery_growl.send(:post_growl, 'test-subject','test-message','localhost') }.to raise_error(RuntimeError)
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when growl is running' do
|
129
|
+
|
130
|
+
before(:each) do
|
131
|
+
allow_message_expectations_on_nil
|
132
|
+
Growl.stub(:new).with('localhost',"ruby-growl")
|
133
|
+
@g = Growl.new('localhost','ruby-growl')
|
134
|
+
@g.stub(:add_notification).with("notification","ruby-growl Notification")
|
135
|
+
@g.stub(:notify).with('notification','test-subject','test-message').and_return(true)
|
136
|
+
@battery_growl = BatteryGrowl.new
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'return true' do
|
140
|
+
expect( @battery_growl.send(:post_growl, 'test-subject','test-message','localhost') ).to be(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: battery_growl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- youyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby-growl
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: When the MacBookAir's battery is running low, notify the growl.
|
70
|
+
email:
|
71
|
+
- 1003ni2@gmail.com
|
72
|
+
executables:
|
73
|
+
- battery_growl
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- battery_growl.gemspec
|
83
|
+
- bin/battery_growl
|
84
|
+
- lib/battery_growl.rb
|
85
|
+
- lib/battery_growl/battery_growl.rb
|
86
|
+
- lib/battery_growl/version.rb
|
87
|
+
- spec/battery_growl_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.0.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: When the MacBookAir's battery is running low, notify the growl.
|
113
|
+
test_files:
|
114
|
+
- spec/battery_growl_spec.rb
|
115
|
+
- spec/spec_helper.rb
|