Class: AtomFeed::AtomFeed
Overview
AtomFeed::AtomFeed is the central place for working with feeds in the Atom format.
Opening an atom feed from the network or a file system is done like this:
feed = AtomFeed::AtomFeed.open(open("http://example.com/atom.xml"))
If you have a file you should do:
f = File.open("feed.xml")
feed = AtomFeed::AtomFeed.open(f)
f.close
If you have an XML string you can do:
feed = AtomFeed::AtomFeed.open("<feed ...")
One can open and parse the feed like so:
AtomFeed::AtomFeed.open(...) do |feed|
puts feed.title
feed.entries do |entry|
puts entry.title
end
end
You can access OpenSearch extensions by using AtomFeed.open_search
. Access to other embedded XML types are available by using AtomFeed.doc+ directly. It's a Nokogiri::XML
instance.
AtomFeed uses Nokogiri for parsing.
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Class Method Summary collapse
Instance Method Summary collapse
-
#authors ⇒ Object
Array of Authors (optional).
-
#categories ⇒ Object
Array of feed categories (optional).
-
#contributors ⇒ Object
Array of contributors (optional).
-
#entries ⇒ Object
Array of feed entries (optional).
-
#generator ⇒ Object
Generator (optional).
-
#icon ⇒ Object
Icon (optional).
-
#id ⇒ Object
Feed id (required).
-
#initialize(doc) ⇒ AtomFeed
constructor
A new instance of AtomFeed.
-
#links ⇒ Object
Array of links (optional).
-
#logo ⇒ Object
Logo (optional).
-
#open_search ⇒ Object
Open Search extensions (optional).
-
#rights ⇒ Object
rights (optional).
-
#subtitle ⇒ Object
subtitle (optional).
-
#title ⇒ Object
Feed title (required).
-
#updated ⇒ Object
Feed update date (required).
Constructor Details
#initialize(doc) ⇒ AtomFeed
Returns a new instance of AtomFeed.
51 52 53 |
# File 'lib/atom_feed/atom_feed.rb', line 51 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
49 50 51 |
# File 'lib/atom_feed/atom_feed.rb', line 49 def doc @doc end |
Class Method Details
Instance Method Details
#authors ⇒ Object
Array of Authors (optional).
78 79 80 81 |
# File 'lib/atom_feed/atom_feed.rb', line 78 def nodes = @doc.xpath("atom:feed/atom:author", ::AtomFeed::NS) || [] nodes.map { |node| AtomPerson.new(node) } end |
#categories ⇒ Object
Array of feed categories (optional).
96 97 98 99 |
# File 'lib/atom_feed/atom_feed.rb', line 96 def categories nodes = @doc.xpath("atom:feed/atom:category", ::AtomFeed::NS) || [] nodes.map { |node| AtomCategory.new(node) } end |
#contributors ⇒ Object
Array of contributors (optional).
102 103 104 105 |
# File 'lib/atom_feed/atom_feed.rb', line 102 def contributors nodes = @doc.xpath("atom:feed/atom:contributor", ::AtomFeed::NS) || [] nodes.map { |node| AtomPerson.new(node) } end |
#entries ⇒ Object
Array of feed entries (optional).
90 91 92 93 |
# File 'lib/atom_feed/atom_feed.rb', line 90 def entries nodes = @doc.xpath("atom:feed/atom:entry", ::AtomFeed::NS) || [] nodes.map { |node| AtomFeedEntry.new(node) } end |
#generator ⇒ Object
Generator (optional).
108 109 110 111 112 |
# File 'lib/atom_feed/atom_feed.rb', line 108 def generator node = @doc.at_xpath("atom:feed/atom:generator", ::AtomFeed::NS) return nil unless node AtomGenerator.new(node) end |
#icon ⇒ Object
Icon (optional).
115 116 117 |
# File 'lib/atom_feed/atom_feed.rb', line 115 def icon @doc.at_xpath("atom:feed/atom:icon", ::AtomFeed::NS).try(:content) end |
#id ⇒ Object
Feed id (required).
63 64 65 |
# File 'lib/atom_feed/atom_feed.rb', line 63 def id @doc.at_xpath("atom:feed/atom:id", ::AtomFeed::NS).content end |
#links ⇒ Object
Array of links (optional).
84 85 86 87 |
# File 'lib/atom_feed/atom_feed.rb', line 84 def links nodes = @doc.xpath("atom:feed/atom:link", ::AtomFeed::NS) || [] nodes.map { |node| AtomLink.new(node) } end |
#logo ⇒ Object
Logo (optional).
120 121 122 |
# File 'lib/atom_feed/atom_feed.rb', line 120 def logo @doc.at_xpath("atom:feed/atom:logo", ::AtomFeed::NS).try(:content) end |
#open_search ⇒ Object
Open Search extensions (optional)
139 140 141 |
# File 'lib/atom_feed/atom_feed.rb', line 139 def open_search @open_search ||= OpenSearch.new(@doc) end |
#rights ⇒ Object
rights (optional)
125 126 127 128 129 |
# File 'lib/atom_feed/atom_feed.rb', line 125 def rights node = @doc.at_xpath("atom:feed/atom:rights", ::AtomFeed::NS) return nil unless node AtomText.new(node) end |
#subtitle ⇒ Object
subtitle (optional)
132 133 134 135 136 |
# File 'lib/atom_feed/atom_feed.rb', line 132 def subtitle node = @doc.at_xpath("atom:feed/atom:subtitle", ::AtomFeed::NS) return nil unless node AtomText.new(node) end |