class TinyAtom::Feed

Attributes

entries[R]
feed_options[R]
feed_url[R]
site_domain[R]
site_url[R]
title[R]

Public Class Methods

new(site_url, title, feed_url, options={}) click to toggle source
# File lib/tinyatom/feed.rb, line 9
def initialize(site_url, title, feed_url, options={})
  @site_url, @title, @feed_url, @feed_options = site_url, title, feed_url,
    options

  @site_domain = URI(@site_url).extend(TinyAtom::URIDomain).domain

  @entries = []
end

Public Instance Methods

add_entry(id, title, updated, link, options={}) click to toggle source

Add an entry to the feed

# File lib/tinyatom/feed.rb, line 19
def add_entry(id, title, updated, link, options={})
  entries << {
    :id => id,
    :title => title,
    :updated => updated,
    :link => link
    }.merge(options)
end
entry_id(e) click to toggle source

Build an entry id.

# File lib/tinyatom/feed.rb, line 70
def entry_id(e)
  # http://diveintomark.org/archives/2004/05/28/howto-atom-id
  "tag:#{site_domain},#{e[:updated].strftime('%Y-%m-%d')}:#{e[:id]}"
end
make(options={}) click to toggle source

Build the feed and return a Builder::XmlMarkup.

# File lib/tinyatom/feed.rb, line 29
def make(options={})
  xm = Builder::XmlMarkup.new(options)
  xm.instruct! :xml

  xm.feed(:xmlns => 'http://www.w3.org/2005/Atom',
    :'xmlns:media' => 'http://search.yahoo.com/mrss/') {
    xm.title title
    xm.link :href => feed_url, :rel => 'self'
    if u = updated
      xm.updated u.xmlschema
    end
    xm.id site_url
    TinyAtom::author xm, feed_options
    feed_options.fetch(:hubs, []).each do |hub|
      xm.link :rel => 'hub', :href => hub
    end

    entries.each do |e|
      xm.entry {
        xm.title e[:title]
        xm.link :href => e[:link]
        xm.id entry_id(e)
        xm.updated e[:updated].xmlschema
        xm.summary(e[:summary])  if e[:summary]
        xm.content(e[:content])  if e[:content]

        (e[:authors] || [e]).each { |h| TinyAtom::author xm, h }
        (e[:enclosures] || [e]).each { |h| TinyAtom::enclosure xm, h }
        (e[:media_thumbnails] || [e]).each do |h|
          TinyAtom::media_thumbnail xm, h
        end
        TinyAtom::via xm, e
      }
    end
  }
end
updated() click to toggle source

Return the last update time of the feed.

# File lib/tinyatom/feed.rb, line 67
def updated; entries.map { |e| e[:updated] }.max; end