# File lib/freedb.rb, line 287 def get_result(index) if index.is_a?(String) idx = nil @results.each_with_index { |r, i| if r =~ /^#{index}/ idx = i end } else idx = index end md = /^\S+ [0-9a-fA-F]{8}/.match(@results[idx]) @handler.send_cmd("read", md[0]) # swallow the whole response into a hash response = Hash.new each_line(@handler) { |line| @raw_response << line + "\n" case line when /^(\d+) (\S+)/, /^([A-Za-z0-9_]+)=(.*)/ key = $1.upcase val = $2.gsub(/\\(.)/) { case $1 when "t" "\t" when "n" "\n" else $1 end } (response[key] ||= '') << val when /^# Revision: (\d+)/ @revision = $1.to_i end } @category = response['210'] @genre = response['DGENRE'] @year = response['DYEAR'].to_i @ext_infos = response['EXTD'] # Use a regexp instead of a bare string to avoid ruby >= 1.7 warning @artist, @title = response['DTITLE'].split(/ \/ /, 2) # A self-titled album may not have a title part @title ||= @artist response.each { |key, val| case key when /^4\d\d$/ raise(FreedbError, val) when /^TTITLE(\d+)$/ i = $1.to_i @tracks[i]["title"] = val when /^EXTT(\d+)$/ i = $1.to_i @tracks[i]["ext"] = val end } self end