Module: MusicBrainz::Bindings::Release

Extended by:
Release
Included in:
Release
Defined in:
lib/musicbrainz/bindings/release.rb

Instance Method Summary collapse

Instance Method Details

#parse(xml) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/musicbrainz/bindings/release.rb', line 5

def parse(xml)
  xml = xml.xpath('./release') unless xml.xpath('./release').empty?
  
  hash = {
    id: (xml.attribute('id').value rescue nil),
    type: (xml.xpath('./release-group').attribute('type').value rescue nil),
    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)
  }
  
  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