# File lib/parsers/simple-rss.rb, line 49 49: def self.parse(xml, loose) 50: begin 51: atomrss = parser.parse(xml) 52: rescue Exception => e 53: #puts "Parser #{parser} failed because #{e.message.gsub("\n",', ')}" 54: return nil 55: end 56: 57: package(atomrss) 58: end
# File lib/parsers/simple-rss.rb, line 128 128: def self.feed_id(parser) 129: overridden_value(parser, :id) || ("#{parser.link}" if parser.respond_to?(:link)) 130: end
# File lib/parsers/simple-rss.rb, line 116 116: def self.image(parser) 117: if parser.respond_to?(:image) && parser.image 118: if parser.image =~ /<url>/ # RSS image contains an <url> spec 119: parser.image.scan(/<url>(.*?)<\/url>/).to_s 120: else 121: parser.image # Atom contains just the url 122: end 123: elsif parser.respond_to?(:logo) && parser.logo 124: parser.logo 125: end 126: end
gets the value returned from the method if it overriden, otherwise nil.
# File lib/parsers/simple-rss.rb, line 133 133: def self.overridden_value(object, method) 134: object.class.public_instance_methods(false).include? method 135: end
# File lib/parsers/simple-rss.rb, line 67 67: def self.package(atomrss) 68: feed = Feed.new(self) 69: 70: # root elements 71: feed_mapping = { 72: :generator => :generator, 73: :title => :title, 74: :last_updated => [:updated, :lastBuildDate, :pubDate, :dc_date], 75: :copyright => [:copyright, :rights], 76: :authors => [:author, :webMaster, :managingEditor, :contributor], 77: :urls => :link, 78: :description => [:description, :subtitle], 79: :ttl => :ttl 80: } 81: 82: map_functions!(feed_mapping, atomrss, feed) 83: 84: # custom channel elements 85: feed.id = feed_id(atomrss) 86: feed.image = image(atomrss) 87: 88: 89: # entry elements 90: entry_mapping = { 91: :date_published => [:pubDate, :published, :dc_date, :issued], 92: :urls => :link, 93: :enclosures => :enclosure, 94: :description => [:description, :summary], 95: :content => [:content, :content_encoded, :description], 96: :title => :title, 97: :authors => [:author, :contributor, :dc_creator], 98: :categories => :category, 99: :last_updated => [:updated, :dc_date, :pubDate] 100: } 101: 102: atomrss.entries.each do |atomrss_entry| 103: feed_entry = Entry.new 104: map_functions!(entry_mapping, atomrss_entry, feed_entry) 105: 106: # custom entry elements 107: feed_entry.id = atomrss_entry.guid || atomrss_entry[:id] # entries are a Hash.. 108: feed_entry.copyright = atomrss_entry.copyright || (atomrss.respond_to?(:copyright) ? atomrss.copyright : nil) 109: 110: feed.entries << feed_entry 111: end 112: 113: feed 114: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.