class AtomFeed::AtomFeed

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.

Attributes

doc[R]

Public Class Methods

new(doc) click to toggle source
# File lib/atom_feed/atom_feed.rb, line 51
def initialize(doc)
  @doc = doc
end
open(string_or_io, url = nil, encoding = nil) { |feed| ... } click to toggle source
# File lib/atom_feed/atom_feed.rb, line 55
def self.open(string_or_io, url = nil, encoding = nil)
  doc = Nokogiri::XML(string_or_io, url, encoding)
  feed = AtomFeed.new(doc)
  yield feed if block_given?
  feed
end

Public Instance Methods

authors() click to toggle source

Array of Authors (optional).

# File lib/atom_feed/atom_feed.rb, line 78
def authors
  nodes = @doc.xpath("atom:feed/atom:author", ::AtomFeed::NS) || []
  nodes.map { |node| AtomPerson.new(node) }
end
categories() click to toggle source

Array of feed categories (optional).

# 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() click to toggle source

Array of contributors (optional).

# 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() click to toggle source

Array of feed entries (optional).

# 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() click to toggle source

Generator (optional).

# 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() click to toggle source

Icon (optional).

# File lib/atom_feed/atom_feed.rb, line 115
def icon
  @doc.at_xpath("atom:feed/atom:icon", ::AtomFeed::NS).try(:content)
end
id() click to toggle source

Feed id (required).

# File lib/atom_feed/atom_feed.rb, line 63
def id
  @doc.at_xpath("atom:feed/atom:id", ::AtomFeed::NS).content
end
rights() click to toggle source

rights (optional)

# 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() click to toggle source

subtitle (optional)

# 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
title() click to toggle source

Feed title (required).

# File lib/atom_feed/atom_feed.rb, line 68
def title
  @doc.at_xpath("atom:feed/atom:title", ::AtomFeed::NS).content
end
updated() click to toggle source

Feed update date (required).

# File lib/atom_feed/atom_feed.rb, line 73
def updated
  Time.parse @doc.at_xpath("atom:feed/atom:updated", ::AtomFeed::NS).content
end