Skip to content

Instantly share code, notes, and snippets.

@djones
Created June 18, 2009 02:24
Show Gist options
  • Save djones/131656 to your computer and use it in GitHub Desktop.
Save djones/131656 to your computer and use it in GitHub Desktop.
# Came from http://snippets.dzone.com/posts/show/68
require 'rexml/document'
require 'net/http'
class RSSParser
require 'rexml/document'
def self.run(url)
xml = REXML::Document.new Net::HTTP.get(URI.parse(url))
data = {
:title => xml.root.elements['channel/title'].text,
:home_url => xml.root.elements['channel/link'].text,
:rss_url => url,
:items => []
}
xml.elements.each '//item' do |item|
new_items = {} and item.elements.each do |e|
new_items[e.name.gsub(/^dc:(\w)/,"\1").to_sym] = e.text
end
data[:items] << new_items
end
data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment