Handle different cases of release's format attribute.

This commit is contained in:
Mathias Gawlista
2013-01-18 18:31:30 +01:00
parent 0d2c12ffc2
commit 75a536d373
2 changed files with 54 additions and 2 deletions
+11 -2
View File
@@ -3,14 +3,23 @@ module MusicBrainz
module Release
def parse(xml)
xml = xml.xpath('./release') unless xml.xpath('./release').empty?
{
hash = {
id: (xml.attribute('id').value rescue nil),
title: (xml.xpath('./title').text rescue nil),
status: (xml.xpath('./status').text rescue nil),
country: (xml.xpath('./country').text rescue nil),
format: (xml.xpath('./medium-list/medium/format').text rescue nil),
date: (xml.xpath('./date').text rescue nil)
}
formats = (xml.xpath('./medium-list/medium/format') rescue []).map(&:text)
hash[:format] = formats.uniq.map do |format|
format_count = formats.select{|f| f == format}.length
format_count == 1 ? format : "#{format_count}x#{format}"
end.join(' + ')
hash
end
extend self