Checking for uniqueness

Discussion in 'Ruby' started by Jason Matthew, Nov 19, 2007.

  1. 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/.
     
    Jason Matthew, Nov 19, 2007
    #1
    1. Advertising

  2. Jason Matthew

    Pat Maddox Guest

    On Nov 18, 2007 6:18 PM, Jason Matthew <> 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
     
    Pat Maddox, Nov 19, 2007
    #2
    1. Advertising

  3. Pat Maddox wrote:
    > On Nov 18, 2007 6:18 PM, Jason Matthew <> 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/.
     
    Jason Matthew, Nov 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ognen Ivanovski
    Replies:
    0
    Views:
    945
    Ognen Ivanovski
    Jul 15, 2003
  2. Don Bate
    Replies:
    0
    Views:
    401
    Don Bate
    Jul 22, 2003
  3. Olaf Meyer

    XML schema uniqueness constraints

    Olaf Meyer, Jan 15, 2004, in forum: XML
    Replies:
    0
    Views:
    506
    Olaf Meyer
    Jan 15, 2004
  4. Victor
    Replies:
    3
    Views:
    976
    Martin Honnen
    Feb 6, 2004
  5. Adam Gardner
    Replies:
    5
    Views:
    147
    Sebastian Hungerecker
    Nov 19, 2008
Loading...

Share This Page