Class: SemanticCrawler::Gdacs::Feed
- Inherits:
-
Object
- Object
- SemanticCrawler::Gdacs::Feed
- Defined in:
- lib/semantic_crawler/gdacs/feed.rb
Overview
The GDACS.org RSS feed contains the latest crisis information about the following crisis types:
-
Floods
-
Earthquakes
-
Tropical Cyclones
-
Volcanoes
Constant Summary collapse
- @@NAMESPACES =
XML namespaces used for the parsing process
{ "atom" => "http://www.w3.org/2005/Atom" }
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
The gdacs.org RSS feed URL.
Instance Method Summary collapse
-
#atom_link ⇒ Object
Get rss/channel/atom:link.
-
#description ⇒ Object
Get rss/channel/description.
-
#initialize(new_url = "http://www.gdacs.org/xml/rss.xml") ⇒ Feed
constructor
Initializes the gdacs.org feed URL.
-
#items ⇒ Object
Get rss/channel/item*.
-
#link ⇒ Object
Get rss/channel/link.
-
#managingEditor ⇒ Object
Get rss/channel/managingEditor.
-
#pubDate ⇒ Object
Get rss/channel/pubDate.
-
#query_root_node(xpath_query, namespaces = {}) ⇒ Object
Query the root_node.
-
#title ⇒ Object
Get rss/channel/title.
-
#webMaster ⇒ Object
Get rss/channel/webMaster.
-
#xml_document ⇒ Object
Returns the whole RSS feed as XML.
Constructor Details
#initialize(new_url = "http://www.gdacs.org/xml/rss.xml") ⇒ Feed
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.
26 27 28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#url ⇒ Object (readonly)
The gdacs.org RSS feed URL. (default: www.gdacs.org/xml/rss.xml)
21 22 23 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 21 def url @url end |
Instance Method Details
#atom_link ⇒ Object
Get rss/channel/atom:link
67 68 69 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 67 def atom_link query_root_node("atom:link/@href", @@NAMESPACES) end |
#description ⇒ Object
Get rss/channel/description
47 48 49 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 47 def description query_root_node("description/text()") end |
#items ⇒ Object
Get rss/channel/item*
72 73 74 75 76 77 78 79 80 81 82 |
# 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 |
#link ⇒ Object
Get rss/channel/link
42 43 44 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 42 def link query_root_node("link/text()") end |
#managingEditor ⇒ Object
Get rss/channel/managingEditor
62 63 64 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 62 def managingEditor query_root_node("managingEditor/text()") end |
#pubDate ⇒ Object
Get rss/channel/pubDate
52 53 54 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 52 def pubDate query_root_node("pubDate/text()") end |
#query_root_node(xpath_query, namespaces = {}) ⇒ Object
Query the root_node
85 86 87 88 89 |
# 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 ⇒ Object
Get rss/channel/title
37 38 39 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 37 def title query_root_node("title/text()") end |
#webMaster ⇒ Object
Get rss/channel/webMaster
57 58 59 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 57 def webMaster query_root_node("webMaster/text()") end |
#xml_document ⇒ Object
Returns the whole RSS feed as XML
92 93 94 |
# File 'lib/semantic_crawler/gdacs/feed.rb', line 92 def xml_document @root_node.to_s end |