Class: Play::Song
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Play::Song
- Defined in:
- lib/play/song.rb
Class Method Summary collapse
-
.office_song ⇒ Object
Pull a magic song from a hat, depending on who’s in the office.
-
.play_next_in_queue ⇒ Object
Plays the next song in the queue.
Instance Method Summary collapse
-
#album_name ⇒ Object
The name of the album.
-
#artist_name ⇒ Object
The name of the artist.
-
#current_votes ⇒ Object
The current votes for a song.
-
#dequeue!(user = nil) ⇒ Object
Remove a song from the queue.
-
#enqueue!(user) ⇒ Object
Queue up a song.
-
#play! ⇒ Object
Update the metadata surrounding playing a song.
Class Method Details
.office_song ⇒ Object
Pull a magic song from a hat, depending on who’s in the office.
Returns a Song that’s pulled from the favorite artists of the users currently located in the office.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/play/song.rb', line 70 def self.office_song users = Play::Office.users if !users.empty? artist = users.collect(&:favorite_artists).flatten.shuffle.first end if artist artist.songs.shuffle.first else Play::Song.order("rand()").first end end |
.play_next_in_queue ⇒ Object
Plays the next song in the queue. Updates the appropriate metainformation in surrounding tables. Will pull an office favorite if there’s nothing in the queue currently.
Returns the Song that was selected next to be played.
88 89 90 91 92 93 94 95 |
# File 'lib/play/song.rb', line 88 def self.play_next_in_queue song = queue.first song ||= office_song Play::History.create(:song => song) song.play! song.dequeue! song end |
Instance Method Details
#album_name ⇒ Object
The name of the album. Used for Mustache purposes.
Returns the String name of the album.
22 23 24 |
# File 'lib/play/song.rb', line 22 def album_name album.name end |
#artist_name ⇒ Object
The name of the artist. Used for Mustache purposes.
Returns the String name of the artist.
15 16 17 |
# File 'lib/play/song.rb', line 15 def artist_name artist.name end |
#current_votes ⇒ Object
The current votes for a song. A song may have many historical votes, which is well and good, but here we’re only concerned for the current round of whether it’s voted for.
Returns and Array of Vote objects.
31 32 33 |
# File 'lib/play/song.rb', line 31 def current_votes votes.where(:active => true).all end |
#dequeue!(user = nil) ⇒ Object
Remove a song from the queue
user - the User who is requesting the song be removed
Returns true if removed properly, false otherwise.
51 52 53 54 |
# File 'lib/play/song.rb', line 51 def dequeue!(user=nil) self.queued = false save end |
#enqueue!(user) ⇒ Object
Queue up a song.
user - the User who is requesting the song to be queued
Returns the result of the user’s vote for that song.
40 41 42 43 44 |
# File 'lib/play/song.rb', line 40 def enqueue!(user) self.queued = true save user.vote_for(self) end |
#play! ⇒ Object
Update the metadata surrounding playing a song.
Returns a Boolean of whether we’ve saved the song.
59 60 61 62 63 64 |
# File 'lib/play/song.rb', line 59 def play! Song.update_all(:now_playing => false) self. = true votes.update_all(:active => false) save end |