Class: Candelabra::EventCmd

Inherits:
Object
  • Object
show all
Includes:
OSX, Ubuntu
Defined in:
lib/candelabra/event_cmd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ubuntu

extended, included, linux?

Methods included from OSX

extended, included, osx?

Constructor Details

#initialize(args) ⇒ EventCmd

Inigialize the Event Command with the given command Once we have the command we can preform different actions



10
11
12
# File 'lib/candelabra/event_cmd.rb', line 10

def initialize(args)
  @command = args.shift
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def album
  @album
end

#artistObject (readonly)

Returns the value of attribute artist.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def artist
  @artist
end

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def command
  @command
end

#coverArtObject (readonly)

Returns the value of attribute coverArt.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def coverArt
  @coverArt
end

#stationNameObject (readonly)

Returns the value of attribute stationName.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def stationName
  @stationName
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/candelabra/event_cmd.rb', line 6

def title
  @title
end

Instance Method Details

#art_workObject

The 2011 release of pianobar supports album art. If wen have album are the it will be displayed in the notification

Returns nil or the path of the file



44
45
46
47
48
49
50
# File 'lib/candelabra/event_cmd.rb', line 44

def art_work
  if coverArt
    Dir.glob('*.jpg').each { |imge| File.delete(imge) }
    File.open( 'img.jpg', 'wb' ) { |f| f.write Net::HTTP.get( URI.parse( coverArt ) ) }
    Dir.glob('*.jpg').first
  end
end

#parse(data) ⇒ Object

Parse out the data from stdin. This will set instance vars that are named the same as the input from pianobar

Retruns nothing



32
33
34
35
36
37
38
# File 'lib/candelabra/event_cmd.rb', line 32

def parse(data)
  data.each do |key_value|
    key, value = key_value.chomp.split('=')
    key = key
    instance_variable_set( "@#{key}".to_sym, value )
  end
end

#runObject

Run the command. Part of running the command



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/candelabra/event_cmd.rb', line 15

def run
  parse( $stdin )
  case command
  when 'songstart'
    notify
    Remote.flush
  when 'userlogin'
    unless @pRet.to_i == 1
      `ps a | grep 'candelabra install' | cut -c1-5`.split("\n").each{|id| `kill #{id}` unless Process.pid == id.to_i }
    end
  end
end