1
0
Fork 0
musicbrainz/lib/musicbrainz/bindings/release.rb

34 lines
1.1 KiB
Ruby
Raw Normal View History

# -*- encoding : utf-8 -*-
2012-10-12 12:45:51 +00:00
module MusicBrainz
module Bindings
module Release
def parse(xml)
xml = xml.xpath('./release') unless xml.xpath('./release').empty?
hash = {
2012-10-12 12:45:51 +00:00
id: (xml.attribute('id').value rescue nil),
2013-01-24 20:12:58 +00:00
type: (xml.xpath('./release-group').attribute('type').value rescue nil),
2012-10-12 12:45:51 +00:00
title: (xml.xpath('./title').text rescue nil),
status: (xml.xpath('./status').text rescue nil),
country: (xml.xpath('./country').text rescue nil),
date: (xml.xpath('./date').text rescue nil),
asin: (xml.xpath('./asin').text rescue nil),
barcode: (xml.xpath('./barcode').text rescue nil),
quality: (xml.xpath('./quality').text rescue nil)
2012-10-12 12:45:51 +00:00
}
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
2012-10-12 12:45:51 +00:00
end
extend self
end
end
end