oldhaven/lib/discogs.rb

34 lines
867 B
Ruby

class Discogs
def self.artists
File.open('tmp/data/discogs_artists.xml') do |file|
Nokogiri::XML::Reader.from_io(file).each do |node|
if node.name == 'artist' and node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
self.process_artist Nokogiri::XML(node.outer_xml).root
end
end
end
end
def self.process_artist node
artist = Artist.new(
:name => (node.css('name').first.text),
:pic_url => (node.css('images > image[type="primary"]').first.text unless node.css('images > image[type="primary"]').empty?),
:status => 1
)
artist.save
node.css('namevariations > name, aliases > name').each do |v|
ArtistAlias.new(
:artist_id => artist.id,
:name => v.text
).save
end
end
def self.releases
end
def self.process_release
end
end