Class: FeedNormalizer::FeedNormalizer

### Home Classes Methods

### In Files

- lib/feed-normalizer.rb

### Parent

Object

### Methods

- ::parse

### 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::FeedNormalizer

### Public Class Methods

parse(xml, opts = {}) click to toggle source

Parses the given xml and attempts to return a normalized Feed object. Setting `force_parser` to a suitable parser will mean that parser is used first, and if `try_others` is false, it is the only parser used, otherwise all parsers in the ParserRegistry are attempted, in order of priority.

### Available options

- `:force_parser` - instruct feed-normalizer to try the specified parser first. Takes a class, such as RubyRssParser, or SimpleRssParser.

- `:try_others` - `true` or `false`, defaults to `true`. If `true`, other parsers will be used as described above. The option is useful if combined with `force_parser` to only use a single parser.

- `:loose` - `true` or `false`, defaults to `false`.

  Specifies parsing should be done loosely. This means that when feed-normalizer would usually throw away data in order to meet the requirement of keeping resulting feed outputs the same regardless of the underlying parser, the data will instead be kept. This currently affects the following items:

  - Categories: RSS allows for multiple categories per feed item.

    - Limitation: SimpleRSS can only return the first category for an item.

    - Result: When loose is true, the extra categories are kept, of course, only if the parser is not SimpleRSS.

    # File lib/feed-normalizer.rb, line 117
    def self.parse(xml, opts = {})

      # Get a string ASAP, as multiple read()'s will start returning nil..
      xml = xml.respond_to?(:read) ? xml.read : xml.to_s

      if opts[:force_parser]
        result = opts[:force_parser].parse(xml, opts[:loose])

        return result if result
        return nil if opts[:try_others] == false
      end

      ParserRegistry.parsers.each do |parser|
        result = parser.parse(xml, opts[:loose])
        return result if result
      end

      # if we got here, no parsers worked.
      return nil
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.