Class: Barr::Blocks::Rhythmbox

Inherits:
Barr::Block show all
Defined in:
lib/barr/blocks/rhythmbox.rb

Instance Attribute Summary collapse

Attributes inherited from Barr::Block

#align, #bgcolor, #fgcolor, #icon, #interval, #output

Instance Method Summary collapse

Methods inherited from Barr::Block

#<<, #colors, #destroy, #destroy!, #draw, #reassign_deprecated_option, #update

Constructor Details

#initialize(opts = {}) ⇒ Rhythmbox

Returns a new instance of Rhythmbox.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/barr/blocks/rhythmbox.rb', line 8

def initialize(opts = {})
  super
  reassign_deprecated_option opts, :show_artist, :artist
  reassign_deprecated_option opts, :show_title, :title
  reassign_deprecated_option opts, :show_buttons, :buttons

  @view_opts = {
    artist:   opts[:artist].nil? || opts[:artist],
    buttons: opts[:buttons].nil? || opts[:buttons],
    title: opts[:title].nil? || opts[:title]
  }
end

Instance Attribute Details

#view_optsObject (readonly)

Returns the value of attribute view_opts.



6
7
8
# File 'lib/barr/blocks/rhythmbox.rb', line 6

def view_opts
  @view_opts
end

Instance Method Details

#buttonsObject



50
51
52
53
54
55
56
# File 'lib/barr/blocks/rhythmbox.rb', line 50

def buttons
  [
    "%{A:rhythmbox-client --previous:}\uf048%{A}",
    "%{A:rhythmbox-client --play-pause:}\uf04b%{A}",
    "%{A:rhythmbox-client --next:}\uf051%{A}"
  ].join(' ').freeze
end

#running?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/barr/blocks/rhythmbox.rb', line 46

def running?
  `pgrep rhythmbox`.chomp.length != 0
end

#update!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/barr/blocks/rhythmbox.rb', line 21

def update!
  op = []

  if @view_opts[:artist] || @view_opts[:title]
    if(running?)
      info = sys_cmd.split(' - ')

      if @view_opts[:artist] && @view_opts[:title]
        op << info.join(' - ')
      elsif @view_opts[:artist]
        op << info[0]
      elsif @view_opts[:title]
        op << info[1]
      end
    else
      op << 'None'
    end
  end

  op << buttons if @view_opts[:buttons]

  @output = op.join(' ')

end