# File lib/parsers/simple-rss.rb, line 49 def self.parse(xml, loose) begin atomrss = parser.parse(xml) rescue Exception => e #puts "Parser #{parser} failed because #{e.message.gsub("\n",', ')}" return nil end package(atomrss) end
# File lib/parsers/simple-rss.rb, line 128 def self.feed_id(parser) overridden_value(parser, :id) || ("#{parser.link}" if parser.respond_to?(:link)) end
# File lib/parsers/simple-rss.rb, line 116 def self.image(parser) if parser.respond_to?(:image) && parser.image if parser.image =~ /<url>/ # RSS image contains an <url> spec parser.image.scan(/<url>(.*?)<\/url>/).to_s else parser.image # Atom contains just the url end elsif parser.respond_to?(:logo) && parser.logo parser.logo end end
gets the value returned from the method if it overriden, otherwise nil.
# File lib/parsers/simple-rss.rb, line 133 def self.overridden_value(object, method) object.class.public_instance_methods(false).include? method end
# File lib/parsers/simple-rss.rb, line 67 def self.package(atomrss) feed = Feed.new(self) # root elements feed_mapping = { :generator => :generator, :title => :title, :last_updated => [:updated, :lastBuildDate, :pubDate, :dc_date], :copyright => [:copyright, :rights], :authors => [:author, :webMaster, :managingEditor, :contributor], :urls => :link, :description => [:description, :subtitle], :ttl => :ttl } map_functions!(feed_mapping, atomrss, feed) # custom channel elements feed.id = feed_id(atomrss) feed.image = image(atomrss) # entry elements entry_mapping = { :date_published => [:pubDate, :published, :dc_date, :issued], :urls => :link, :enclosures => :enclosure, :description => [:description, :summary], :content => [:content, :content_encoded, :description], :title => :title, :authors => [:author, :contributor, :dc_creator], :categories => :category, :last_updated => [:updated, :dc_date, :pubDate] } atomrss.entries.each do |atomrss_entry| feed_entry = Entry.new map_functions!(entry_mapping, atomrss_entry, feed_entry) # custom entry elements feed_entry.id = atomrss_entry.guid || atomrss_entry[:id] # entries are a Hash.. feed_entry.copyright = atomrss_entry.copyright || (atomrss.respond_to?(:copyright) ? atomrss.copyright : nil) feed.entries << feed_entry end feed end
Generated with the Darkfish Rdoc Generator 2.