Okay,
The end result was modifying the model for the table I was working with
to do the following:
class RushingOffense < ActiveRecord::Base
def scrape
offensive_rushing =
Scraper.new('http://web1.ncaa.org/mfb/natlRank.jsp?year=2008&rpt=IA_teamrush&site=org',
'table', 'statstable', '//tr')
offensive_rushing.scrape_data
offensive_rushing.clean_celldata
start_date = Time.now.beginning_of_week
end_date = Time.now.end_of_week
current_date = Time.now
@rushing_offenses = RushingOffense.find(:all, :conditions =>
['compiled_on > ? and compiled_on < ?', start_date, end_date])
if @rushing_offenses == [] #means we have an empty array
for i in 0..offensive_rushing.numrows-1
puts "Updating Offensive Rushing Statistics for
#{offensive_rushing.rows[i][1]}."
RushingOffense.create(:rank => offensive_rushing.rows[i][0],
:name => offensive_rushing.rows[i][1],
:games => offensive_rushing.rows[i][2],
:carries => offensive_rushing.rows[i][3],
:net => offensive_rushing.rows[i][4],
:avg => offensive_rushing.rows[i][5],
:tds => offensive_rushing.rows[i][6],
:ydspg => offensive_rushing.rows[i][7],
:wins => offensive_rushing.rows[i][8],
:losses => offensive_rushing.rows[i][9],
:ties => offensive_rushing.rows[i][10],
:compiled_on => current_date)
end
end
if @rushing_offenses != [] #means the current week's data is not
empty
puts "Current Week's Data Is Already Populated!"
end
end
end
This code works 100% and doesn't overlap.
However, if you could take a look at this code and let me know if
there's something I should change to make it "better" or follow "best
practices" to shorten or make it more efficient, I would be
appreciative.
I feel great now having completed my first difficult action with rails.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---