Skip to content

Instantly share code, notes, and snippets.

@julien51
Created August 5, 2009 20:30
Show Gist options
  • Save julien51/162930 to your computer and use it in GitHub Desktop.
Save julien51/162930 to your computer and use it in GitHub Desktop.
module SuperParsr
module Atom
def namespaces
"http://www.w3.org/2005/Atom"
# [nil, '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 => [], :as => :title
base.element :updated, :xmlns => [], :as => :updated_as_string
base.element :id, :xmlns => [], :as => :feed_id
base.elements :link, :xmlns => [], :as => :links, :class => subs[::Link]
base.elements :author, :xmlns => [], :as => :authors, :class => subs[::Author]
base.elements :entry, :xmlns => [], :as => :entries, :class => subs[::Entry]
base.elements :category, :xmlns => [], :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