Created
August 5, 2009 20:31
-
-
Save julien51/162932 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SuperParsr | |
module Atom | |
def namespaces | |
'http://www.w3.org/2005/Atom' | |
#['http://www.w3.org/2005/Atom', 'http://purl.org/atom/ns', 'http://purl.org/atom/ns#'] | |
end | |
module Feed | |
def self.included(base) | |
subs = base.subclass_and_add_parsers_for_classes([::Link, ::Author, ::Entry, ::Category]) | |
base.element :title, :xmlns => SuperParsr::Atom.namespaces, :as => :title | |
base.element :updated, :xmlns => SuperParsr::Atom.namespaces, :as => :updated_as_string | |
base.element :id, :xmlns => SuperParsr::Atom.namespaces, :as => :feed_id | |
base.elements :link, :xmlns => SuperParsr::Atom.namespaces, :as => :links, :class => subs[::Link] | |
base.elements :author, :xmlns => SuperParsr::Atom.namespaces, :as => :authors, :class => subs[::Author] | |
base.elements :entry, :xmlns => SuperParsr::Atom.namespaces, :as => :entries, :class => subs[::Entry] | |
base.elements :category, :xmlns => SuperParsr::Atom.namespaces, :as => :categories, :class => subs[::Category] | |
end | |
def self.able_to_parse?(xml) #:nodoc: | |
xml =~ /(#{Regexp.escape("http://www.w3.org/2005/Atom")})|(#{Regexp.escape("http://purl.org/atom")})/ | |
end | |
end | |
end | |
end | |
#<?xml version="1.0" encoding="utf-8"?> | |
#<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0"> | |
<title>Amazon Web Services Blog</title> | |
#</feed> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment