Class: Cejo::Ops::Volume
- Inherits:
-
Object
- Object
- Cejo::Ops::Volume
- Defined in:
- lib/cejo/ops/volume/volume.rb
Overview
Manage System Volume.
Constant Summary collapse
- STEP =
3
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#amixer ⇒ Object
-
AMIXER.
-
- #amixer_toggle ⇒ Object
- #amixer_updown ⇒ Object
- #final_command ⇒ Object
-
#initialize(utils, state) ⇒ Volume
constructor
A new instance of Volume.
-
#mixer ⇒ Object
-
BSD MIXER.
-
- #mixer_toggle ⇒ Object
- #mixer_updown ⇒ Object
- #mode ⇒ Object
-
#pactl ⇒ Object
-
PACTL.
-
- #pactl_toggle ⇒ Object
- #pactl_updown ⇒ Object
- #run ⇒ Object
- #states ⇒ Object
-
#toggle ⇒ Object
-
MODES.
-
- #updown ⇒ Object
Constructor Details
#initialize(utils, state) ⇒ Volume
Returns a new instance of Volume.
12 13 14 15 |
# File 'lib/cejo/ops/volume/volume.rb', line 12 def initialize(utils, state) @state = state.to_sym if state @info = SoundManager.new(utils).info end |
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
10 11 12 |
# File 'lib/cejo/ops/volume/volume.rb', line 10 def info @info end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
9 10 11 |
# File 'lib/cejo/ops/volume/volume.rb', line 9 def state @state end |
Instance Method Details
#amixer ⇒ Object
-
AMIXER
45 46 47 48 49 50 51 |
# File 'lib/cejo/ops/volume/volume.rb', line 45 def amixer { name: 'amixer', toggle: '-q sset Master toggle', updown: "set Master #{STEP}%#{states[state]}" } end |
#amixer_toggle ⇒ Object
53 54 55 |
# File 'lib/cejo/ops/volume/volume.rb', line 53 def amixer_toggle [amixer[:name], amixer[:toggle]].join(' ') end |
#amixer_updown ⇒ Object
57 58 59 |
# File 'lib/cejo/ops/volume/volume.rb', line 57 def amixer_updown [amixer[:name], amixer[:updown]].join(' ') end |
#final_command ⇒ Object
105 106 107 |
# File 'lib/cejo/ops/volume/volume.rb', line 105 def final_command mode[state] end |
#mixer ⇒ Object
-
BSD MIXER
63 64 65 66 67 68 69 |
# File 'lib/cejo/ops/volume/volume.rb', line 63 def mixer { name: 'mixer', toggle: '', updown: "mixer vol #{states[state]}#{STEP}" } end |
#mixer_toggle ⇒ Object
71 72 73 |
# File 'lib/cejo/ops/volume/volume.rb', line 71 def mixer_toggle [mixer[:name], mixer[:toggle]].join(' ') end |
#mixer_updown ⇒ Object
75 76 77 |
# File 'lib/cejo/ops/volume/volume.rb', line 75 def mixer_updown [mixer[:name], mixer[:updown]].join(' ') end |
#mode ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/cejo/ops/volume/volume.rb', line 97 def mode { toggle: toggle[info.name], up: updown[info.name], down: updown[info.name] } end |
#pactl ⇒ Object
-
PACTL
27 28 29 30 31 32 33 |
# File 'lib/cejo/ops/volume/volume.rb', line 27 def pactl { name: 'pactl', toggle: "set-sink-mute #{info.sink} toggle", updown: "set-sink-volume #{info.sink} #{states[state]}#{STEP}%" } end |
#pactl_toggle ⇒ Object
35 36 37 |
# File 'lib/cejo/ops/volume/volume.rb', line 35 def pactl_toggle [pactl[:name], pactl[:toggle]].join(' ') end |
#pactl_updown ⇒ Object
39 40 41 |
# File 'lib/cejo/ops/volume/volume.rb', line 39 def pactl_updown [pactl[:name], pactl[:updown]].join(' ') end |
#run ⇒ Object
109 110 111 112 113 |
# File 'lib/cejo/ops/volume/volume.rb', line 109 def run return unless %i[up down toggle].include? state system final_command end |
#states ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/cejo/ops/volume/volume.rb', line 17 def states { up: '+', down: '-', toggle: '' } end |
#toggle ⇒ Object
-
MODES
81 82 83 84 85 86 87 |
# File 'lib/cejo/ops/volume/volume.rb', line 81 def toggle { pactl: pactl_toggle, amixer: amixer_toggle, mixer: mixer_toggle } end |
#updown ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/cejo/ops/volume/volume.rb', line 89 def updown { pactl: pactl_updown, amixer: amixer_updown, mixer: mixer_updown } end |