lib/audioinfo/album.rb in ruby-audioinfo-0.1.7 vs lib/audioinfo/album.rb in ruby-audioinfo-0.2
- old
+ new
@@ -41,16 +41,19 @@
# first and last file of the directory
def initialize(path, fast_lookup = false)
@path = path
@multicd = false
@basename = @path
- exts = AudioInfo::SUPPORTED_EXTENSIONS.join(",")
+ exts = AudioInfo::SUPPORTED_EXTENSIONS.collect do |ext|
+ ext.gsub(/[a-z]/) { |c| "[#{c.downcase}#{c.upcase}]" }
+ end.join(",")
# need to escape the glob path
glob_escaped_path = @path.gsub(/([{}?*\[\]])/) { |s| '\\' << s }
- file_names = Dir.glob( File.join(glob_escaped_path, "*.{#{exts}}") , File::FNM_CASEFOLD).sort
+ glob_val = File.join(glob_escaped_path, "*.{#{exts}}")
+ file_names = Dir.glob(glob_val).sort
if fast_lookup
file_names = [file_names.first, file_names.last]
end
@@ -102,16 +105,12 @@
self.class.images(@path)
end
# title of the album
def title
- albums = @files.collect { |f| f.album }.uniq
- #if albums.size > 1
- # "#{albums.first} others candidates: '" + albums[1..-1].join("', '") + "'"
- #else
- albums.first
- #end
+ hash_counted = self.files.collect { |f| f.album }.inject(Hash.new(0)) { |hash, album| hash[album] += 1; hash }
+ hash_counted.sort_by { |k, v| v }.last[0]
end
# mbid (MusicBrainz ID) of the album
def mbid
return nil unless mb_tagged?
@@ -142,9 +141,13 @@
end
out.puts
end
out.string
+ end
+
+ def inspect
+ @infos.inspect
end
end