volumerb 0.0.1
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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +8 -0
- data/lib/volumerb/linux_volume.rb +26 -0
- data/lib/volumerb/mac_volume.rb +39 -0
- data/lib/volumerb/version.rb +4 -0
- data/lib/volumerb.rb +38 -0
- data/test/volumerb_test.rb +32 -0
- data/volumerb.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTlmMDE4YjVlYTAxNTc2Y2ExYzFlNWY5MzBlNGJjYjU1ZDlhYmE5NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZmM2Nzg1ODgxYWI4ZWEwOWM5Nzk0MDBmOWYxYTE5MGI3YTI1YzQ5Mw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjY1MWU1NGM0NWNjYTdjOTNhZmU2ZjViOTFiMmU1ZjkxODU1YjNiNjk4MmY1
|
10
|
+
NDY5ODU2NjlhMjkyOWUyYWMzZTA2OGEzMDIwMDJiNTY2NjY5ZDhmNzRjYWI0
|
11
|
+
ZGViMTZmYWQzOTg4MjE1M2MwNWU0M2YwOWY4YmIxMGI4M2I1ODk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NTdhMzBjZmVlMGJhM2Y4ZDk1NWQ0M2RjYjc4YTMyOWQzODllZDYzMWE3MjJh
|
14
|
+
YjExNTJmNzNmYjZkYjM1ZmQ5ZGQ5NWQwNmNhODRhOWY5MTAzZjNjYTUwMDAz
|
15
|
+
NzYxZjAyMWY1YjZjNzk2MjlkZjcyNmMyOTJiNDU5YTJjNjUwZWI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Fernando Briano
|
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,43 @@
|
|
1
|
+
# Volumerb
|
2
|
+
|
3
|
+
Gem to manage the volume on GNU/Linux and Mac OS X operating systems.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'volumerb'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install volumerb
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The available methods are:
|
22
|
+
* `vol` - Returns the current volume state (on/off if unmuted/muted
|
23
|
+
and a value)
|
24
|
+
* `up` - Increases volume.
|
25
|
+
* `down` - Decreases volume.
|
26
|
+
* `mute` - Mutes/unmutes sound., `vol` and `mute`.
|
27
|
+
|
28
|
+
Example:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## TODO
|
42
|
+
* Method for setting the volume value directly, eg: Volumerb.vol = 30
|
43
|
+
* Customize volume increase/decrease
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Volumerb
|
3
|
+
module LinuxVolume
|
4
|
+
def self.up
|
5
|
+
`amixer -q sset Master 3%+`
|
6
|
+
vol
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
`amixer -q sset Master 3%-`
|
11
|
+
vol
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.mute
|
15
|
+
`amixer sset Master toggle`
|
16
|
+
vol
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.vol
|
20
|
+
vol = `amixer get Master | grep "\[[0-9]*%\]\ \[o[n|f]"`
|
21
|
+
number = vol.match(/([0-9]+)%/)[1]
|
22
|
+
state = vol.match(/\[([a-z]+)\]/)[1]
|
23
|
+
{ value: number.to_i, state: state.to_s }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Volumerb
|
3
|
+
module MacVolume
|
4
|
+
def self.up
|
5
|
+
osa 'set currentVolume to output volume of (get volume settings)
|
6
|
+
set volume output volume (currentVolume + 3)'
|
7
|
+
vol
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
osa 'set currentVolume to output volume of (get volume settings)
|
12
|
+
set volume output volume (currentVolume - 3)'
|
13
|
+
vol
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.mute
|
17
|
+
state = osa 'output muted of (get volume settings)'
|
18
|
+
setmute = !eval(state)
|
19
|
+
osa "set volume output muted #{setmute}"
|
20
|
+
vol
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.vol
|
24
|
+
# Mac OS X output:
|
25
|
+
# output volume:100, input volume:missing value, alert
|
26
|
+
# volume:98, output muted:false
|
27
|
+
vol = osa 'get volume settings'
|
28
|
+
number = vol.match(/output\ volume\:([0-9]+)/)[1]
|
29
|
+
state = vol.match(/muted:([t|f])/)[1]
|
30
|
+
{ number: number.to_s, state: state.to_s }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.osa(script)
|
36
|
+
`osascript -e '#{script}'`
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/volumerb.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'volumerb/version'
|
3
|
+
|
4
|
+
module Volumerb
|
5
|
+
def self.up
|
6
|
+
mixer unless @mixer
|
7
|
+
@mixer.up
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
mixer unless @mixer
|
12
|
+
@mixer.down
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.mute
|
16
|
+
mixer unless @mixer
|
17
|
+
@mixer.mute
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.vol
|
21
|
+
mixer unless @mixer
|
22
|
+
@mixer.vol
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.mixer
|
28
|
+
if RUBY_PLATFORM =~ /linux/
|
29
|
+
require 'volumerb/linux_volume'
|
30
|
+
@mixer = Volumerb::LinuxVolume
|
31
|
+
elsif RUBY_PLATFORM =~ /darwin|macos/
|
32
|
+
require 'volumerb/mac_volume'
|
33
|
+
@mixer = Volumerb::MacVolume
|
34
|
+
else
|
35
|
+
raise "Unsupported Ruby platform"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'volumerb'
|
3
|
+
|
4
|
+
class VolumerbTest < Minitest::Test
|
5
|
+
def test_vol
|
6
|
+
volume = Volumerb.vol
|
7
|
+
assert_instance_of Hash, volume
|
8
|
+
assert_includes 0..100, volume[:value]
|
9
|
+
assert_match(/on|off/, volume[:state])
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_up
|
13
|
+
previous = Volumerb.vol[:value]
|
14
|
+
assert_operator(previous, :<, Volumerb.up[:value])
|
15
|
+
# Restore volume
|
16
|
+
Volumerb.down
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_down
|
20
|
+
previous = Volumerb.vol[:value]
|
21
|
+
assert_operator(previous, :>, Volumerb.down[:value])
|
22
|
+
# Restore volume
|
23
|
+
Volumerb.up
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_mute
|
27
|
+
states = {'off' => 'on', 'on' => 'off'}
|
28
|
+
assert_equal Volumerb.vol[:state], states[Volumerb.mute[:state]]
|
29
|
+
# Restore volume
|
30
|
+
Volumerb.mute
|
31
|
+
end
|
32
|
+
end
|
data/volumerb.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'volumerb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "volumerb"
|
8
|
+
spec.version = Volumerb::VERSION
|
9
|
+
spec.authors = ["Fernando Briano"]
|
10
|
+
spec.email = ["fernando@picandocodigo.net"]
|
11
|
+
spec.description = %q{Gem to manage the computer's volume}
|
12
|
+
spec.summary = %q{Gem to manage the volume on GNU/Linux and Mac OS X operating systems}
|
13
|
+
spec.homepage = "https://github.com/picandocodigo/volumerb"
|
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", "~> 10.2"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.3"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: volumerb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernando Briano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-28 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: '10.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.3'
|
55
|
+
description: Gem to manage the computer's volume
|
56
|
+
email:
|
57
|
+
- fernando@picandocodigo.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/volumerb.rb
|
68
|
+
- lib/volumerb/linux_volume.rb
|
69
|
+
- lib/volumerb/mac_volume.rb
|
70
|
+
- lib/volumerb/version.rb
|
71
|
+
- test/volumerb_test.rb
|
72
|
+
- volumerb.gemspec
|
73
|
+
homepage: https://github.com/picandocodigo/volumerb
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.2.2
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Gem to manage the volume on GNU/Linux and Mac OS X operating systems
|
97
|
+
test_files:
|
98
|
+
- test/volumerb_test.rb
|
99
|
+
has_rdoc:
|