Sha256: 0b44315110b26321037c81c0285d808dd097a3df3f74ad5b2d8caf897dbaef37
Contents?: true
Size: 1.42 KB
Versions: 3
Compression:
Stored size: 1.42 KB
Contents
module MusicBrainz class ReleaseGroup < MusicBrainz::Base 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(:release, :release_group => self.id, :inc => [:media], :limit => 100)).css('release').each do |r| @releases << MusicBrainz::Release.parse_xml(r) end end @releases.sort{ |a, b| a.date <=> b.date } end def self.find mbid xml = Nokogiri::XML(MusicBrainz.load(:release_group, :id => mbid)).css('release-group').first self.parse_xml(xml) unless xml.nil? end def self.parse_xml xml @release_group = MusicBrainz::ReleaseGroup.new @release_group.id = self.safe_get_attr(xml, nil, 'id') @release_group.type = self.safe_get_attr(xml, nil, 'type') @release_group.title = self.safe_get_value(xml, 'title') @release_group.disambiguation = self.safe_get_value(xml, 'disambiguation') date = xml.css('first-release-date').empty? ? '2030-12-31' : xml.css('first-release-date').text if date.length == 0 date = '2030-12-31' elsif date.length == 4 date += '-12-31' elsif date.length == 7 date += '-31' end date = date.split('-') @release_group.first_release_date = Time.utc(date[0], date[1], date[2]) @release_group end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
musicbrainz-0.5.2 | lib/models/music_brainz/release_group.rb |
musicbrainz-0.5.1 | lib/models/music_brainz/release_group.rb |
musicbrainz-0.5.0 | lib/models/music_brainz/release_group.rb |