Prev | Current Page 313 | Next

David Berube

"Practical Reporting with Ruby and Rails"

title=feed_story.title.gsub(/<[^>]*>/, '') # strip HTML
new_story.guid=feed_story.guid
new_story.sourcename=feed_story.publisher.name if feed_story.publisher.name
new_story.url=feed_story.link
new_story.published_at = feed_story.published
new_story.save
end
else
# do nothing
end
end
end
If the feed isn??™t live??”in other words, if it??™s cached??”you print a brief message stating
that, and then print the date of when it was last cached and when the cache will expire.
(You could go through the data-insertion loop either way, but cached feed items are
guaranteed to be in the database already, so that would just be a waste of time.) Note that
some programmers believe that unless feed.live? is better written as if not feed.live?.
If the feed is live, you iterate through all of the items in the feed by using the items
method. You check if any stories exist with the same title, url, or guid; if none exist, you
add the story to the database. Otherwise, the story is a duplicate and you don??™t add the
item.


Pages:
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
Mika Modjo Sarah McLachlan sprzedam wózek Rok 2001 / MMI