Class: MTP::FileSystem::Albums

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

Instance Method Summary collapse

Constructor Details

#initialize(device, artist = nil) ⇒ Albums

Returns a new instance of Albums.



145
146
147
148
# File 'lib/mtp/fuse.rb', line 145

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

Instance Method Details

#can_rmdir?(path) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/mtp/fuse.rb', line 162

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

#contents(path) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/mtp/fuse.rb', line 172

def contents(path)
  if path.empty?
    if @artist.nil?
      @device.tracks.map { |t| t.album_name }.uniq
    else
      albums = []
      @device.objects.each do |o|
        if o.is_a?(Track) and o.artist == @artist and !albums.include?(o.album_name)
          albums << o.album_name
        end
      end
      albums
    end
  elsif path.size == 1
    @device.objects.select { |o| o.is_a?(Track) and o.album_name == path[0] }.map { |t| t.filename }
  else
    []
  end
end

#directory?(path) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/mtp/fuse.rb', line 150

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

#file?(path) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/mtp/fuse.rb', line 154

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

#rmdir(path) ⇒ Object



166
167
168
169
170
# File 'lib/mtp/fuse.rb', line 166

def rmdir(path)
  @device.objects.each do |object|
    @device.delete(object) if object.is_a?(Track) and (@artist.nil? or @artist == object.artist) and object.album_name == path.first
  end
end

#size(path) ⇒ Object



158
159
160
# File 'lib/mtp/fuse.rb', line 158

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