class SemanticCrawler::Gdacs::Feed

The GDACS.org RSS feed contains the latest crisis information about the following crisis types:

Attributes

url[R]

The gdacs.org RSS feed URL. (default: www.gdacs.org/xml/rss.xml)

Public Class Methods

new(new_url = "http://www.gdacs.org/xml/rss.xml") click to toggle source

Initializes the gdacs.org feed URL. If not specified the default URL (www.gdacs.org/xml/rss.xml) is used. Normally the feed URL should not be changed.

# File lib/semantic_crawler/gdacs/feed.rb, line 26
def initialize(new_url = "http://www.gdacs.org/xml/rss.xml")
    @url = new_url
    @root_node = nil
    begin
        fetch_feed
    rescue => e
        $log.error("Not able to get country information, through exception: #{e}")
    end
end

Public Instance Methods

description() click to toggle source

Get rss/channel/description

# File lib/semantic_crawler/gdacs/feed.rb, line 47
def description
    query_root_node("description/text()")
end
items() click to toggle source

Get rss/channel/item*

# File lib/semantic_crawler/gdacs/feed.rb, line 72
def items
   nodeset = query_root_node("item")
   @items = []
   if !nodeset.nil?
       nodeset.each do |item|
           item_obj = SemanticCrawler::Gdacs::FeedItem.new(item)
           @items << item_obj
       end
   end
   @items
end
managingEditor() click to toggle source

Get rss/channel/managingEditor

# File lib/semantic_crawler/gdacs/feed.rb, line 62
def managingEditor
    query_root_node("managingEditor/text()")
end
pubDate() click to toggle source

Get rss/channel/pubDate

# File lib/semantic_crawler/gdacs/feed.rb, line 52
def pubDate
    query_root_node("pubDate/text()")
end
query_root_node(xpath_query, namespaces = {}) click to toggle source

Query the root_node

# File lib/semantic_crawler/gdacs/feed.rb, line 85
def query_root_node(xpath_query, namespaces = {})
    if !@root_node.nil?
        @root_node.xpath(xpath_query, namespaces)
    end
end
title() click to toggle source

Get rss/channel/title

# File lib/semantic_crawler/gdacs/feed.rb, line 37
def title
    query_root_node("title/text()")
end
webMaster() click to toggle source

Get rss/channel/webMaster

# File lib/semantic_crawler/gdacs/feed.rb, line 57
def webMaster
    query_root_node("webMaster/text()")
end
xml_document() click to toggle source

Returns the whole RSS feed as XML

# File lib/semantic_crawler/gdacs/feed.rb, line 92
def xml_document
    @root_node.to_s
end

Private Instance Methods

fetch_feed() click to toggle source

Retrieves the RSS feed

# File lib/semantic_crawler/gdacs/feed.rb, line 98
def fetch_feed
    @doc = Nokogiri::XML(open(@url))
    @root_node = @doc.xpath("/rss/channel")
end