Class: Knj::Amixer
Overview
This class is a Ruby-interface to the amixer-binary. It can read and set the volume.
Defined Under Namespace
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#devices ⇒ Object
Returns a hash with devices.
-
#initialize(args = {}) ⇒ Amixer
constructor
A new instance of Amixer.
Constructor Details
#initialize(args = {}) ⇒ Amixer
Returns a new instance of Amixer.
5 6 7 8 9 10 11 12 |
# File 'lib/knj/amixer.rb', line 5 def initialize(args = {}) @args = { :amixer_bin => "/usr/bin/amixer", :aplay_bin => "/usr/bin/aplay" }.merge(args) @devices = {} end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/knj/amixer.rb', line 3 def args @args end |
Instance Method Details
#devices ⇒ Object
Returns a hash with devices.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/knj/amixer.rb', line 15 def devices ret = %x[#{@args[:aplay_bin]} -l] ret.scan(/card (\d+): (.+?) \[(.+?)\],/) do |match| id = match[0] if !@devices.key?(id) @devices[id] = Knj::Amixer::Device.new( :amixer => self, :id => id, :name => match[2], :code => match[1] ) end end return @devices end |