Class: Anyplayer::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/anyplayer/player.rb

Overview

Default Player class that is inherrited by all players.

All players should override these methods:

launched? (return bool)
next
prev
play
pause
playpause
track     (return string)
artist    (return string)
album     (return string)
voldown
volup
volume    (return int)
playing?  (return bool)
paused?   (return bool)

Constant Summary collapse

DEFAULT_VOTES_TO_SKIP =
5

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Player

Returns a new instance of Player.



21
22
23
# File 'lib/anyplayer/player.rb', line 21

def initialize
  @votes = 0
end

Instance Method Details

#launched? ⇒ Boolean

Return true if the player is currently launched

Returns:

  • (Boolean)


26
27
28
# File 'lib/anyplayer/player.rb', line 26

def launched?
  false
end

#name ⇒ Object

Player name defaults to the classe's, feel free to override it Example: player.name # => iTunes



33
34
35
# File 'lib/anyplayer/player.rb', line 33

def name
  self.class.to_s.gsub(/^.*::/, '')
end

#next ⇒ Object

Tell the player to go the the next song This resets the votes, so be sure to call super in children



58
59
60
# File 'lib/anyplayer/player.rb', line 58

def next
  reset_votes
end

#playpause ⇒ Object

Tells the player to toggle the pause state



38
39
40
# File 'lib/anyplayer/player.rb', line 38

def playpause
  paused? ? play : pause
end

#prev ⇒ Object

Tell the player to go to the previous song This resets the votes, so be sur eto call super in children



64
65
66
# File 'lib/anyplayer/player.rb', line 64

def prev
  reset_votes
end

#vote(votes_to_skip = DEFAULT_VOTES_TO_SKIP) ⇒ Object

Vote to skip this song



43
44
45
46
47
48
49
# File 'lib/anyplayer/player.rb', line 43

def vote(votes_to_skip = DEFAULT_VOTES_TO_SKIP)
  @votes += 1
  if @votes >= votes_to_skip
    self.next
    reset_votes
  end
end

#votes ⇒ Object

Returns the number of votes to skip this song



52
53
54
# File 'lib/anyplayer/player.rb', line 52

def votes
  @votes
end