Class: FeedNormalizer::SimpleRssParser

### Home Classes Methods

### In Files

- lib/parsers/simple-rss.rb

### Parent

FeedNormalizer::Parser

### Methods

- ::feed_id
- ::image
- ::overridden_value
- ::package
- ::parse
- ::parser
- ::priority

### Files

- History.txt
- License.txt
- Manifest.txt
- README.txt

### Class/Module Index

Quicksearch

- FeedNormalizer
- FeedNormalizer::ElementCleaner
- FeedNormalizer::ElementEquality
- FeedNormalizer::Entry
- FeedNormalizer::Feed
- FeedNormalizer::FeedNormalizer
- FeedNormalizer::HtmlCleaner
- FeedNormalizer::Parser
- FeedNormalizer::ParserRegistry
- FeedNormalizer::RewriteRelativeLinks
- FeedNormalizer::RubyRssParser
- FeedNormalizer::SimpleRssParser
- FeedNormalizer::Singular
- FeedNormalizer::TimeFix
- RSS
- RSS::Rss
- RSS::Rss::Channel
- RSS::Rss::Channel::Item
- RSS::Rss::Channel::Item::Enclosure
- SimpleRSS

No matching classes.

# FeedNormalizer::SimpleRssParser

The SimpleRSS parser can handle both RSS and Atom feeds.

### Public Class Methods

parse(xml, loose) click to toggle source

    # 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

parser() click to toggle source

    # File lib/parsers/simple-rss.rb, line 45
    def self.parser
      SimpleRSS
    end

priority() click to toggle source

Fairly low priority; a slower, liberal parser.

    # File lib/parsers/simple-rss.rb, line 61
    def self.priority
      900
    end

### Protected Class Methods

feed_id(parser) click to toggle source

    # 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

image(parser) click to toggle source

    # 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

overridden_value(object, method) click to toggle source

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

package(atomrss) click to toggle source

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.