Class: MTP::FileSystem::Artists

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

Instance Method Summary collapse

Constructor Details

#initialize(device, genre = nil) ⇒ Artists

Returns a new instance of Artists.



196
197
198
199
# File 'lib/mtp/fuse.rb', line 196

def initialize(device, genre = nil)
  @device = device
  @genre = genre
end

Instance Method Details

#can_rmdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


221
222
223
224
225
# File 'lib/mtp/fuse.rb', line 221

def can_rmdir?(path)
  dispatch(:can_rmdir?, path) do |path|
    !path.empty?
  end          
end

#contents(path) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/mtp/fuse.rb', line 235

def contents(path)
  dispatch(:contents, path) do |path|
    if @genre.nil?
      @device.tracks.map { |t| t.artist }.uniq      
    else
      artists = []
      @device.objects.each do |o|
        if o.is_a?(Track) and o.genre == @genre and !artists.include?(o.artist)
          artists << o.artist
        end
      end
      artists
    end
  end
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/mtp/fuse.rb', line 209

def directory?(path)
  path.size <= 2
end

#dispatch(method, path, &block) ⇒ Object



201
202
203
204
205
206
207
# File 'lib/mtp/fuse.rb', line 201

def dispatch(method, path, &block)
  if path.size > 1 or (path.size == 1 and method == :contents)
    Albums.new(@device, path.shift).send(method, path)
  else
    yield path
  end
end

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


213
214
215
# File 'lib/mtp/fuse.rb', line 213

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

#rmdir(path) ⇒ Object



227
228
229
230
231
232
233
# File 'lib/mtp/fuse.rb', line 227

def rmdir(path)
  dispatch(:rmdir, path) do |path|
    @device.objects.each do |object|
      @device.delete(object) if object.is_a?(Track) and path.first == object.artist
    end
  end
end

#size(path) ⇒ Object



217
218
219
# File 'lib/mtp/fuse.rb', line 217

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