Class: Cejo::Ops::Volume

Inherits:
Object
  • Object
show all
Defined in:
lib/cejo/ops/volume/volume.rb

Overview

Manage System Volume.

Constant Summary collapse

STEP =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#infoObject

Returns the value of attribute info.



10
11
12
# File 'lib/cejo/ops/volume/volume.rb', line 10

def info
  @info
end

#stateObject (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

#amixerObject

  • 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_toggleObject



53
54
55
# File 'lib/cejo/ops/volume/volume.rb', line 53

def amixer_toggle
  [amixer[:name], amixer[:toggle]].join(' ')
end

#amixer_updownObject



57
58
59
# File 'lib/cejo/ops/volume/volume.rb', line 57

def amixer_updown
  [amixer[:name], amixer[:updown]].join(' ')
end

#final_commandObject



105
106
107
# File 'lib/cejo/ops/volume/volume.rb', line 105

def final_command
  mode[state]
end

#mixerObject

  • 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_toggleObject



71
72
73
# File 'lib/cejo/ops/volume/volume.rb', line 71

def mixer_toggle
  [mixer[:name], mixer[:toggle]].join(' ')
end

#mixer_updownObject



75
76
77
# File 'lib/cejo/ops/volume/volume.rb', line 75

def mixer_updown
  [mixer[:name], mixer[:updown]].join(' ')
end

#modeObject



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

#pactlObject

  • 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_toggleObject



35
36
37
# File 'lib/cejo/ops/volume/volume.rb', line 35

def pactl_toggle
  [pactl[:name], pactl[:toggle]].join(' ')
end

#pactl_updownObject



39
40
41
# File 'lib/cejo/ops/volume/volume.rb', line 39

def pactl_updown
  [pactl[:name], pactl[:updown]].join(' ')
end

#runObject



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

#statesObject



17
18
19
20
21
22
23
# File 'lib/cejo/ops/volume/volume.rb', line 17

def states
  {
    up: '+',
    down: '-',
    toggle: ''
  }
end

#toggleObject

  • 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

#updownObject



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