1
0
Fork 0
musicbrainz/lib/models/music_brainz_artist.rb

31 lines
1.0 KiB
Ruby

class MusicBrainzArtist
attr_accessor :id, :type, :name, :country, :date_begin, :date_end
@release_groups
def release_groups
if @release_groups.nil? and not self.id.nil?
@release_groups = []
Nokogiri::XML(open('http://musicbrainz.org/ws/2/release-group/?artist=' + self.id)).css('release-group').each do |rg|
@release_groups << MusicBrainzReleaseGroup.parse_xml(rg)
end
end
@release_groups
end
def self.find mbid
@artist = self.parse_xml(Nokogiri::XML(open('http://musicbrainz.org/ws/2/artist/' + mbid)))
end
def self.parse_xml xml
@artist = MusicBrainzArtist.new
@artist.id = xml.css('artist').attr('id').value
@artist.type = xml.css('artist').attr('type').value
@artist.name = xml.css('artist > name').text
@artist.country = xml.css('artist > country').text || nil
@artist.date_begin = xml.css('artist > life-span > begin').text || nil
@artist.date_end = xml.css('artist > life-span > end').text || nil
@artist
end
end