Class: Syndication::Atom::Parser

Inherits:
Syndication::AbstractParser show all
Includes:
REXML::StreamListener
Defined in:
lib/syndication/atom.rb

Overview

A parser for Atom feeds. See Syndication::Parser in common.rb for the abstract class this specializes.

Constant Summary

CLASS_FOR_TAG =

:stopdoc: A hash of tags which require the creation of new objects, and the class to use for creating the object.

{
  'entry' => Entry,
  'author' => Person,
  'contributor' => Person,
  'title' => Data,
  'subtitle' => Data,
  'summary' => Data,
  'link' => Link,
  'source' => Feed,
  'category' => Category,
  'content' => Content
}

Constants inherited from Syndication::AbstractParser

Syndication::AbstractParser::KNOWN_NAMESPACES

Instance Method Summary (collapse)

Methods inherited from Syndication::AbstractParser

#cdata, #define_namespace, #end_tag, #handle_namespace, #initialize, #parse, #store, #tag_end, #tag_start

Constructor Details

This class inherits a constructor from Syndication::AbstractParser

Instance Method Details

- (Object) feed

The most recently parsed feed as a Syndication::Feed object.



523
524
525
# File 'lib/syndication/atom.rb', line 523

def feed
  return @parsetree
end

- (Object) reset

Reset the parser ready to parse a new feed.



513
514
515
516
517
518
519
520
# File 'lib/syndication/atom.rb', line 513

def reset
  # Set up an empty Feed object and make it the current object
  @parsetree = Feed.new(nil)
  # Set up the class-for-tag hash
  @class_for_tag = CLASS_FOR_TAG
  # Everything else is common to both kinds of parser
  super
end

- (Object) text(s)

Called when REXML finds a text fragment. For Atom parsing, we need to handle Data objects specially: They need all events passed through verbatim, because they might contain XHTML which will be sent through as REXML events and will need to be reconstructed.



501
502
503
504
505
506
507
508
509
# File 'lib/syndication/atom.rb', line 501

def text(s)
  if @current_object.kind_of?(Data)
    @current_object.text(s)
    return
  end
  if @textstack.last
    @textstack.last << s
  end
end