Module: Listlace::Commands
- Included in:
- Listlace
- Defined in:
- lib/listlace/commands.rb
Instance Method Summary collapse
- #albums(playlist = nil) ⇒ Object
- #artists(playlist = nil) ⇒ Object
- #genres(playlist = nil) ⇒ Object
- #list(playlist = nil) ⇒ Object
- #p(*playlist) ⇒ Object
- #q(*playlist) ⇒ Object
- #stop ⇒ Object
- #years(playlist = nil) ⇒ Object
Instance Method Details
#albums(playlist = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/listlace/commands.rb', line 56 def albums(playlist = nil) (playlist || all).group_by(&:album).each do |album, songs| plural = (songs.length == 1) ? "" : "s" puts "#{songs.first.artist} - #{album} (#{songs.length} song#{plural})" end nil end |
#artists(playlist = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/listlace/commands.rb', line 48 def artists(playlist = nil) (playlist || all).group_by(&:artist).each do |artist, songs| plural = (songs.length == 1) ? "" : "s" puts "#{artist} (#{songs.length} song#{plural})" end nil end |
#genres(playlist = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/listlace/commands.rb', line 64 def genres(playlist = nil) (playlist || all).group_by(&:genre).each do |genre, songs| plural = (songs.length == 1) ? "" : "s" puts "#{genre} (#{songs.length} song#{plural})" end nil end |
#list(playlist = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/listlace/commands.rb', line 40 def list(playlist = nil) (playlist || all).each do |song| time = TimeHelpers.format_time(song.time) puts "#{song.artist} - #{song.album} - #{song.title} (#{time})" end nil end |
#p(*playlist) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/listlace/commands.rb', line 3 def p(*playlist) if playlist.empty? case mpd.status[:state] when :play mpd.pause = true when :pause mpd.pause = false when :stop mpd.play end else mpd.clear playlist.flatten.each do |song| mpd.add song.file end mpd.play end nil end |
#q(*playlist) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/listlace/commands.rb', line 28 def q(*playlist) if playlist.empty? mpd.queue else mpd.clear playlist.flatten.each do |song| mpd.add song.file end nil end end |
#stop ⇒ Object
23 24 25 26 |
# File 'lib/listlace/commands.rb', line 23 def stop mpd.stop nil end |
#years(playlist = nil) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/listlace/commands.rb', line 72 def years(playlist = nil) (playlist || all).group_by(&:date).each do |year, songs| plural = (songs.length == 1) ? "" : "s" puts "#{year} (#{songs.length} song#{plural})" end nil end |