Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Checking for uniqueness

Reply
Thread Tools

Checking for uniqueness

 
 
Jason Matthew
Guest
Posts: n/a
 
      11-19-2007
I am using FeedTools to parse an rss feed and store it in my Meetings
model.

I am trying to store only unique parsed rss feeds. To check for
uniqueness, I have decided to use the Feed's link. How can I check if
there is not already a row in the database containing that feed's link.

require "myprogram_dbconnect"
require 'rubygems'
require 'feed_tools'

activerecord_connect

class Meeting < ActiveRecord::Base
has_many :comments
end

meeting =
FeedTools::Feed.open('http://projects.washingtonpost.com/congress/rss/committee-events/')

if #meeting with item.link does not allready exist in the database
puts "No new feeds to put in database"
else
meeting.items.each do |item|
Meeting.create(:title => item.title, :link => item.link,
:description => item.description,
:feed_data => item.feed_data, :feed_data_type =>
item.feed_data_type)
end

end
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Pat Maddox
Guest
Posts: n/a
 
      11-19-2007
On Nov 18, 2007 6:18 PM, Jason Matthew <(E-Mail Removed)> wrote:
> I am using FeedTools to parse an rss feed and store it in my Meetings
> model.
>
> I am trying to store only unique parsed rss feeds. To check for
> uniqueness, I have decided to use the Feed's link. How can I check if
> there is not already a row in the database containing that feed's link.
>
> require "myprogram_dbconnect"
> require 'rubygems'
> require 'feed_tools'
>
> activerecord_connect
>
> class Meeting < ActiveRecord::Base
> has_many :comments
> end
>
> meeting =
> FeedTools::Feed.open('http://projects.washingtonpost.com/congress/rss/committee-events/')
>
> if #meeting with item.link does not allready exist in the database
> puts "No new feeds to put in database"
> else
> meeting.items.each do |item|
> Meeting.create(:title => item.title, :link => item.link,
> :description => item.description,
> :feed_data => item.feed_data, :feed_data_type =>
> item.feed_data_type)
> end
>
> end
> --
> Posted via http://www.ruby-forum.com/.
>
>


You can enforce it in the model with

class Meeting < ActiveRecord::Base
has_many :comments
validates_uniqueness_of :link
end

Pat

 
Reply With Quote
 
 
 
 
Jason Matthew
Guest
Posts: n/a
 
      11-19-2007
Pat Maddox wrote:
> On Nov 18, 2007 6:18 PM, Jason Matthew <(E-Mail Removed)> wrote:
>>
>> puts "No new feeds to put in database"
>> Posted via http://www.ruby-forum.com/.
>>
>>

>
> You can enforce it in the model with
>
> class Meeting < ActiveRecord::Base
> has_many :comments
> validates_uniqueness_of :link
> end
>
> Pat


Thanks Pat! I can't believe I didnt bother just to validate it.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Subclassing Hash to enforce value uniqueness ala key uniqueness. Adam Gardner Ruby 5 11-19-2008 07:36 AM
NEWBIE: Enforcing uniqueness in XML schema Victor XML 3 02-06-2004 11:16 AM
XML schema uniqueness constraints Olaf Meyer XML 0 01-15-2004 07:38 PM
uniqueness across different child elements Don Bate XML 0 07-22-2003 10:42 PM
XML Schema keys, uniqueness based on ancestor's attribute Ognen Ivanovski XML 0 07-15-2003 02:36 PM



Advertisments