Class: MTP::FileSystem::Playlists

Inherits:
Object
  • Object
show all
Defined in:
lib/mtp/fuse.rb

Instance Method Summary collapse

Constructor Details

#initialize(device) ⇒ Playlists

Returns a new instance of Playlists.



303
304
305
# File 'lib/mtp/fuse.rb', line 303

def initialize(device)
  @device = device
end

Instance Method Details

#can_delete?(path) ⇒ Boolean

Returns:

  • (Boolean)


331
332
333
# File 'lib/mtp/fuse.rb', line 331

def can_delete?(path)
  !path.empty?
end

#can_mkdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


339
340
341
# File 'lib/mtp/fuse.rb', line 339

def can_mkdir?(path)
  path.size == 1 and playlist(path.first).nil?
end

#can_rmdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


350
351
352
# File 'lib/mtp/fuse.rb', line 350

def can_rmdir?(path)
  !path.empty?
end

#can_write?(path) ⇒ Boolean

Returns:

  • (Boolean)


323
324
325
# File 'lib/mtp/fuse.rb', line 323

def can_write?(path)
  path.size == 2
end

#contents(path) ⇒ Object



358
359
360
361
362
363
364
# File 'lib/mtp/fuse.rb', line 358

def contents(path)
  if path.empty?
    @device.playlists.map { |p| p.name }
  else
    playlist(path.first).to_a.map { |o| o.filename }
  end
end

#delete(path) ⇒ Object



335
336
337
# File 'lib/mtp/fuse.rb', line 335

def delete(path)
  playlist(path.first).delete(@device[path.last])
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


311
312
313
# File 'lib/mtp/fuse.rb', line 311

def directory?(path)
  path.size.zero? or (path.size == 1 and !playlist(path.first).nil?)
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


315
316
317
# File 'lib/mtp/fuse.rb', line 315

def file?(path)
  path.size == 2
end

#mkdir(path) ⇒ Object



343
344
345
346
347
348
# File 'lib/mtp/fuse.rb', line 343

def mkdir(path)
  playlist = MTP::Playlist.new
  @device.send(playlist)
  playlist.name = path.first
  puts "haha #{playlist.name}"
end

#playlist(name) ⇒ Object



307
308
309
# File 'lib/mtp/fuse.rb', line 307

def playlist(name)
  @device.playlists.detect { |p| p.name == name }
end

#rmdir(path) ⇒ Object



354
355
356
# File 'lib/mtp/fuse.rb', line 354

def rmdir(path)
  @device.delete(playlist(path.first))
end

#size(path) ⇒ Object



319
320
321
# File 'lib/mtp/fuse.rb', line 319

def size(path)
  @device[path.last].compressed_size
end

#write_to(path, str) ⇒ Object



327
328
329
# File 'lib/mtp/fuse.rb', line 327

def write_to(path, str)
  playlist(path.first) << @device[path.last] unless @device[path.last].nil? or playlist.include?(@device[path.last])
end