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/date_time_utilities.rb,
lib/feedjira/parser/atom_youtube.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_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/date_time_utilities/date_time_epoch_parser.rb,
lib/feedjira/date_time_utilities/date_time_pattern_parser.rb,
lib/feedjira/date_time_utilities/date_time_language_parser.rb

Overview

Feedjira::Configuration

Defined Under Namespace

Modules: Configuration, DateTimeUtilities, FeedEntryUtilities, FeedUtilities, Parser Classes: Feed, Preprocessor

Constant Summary collapse

NoParserAvailable =
Class.new(StandardError)
VERSION =
"3.0.0.beta1".freeze

Instance Attribute Summary

Attributes included from Configuration

#logger, #parsers

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)


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

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)


70
71
72
73
# File 'lib/feedjira.rb', line 70

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