Class: FeedUtils::Parser

Inherits:
Object
  • Object
show all
Includes:
LogUtils::Logging
Defined in:
lib/feedutils/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Parser

Note: lets keep/use same API as RSS::Parser for now



15
16
17
18
# File 'lib/feedutils/parser.rb', line 15

def initialize( xml )
  @xml = xml
  @atomv03helper = AtomV03Helper.new
end

Class Method Details

.parse(xml, opts = {}) ⇒ Object

convenience class/factory method



10
11
12
# File 'lib/feedutils/parser.rb', line 10

def self.parse( xml, opts={} )
  self.new( xml ).parse
end

Instance Method Details

#parseObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/feedutils/parser.rb', line 21

def parse
  logger.debug "using stdlib rss/#{RSS::VERSION}"

  ## old (obsolete) Atom Version 0.3 - try to patch/upgrade to 1.0(-ish)
  if @atomv03helper.match?( @xml )
    logger.warn "*** atom v0.3 feed; try to patch/upgrade to 1.0(-ish); please use/find atom v1.0 feed"
    parser = RSS::Parser.new( @atomv03helper.convert( @xml ))
  else
    parser = RSS::Parser.new( @xml )
  end

  parser.do_validate            = false
  parser.ignore_unknown_element = true

  puts "Parsing feed..."
  feed_wild = parser.parse  # not yet normalized

  logger.debug "  feed.class=#{feed_wild.class.name}"

  if feed_wild.is_a?( RSS::Atom::Feed )
    feed = AtomFeedBuilder.build( feed_wild )
  else  # -- assume RSS::Rss::Feed
    feed = RssFeedBuilder.build( feed_wild )
  end

  puts "== #{feed.format} / #{feed.title} =="
  feed # return new (normalized) feed
end