Skip to content

Instantly share code, notes, and snippets.

@nz
Forked from new2/user.rb
Created May 14, 2011 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nz/971860 to your computer and use it in GitHub Desktop.
Save nz/971860 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_accessible :email, :name
validates :email, :presence => true
validates :name, :presence => true
validates_uniqueness_of :email, :scope => :user
has_many :song_entries
has_many :songs, :through => :song_entries
require 'open-uri'
def get_data(url)
doc.xpath('//rss/channel/item').each do |node|
song = {
:track => node.xpath('mm:Track/dc:title').text.strip.downcase,
:artist => node.xpath('mm:Artist/dc:title').text.strip.downcase,
:artwork => node.xpath('albumArtUrl').text.strip
}
songs << song
populate(song)
end
end
def populate(song)
s = Song.find_or_create_by_track_and_artist_and_artworkUrl(
:track => song[:track],
:artist => song[:artist],
:artworkUrl => song[:artwork]
)
song_entries.find_or_create_by_song_id(:song_id => s.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment