Class: MPD::Controller::Database

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

Defined Under Namespace

Classes: Artist, Directory, Element, Song

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Database

Returns a new instance of Database.



184
185
186
187
# File 'lib/mpd/controller/database.rb', line 184

def initialize (controller)
	@controller = controller
	@root       = Directory.new(self)
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



182
183
184
# File 'lib/mpd/controller/database.rb', line 182

def controller
  @controller
end

#rootObject (readonly)

Returns the value of attribute root.



182
183
184
# File 'lib/mpd/controller/database.rb', line 182

def root
  @root
end

Instance Method Details

#[](name) ⇒ Object



217
218
219
# File 'lib/mpd/controller/database.rb', line 217

def [] (name)
	@root[name]
end

#each(&block) ⇒ Object



209
210
211
212
213
214
215
# File 'lib/mpd/controller/database.rb', line 209

def each (&block)
	return to_enum unless block_given?

	@root.each(&block)

	self
end

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



205
206
207
# File 'lib/mpd/controller/database.rb', line 205

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

#tags(name, artist = nil) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/mpd/controller/database.rb', line 189

def tags (name, artist = nil)
	return enum_for :tags, name, artist unless block_given?

	controller.do_and_raise_if_needed(:list, name, *artist).each {|_, value|
		yield value
	}
end

#update(*args) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/mpd/controller/database.rb', line 221

def update (*args)
	options = args.last.is_a?(Hash) ? args.pop : { force: false }
	uri     = args.shift

	if options[:force]
		controller.do_and_raise_if_needed :rescan, *uri
	else
		controller.do_and_raise_if_needed :update, *uri
	end

	self
end