Module: Feedjira

Extended by:
Configuration
Defined in:
lib/feedjira.rb,
lib/feedjira/feed.rb,
lib/feedjira/parser.rb,
lib/feedjira/version.rb,
lib/feedjira/parser/rss.rb,
lib/feedjira/parser/atom.rb,
lib/feedjira/preprocessor.rb,
lib/feedjira/configuration.rb,
lib/feedjira/feed_utilities.rb,
lib/feedjira/parser/json_feed.rb,
lib/feedjira/parser/rss_entry.rb,
lib/feedjira/parser/rss_image.rb,
lib/feedjira/parser/atom_entry.rb,
lib/feedjira/parser/itunes_rss.rb,
lib/feedjira/parser/atom_youtube.rb,
lib/feedjira/rss_entry_utilities.rb,
lib/feedjira/atom_entry_utilities.rb,
lib/feedjira/feed_entry_utilities.rb,
lib/feedjira/parser/json_feed_item.rb,
lib/feedjira/parser/itunes_rss_item.rb,
lib/feedjira/parser/podlove_chapter.rb,
lib/feedjira/parser/rss_feed_burner.rb,
lib/feedjira/parser/atom_feed_burner.rb,
lib/feedjira/parser/google_docs_atom.rb,
lib/feedjira/parser/itunes_rss_owner.rb,
lib/feedjira/parser/atom_google_alerts.rb,
lib/feedjira/parser/atom_youtube_entry.rb,
lib/feedjira/parser/itunes_rss_category.rb,
lib/feedjira/parser/rss_feed_burner_entry.rb,
lib/feedjira/parser/atom_feed_burner_entry.rb,
lib/feedjira/parser/google_docs_atom_entry.rb,
lib/feedjira/parser/atom_google_alerts_entry.rb,
lib/feedjira/parser/globally_unique_identifier.rb

Overview

Feedjira::Configuration

Defined Under Namespace

Modules: AtomEntryUtilities, Configuration, FeedEntryUtilities, FeedUtilities, Parser, RSSEntryUtilities Classes: Feed, Preprocessor

Constant Summary collapse

NoParserAvailable =
Class.new(StandardError)
VERSION =
"3.2.3"

Instance Attribute Summary

Attributes included from Configuration

#logger, #parsers, #strip_whitespace

Class Method Summary collapse

Methods included from Configuration

configure, extended, reset_configuration!, set_default_configuration

Class Method Details

.parse(xml, parser: nil, &block) ⇒ Object

Parse XML with first compatible parser

Examples:

xml = HTTParty.get("http://example.com").body
Feedjira.parse(xml)


55
56
57
58
59
60
61
62
63
# File 'lib/feedjira.rb', line 55

def parse(xml, parser: nil, &block)
  parser ||= parser_for_xml(xml)

  if parser.nil?
    raise NoParserAvailable, "No valid parser for XML."
  end

  parser.parse(xml, &block)
end

.parser_for_xml(xml) ⇒ Object

Find compatible parser for given XML

Examples:

xml = HTTParty.get("http://example.com").body
parser = Feedjira.parser_for_xml(xml)
parser.parse(xml)


72
73
74
75
# File 'lib/feedjira.rb', line 72

def parser_for_xml(xml)
  start_of_doc = xml.slice(0, 2000)
  Feedjira.parsers.detect { |klass| klass.able_to_parse?(start_of_doc) }
end