class RSSFeed::RSSChannel

RSSFeed::RSSChannel is the central place for working with feeds in the RSS format.

Opening an RSS feed from the network or a file system is done like this:

feed = RSSFeed::RSSChannel.open(open("http://example.com/rss.xml"))

If you have a file you should do:

f = File.open("rss.xml")
feed = RSSFeed::RSSChannel.open(f)
f.close

If you have an XML string you can do:

feed = RSSFeed::RSSChannel.open("<rss version='1.0'> ...")

One can open and parse the feed like so:

RSSFeed::RSSChannel.open(...) do |feed|
  puts feed.title
  feed.items do |item|
    puts item.title
  end
end

You can access OpenSearch extensions by using RSSChannel.open_search. Access to other embedded XML types are available by using RSSChannel.doc+ directly. It's a Nokogiri::XML instance.

RSSFeed uses Nokogiri for parsing.

Attributes

doc[R]

Public Class Methods

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

Public Instance Methods

category() click to toggle source

Category (optional).

# File lib/rss_feed/rss_channel.rb, line 107
def category
  if node = @doc.at_xpath("rss/channel/category")
    RSSCategory.new(node)
  end
end
cloud() click to toggle source

Cloud (optional)

# File lib/rss_feed/rss_channel.rb, line 124
def cloud
  if node = @doc.at_xpath("rss/channel/cloud")
    RSSCloud.new(node)
  end
end
description() click to toggle source

Description (required).

# File lib/rss_feed/rss_channel.rb, line 73
def description
  @doc.at_xpath("rss/channel/description").content
end
docs() click to toggle source

Documentation link (optional).

# File lib/rss_feed/rss_channel.rb, line 119
def docs
  @doc.at_xpath("rss/channel/docs").try(:content)
end
generator() click to toggle source

Generator (optional).

# File lib/rss_feed/rss_channel.rb, line 114
def generator
  @doc.at_xpath("rss/channel/generator").try(:content)
end
image() click to toggle source

Image (optional).

# File lib/rss_feed/rss_channel.rb, line 136
def image
  if node = @doc.at_xpath("rss/channel/image")
    RSSImage.new(node)
  end
end
items() click to toggle source

Array of channel items (optional).

# File lib/rss_feed/rss_channel.rb, line 165
def items
  nodes = @doc.xpath("rss/channel/item") || []
  nodes.map { |node| RSSChannelItem.new(node) }
end
language() click to toggle source

Language (optional).

# File lib/rss_feed/rss_channel.rb, line 78
def language
  @doc.at_xpath("rss/channel/language").try(:content)
end
last_build_date() click to toggle source

Last build date (optional).

# File lib/rss_feed/rss_channel.rb, line 100
def last_build_date
  if date = @doc.at_xpath("rss/channel/lastBuildDate").try(:content)
    Time.rfc822(date)
  end
end
managing_editor() click to toggle source

Managing editor (optional).

# File lib/rss_feed/rss_channel.rb, line 88
def managing_editor
  @doc.at_xpath("rss/channel/managingEditor").try(:content)
end
pub_date() click to toggle source

Publication date (optional).

# File lib/rss_feed/rss_channel.rb, line 93
def pub_date
  if date = @doc.at_xpath("rss/channel/pubDate").try(:content)
    Time.rfc822(date)
  end
end
rating() click to toggle source

PICS rating (optional).

# File lib/rss_feed/rss_channel.rb, line 143
def rating
  @doc.at_xpath("rss/channel/rating").try(:content)
end
skip_days() click to toggle source

Hint for aggregators telling them which days they can skip (optional).

# File lib/rss_feed/rss_channel.rb, line 160
def skip_days
  @doc.at_xpath("rss/channel/skipDays").try(:content).nonzero?
end
skip_hours() click to toggle source

Hint for aggregators telling them which hours they can skip (optional).

# File lib/rss_feed/rss_channel.rb, line 155
def skip_hours
  @doc.at_xpath("rss/channel/skipHours").try(:content).nonzero?
end
text_input() click to toggle source

Text input box (optional).

# File lib/rss_feed/rss_channel.rb, line 148
def text_input
  if node = @doc.at_xpath("rss/channel/textInput")
    RSSTextInput.new(node)
  end
end
title() click to toggle source

Title (required).

# File lib/rss_feed/rss_channel.rb, line 63
def title
  @doc.at_xpath("rss/channel/title").content
end
ttl() click to toggle source

Time to live in minutes (optional).

# File lib/rss_feed/rss_channel.rb, line 131
def ttl
  @doc.at_xpath("rss/channel/ttl").try(:content).nonzero?
end