Class: Dhun::Handler
- Inherits:
-
Object
- Object
- Dhun::Handler
- Defined in:
- lib/dhun/handler.rb
Overview
Handling commands sent by Dhun client
Instance Attribute Summary collapse
-
#player ⇒ Object
Returns the value of attribute player.
Instance Method Summary collapse
- #clear ⇒ Object
- #enqueue(files) ⇒ Object
- #history ⇒ Object
-
#initialize(player = Dhun::Player.instance) ⇒ Handler
constructor
A new instance of Handler.
- #next(skip_length = 1) ⇒ Object
- #pause ⇒ Object
- #play ⇒ Object
- #prev(skip_length = 1) ⇒ Object
- #resume ⇒ Object
- #shuffle ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#player ⇒ Object
Returns the value of attribute player.
5 6 7 |
# File 'lib/dhun/handler.rb', line 5 def player @player end |
Instance Method Details
#clear ⇒ Object
59 60 61 62 63 |
# File 'lib/dhun/handler.rb', line 59 def clear perform_action :clear,nil, :success => "Queue is cleared", :error => "Queue is not cleared" end |
#enqueue(files) ⇒ Object
21 22 23 24 25 |
# File 'lib/dhun/handler.rb', line 21 def enqueue(files) perform_action :enqueue, files, :success => ["#{files.size} files queued", {:files => files}], :error => ["No files queued"] end |
#history ⇒ Object
76 77 78 79 |
# File 'lib/dhun/handler.rb', line 76 def history return [:success, "#{@player.history.size} files in history",{:history => @player.history}] unless @player.history.empty? return [:error, "No files in history"] end |
#next(skip_length = 1) ⇒ Object
45 46 47 |
# File 'lib/dhun/handler.rb', line 45 def next(skip_length=1) next_prev :next, 'queue',skip_length end |
#pause ⇒ Object
27 28 29 30 31 |
# File 'lib/dhun/handler.rb', line 27 def pause perform_action :pause,nil, :success => "Dhun is paused at #{@player.current}", :error => "Dhun has already paused or stopped" end |
#play ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/dhun/handler.rb', line 11 def play response = case @player.play when false then [:error,"already playing"] when true then [:success, "resuming playback"] when :empty then [:error, 'no file in queue'] end response end |
#prev(skip_length = 1) ⇒ Object
49 50 51 |
# File 'lib/dhun/handler.rb', line 49 def prev(skip_length=1) next_prev :prev, 'history',skip_length end |
#resume ⇒ Object
33 34 35 36 37 |
# File 'lib/dhun/handler.rb', line 33 def resume perform_action :resume,nil, :success => "Dhun is resumed at #{@player.current}", :error => "Dhun has already resumed or stopped" end |
#shuffle ⇒ Object
53 54 55 56 57 |
# File 'lib/dhun/handler.rb', line 53 def shuffle perform_action :shuffle,nil, :success => ['Queue is shuffled', { :queue => @player.queue }], :error => 'Dhun cannot shuffle(queue empty, same songs)' end |
#status ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/dhun/handler.rb', line 66 def status status_msg = case @player.status when :playing then "Dhun is running" when :paused then "Dhun is paused" when :stopped then "Dhun has stopped" end [:success, status_msg, {:current => @player.current, :queue => @player.queue}] end |
#stop ⇒ Object
39 40 41 42 43 |
# File 'lib/dhun/handler.rb', line 39 def stop perform_action :stop,nil, :success => "Dhun has stopped", :error => "Dhun has already stopped" end |