class SemanticCrawler::Gdacs::EmergencyFeed
The emergency GDACS.org RSS feed contains the very, very basic information about emergencies.
Attributes
url[R]
The gdacs.org RSS feed URL. (default: new.gdacs.org/xml/rss.xml)
Public Class Methods
new(new_url = "http://new.gdacs.org/xml/vo.xml")
click to toggle source
Initializes the gdacs.org feed URL. If not specified the default URL (new.gdacs.org/xml/rss.xml) is used. Normally the feed URL should not be changed.
# File lib/semantic_crawler/gdacs/emergency_feed.rb, line 16 def initialize(new_url = "http://new.gdacs.org/xml/vo.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/emergency_feed.rb, line 32 def description query_root_node("description/text()") end
items()
click to toggle source
Get rss/channel/item*
# File lib/semantic_crawler/gdacs/emergency_feed.rb, line 37 def items nodeset = query_root_node("item") @items = [] if !nodeset.nil? nodeset.each do |item| item_obj = SemanticCrawler::Gdacs::EmergencyFeedItem.new(item) @items << item_obj end end @items end
query_root_node(xpath_query, namespaces = {})
click to toggle source
Query the root_node
# File lib/semantic_crawler/gdacs/emergency_feed.rb, line 50 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/emergency_feed.rb, line 27 def title query_root_node("title/text()") end
xml_document()
click to toggle source
Returns the whole RSS feed as XML
# File lib/semantic_crawler/gdacs/emergency_feed.rb, line 57 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/emergency_feed.rb, line 63 def fetch_feed @doc = Nokogiri::XML(open(@url)) @root_node = @doc.xpath("/rss/channel") end