Class: FeedParser

Inherits:
Object
  • Object
show all
Defined in:
lib/feed_parser.rb,
lib/feed_parser/dsl.rb,
lib/feed_parser/feed.rb,
lib/feed_parser/feed_item.rb,
lib/feed_parser/self_sanitizer.rb

Defined Under Namespace

Classes: AtomItem, Dsl, Feed, FeedItem, InvalidURI, RssItem, SelfSanitizer, UnknownFeedType

Constant Summary collapse

USER_AGENT =
"Ruby / FeedParser gem"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ FeedParser

Returns a new instance of FeedParser.



16
17
18
19
20
21
22
23
# File 'lib/feed_parser.rb', line 16

def initialize(opts)
  @url = opts[:url]
  @http_options = {"User-Agent" => FeedParser::USER_AGENT}.merge(opts[:http] || {})
  @@sanitizer = (opts[:sanitizer] || SelfSanitizer.new)
  @@fields_to_sanitize = (opts[:fields_to_sanitize] || [:content])
  @feed_xml = opts[:feed_xml]
  self
end

Class Method Details

.fields_to_sanitizeObject



29
30
31
# File 'lib/feed_parser.rb', line 29

def self.fields_to_sanitize
  @@fields_to_sanitize
end

.parse(opts) ⇒ Object



11
12
13
14
# File 'lib/feed_parser.rb', line 11

def self.parse(opts)
  fp = FeedParser.new(opts)
  fp.parse
end

.sanitizerObject



25
26
27
# File 'lib/feed_parser.rb', line 25

def self.sanitizer
  @@sanitizer
end

Instance Method Details

#parseObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/feed_parser.rb', line 33

def parse
  if @feed_xml
    feed_xml = @feed_xml
  else
    feed_xml = open_or_follow_redirect(@url)
  end
  @feed ||= Feed.new(feed_xml)
  feed_xml.close! if feed_xml.class.to_s == 'Tempfile'
  @feed
end