Module: PoliticoRSS
- Defined in:
- lib/politico_rss.rb,
lib/politico_rss/version.rb
Overview
A module for parsing POLITICO RSS feeds (http://www.politico.com/rss).
Constant Summary collapse
- VERSION =
Please observe semantic versioning (http://semver.org/).
"1.0.0"
Class Method Summary collapse
-
.feed(feed_name) ⇒ Hash
Request information about, and contents of, a given RSS feed.
Class Method Details
.feed(feed_name) ⇒ Hash
Request information about, and contents of, a given RSS feed.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/politico_rss.rb', line 19 def self.feed(feed_name) feed_url = "http://www.politico.com/rss/#{feed_name}.xml" doc = Nokogiri::XML(open(feed_url)) response = Hash.from_xml(doc.to_s) response = response["rss"]["channel"] response = response.to_snake_keys # rename "pubDate" attribute to "pub_date", and rename any other camel-cased keys that might exist in the future response[:link] = response[:link][0][:href] unless response[:link].kind_of?(String) # simplify "link" attribute from a Hash to a String (if necessary - sometimes its just a string) response[:items] = response.delete(:item) # rename "item" attribute to "items" response[:items] = [response[:items]] unless response[:items].kind_of?(Array) # ensure the "items" attribute is an array, even if there is only one item, in which case it was a hash return response end |