lib/models/music_brainz/release_group.rb in musicbrainz-0.4.1 vs lib/models/music_brainz/release_group.rb in musicbrainz-0.4.2

- old
+ new

@@ -1,18 +1,18 @@ module MusicBrainz class ReleaseGroup - attr_accessor :id, :type, :title, :first_release_date + attr_accessor :id, :type, :title, :disambiguation, :first_release_date @releases def releases if @releases.nil? and not self.id.nil? @releases = [] Nokogiri::XML(MusicBrainz.load('http://musicbrainz.org/ws/2/release/?release-group=' + self.id + '&limit=100')).css('release').each do |r| @releases << MusicBrainz::Release.parse_xml(r) end end - @releases + @releases.sort{ |a, b| a.date <=> b.date } end def self.find mbid xml = Nokogiri::XML(MusicBrainz.load('http://musicbrainz.org/ws/2/release-group/' + mbid)).css('release-group').first self.parse_xml(xml) unless xml.nil? @@ -20,21 +20,21 @@ def self.parse_xml xml @release_group = MusicBrainz::ReleaseGroup.new @release_group.id = xml.attr('id') @release_group.type = xml.attr('type') - @release_group.title = xml.css('title').text unless xml.css('title').empty? - date = nil - date = xml.css('first-release-date').text unless xml.css('first-release-date').empty? - unless date.nil? or date.empty? - if date.length == 4 - date += '-01-01' - elsif date.length == 7 - date += '-01' - end - date = Time.parse(date) + @release_group.title = xml.css('title').text + @release_group.disambiguation = xml.css('disambiguation').empty? ? '' : xml.css('disambiguation').text + date = xml.css('first-release-date').empty? ? '9999-12-31' : xml.css('first-release-date').text + if date.length == 0 + date = '9999-12-31' + elsif date.length == 4 + date += '-12-31' + elsif date.length == 7 + date += '-31' end - @release_group.first_release_date = date + date = date.split('-') + @release_group.first_release_date = Time.utc(date[0], date[1], date[2]) @release_group end end end