Class: MPD::Controller::CurrentPlaylist

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mpd/controller/current_playlist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ CurrentPlaylist

Returns a new instance of CurrentPlaylist.



18
19
20
# File 'lib/mpd/controller/current_playlist.rb', line 18

def initialize (controller)
	@controller = controller
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



16
17
18
# File 'lib/mpd/controller/current_playlist.rb', line 16

def controller
  @controller
end

Instance Method Details

#[](id) ⇒ Object



82
83
84
# File 'lib/mpd/controller/current_playlist.rb', line 82

def [] (id)
	Database::Song.from_data(controller.do_and_raise_if_needed(:playlistid, id))
end

#add(uri, position = nil) ⇒ Object



30
31
32
# File 'lib/mpd/controller/current_playlist.rb', line 30

def add (uri, position = nil)
	controller.do_and_raise_if_needed(:addid, uri, *position).first.last
end

#clearObject



54
55
56
# File 'lib/mpd/controller/current_playlist.rb', line 54

def clear
	controller.do_and_raise_if_needed :clear
end

#delete(what) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/mpd/controller/current_playlist.rb', line 34

def delete (what)
	if what.is_a?(Integer) || what.is_a?(Range)
		controller.do_and_raise_if_needed :delete, what
	else
		controller.do_and_raise_if_needed :deleteid, what
	end

	self
end

#eachObject



72
73
74
75
76
77
78
79
80
# File 'lib/mpd/controller/current_playlist.rb', line 72

def each
	return to_enum unless block_given?

	Database::Song.from_data(controller.do(:playlistinfo)).each {|song|
		yield song
	}

	self
end

#lengthObject



26
27
28
# File 'lib/mpd/controller/current_playlist.rb', line 26

def length
	controller.status.playlist.length
end

#move(from, to) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/mpd/controller/current_playlist.rb', line 44

def move (from, to)
	if from.is_a?(Integer) || what.is_a?(Range)
		controller.do_and_raise_if_needed :move, from, to
	else
		controller.do_and_raise_if_needed :moveid, from, to
	end

	self
end

#priority(priority, *args) ⇒ Object



86
87
88
89
90
91
# File 'lib/mpd/controller/current_playlist.rb', line 86

def priority (priority, *args)
	controller.do_and_raise_if_needed :prio, priority, *args.select { |o| o.is_a?(Range) }
	controller.do_and_raise_if_needed :prioid, priority, *args.reject { |o| o.is_a?(Range) }

	self
end

#save_as(name, force = false) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/mpd/controller/current_playlist.rb', line 58

def save_as (name, force = false)
	if force
		controller.playlists[name].delete!
	end

	controller.do_and_raise_if_needed :save, name

	self
end

#search(pattern, options = { tag: :title, strict: false }) ⇒ Object



68
69
70
# File 'lib/mpd/controller/current_playlist.rb', line 68

def search (pattern, options = { tag: :title, strict: false })
	Database::Song.from_data(controller.do_and_raise_if_needed(options[:strict] ? :playlistfind : :playlistsearch, options[:tag], pattern))
end

#shuffle(range = nil) ⇒ Object



93
94
95
96
97
# File 'lib/mpd/controller/current_playlist.rb', line 93

def shuffle (range = nil)
	controller.do_and_raise_if_needed :shuffle, *range

	self
end

#swap(a, b) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/mpd/controller/current_playlist.rb', line 99

def swap (a, b)
	if a.is_a?(Integer) && b.is_a?(Integer)
		controller.do_and_raise_if_needed :swap, a, b
	else
		controller.do_and_raise_if_needed :swapip, a, b
	end

	self
end

#versionObject



22
23
24
# File 'lib/mpd/controller/current_playlist.rb', line 22

def version
	controller.status.playlist.version
end