Class: SemanticCrawler::Gdacs::EmergencyFeed

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_crawler/gdacs/emergency_feed.rb

Overview

The emergency GDACS.org RSS feed contains the very, very basic information about emergencies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_url = "http://new.gdacs.org/xml/vo.xml") ⇒ EmergencyFeed

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.



16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#urlObject (readonly)

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



11
12
13
# File 'lib/semantic_crawler/gdacs/emergency_feed.rb', line 11

def url
  @url
end

Instance Method Details

#descriptionObject

Get rss/channel/description



32
33
34
# File 'lib/semantic_crawler/gdacs/emergency_feed.rb', line 32

def description
    query_root_node("description/text()")
end

#itemsObject

Get rss/channel/item*



37
38
39
40
41
42
43
44
45
46
47
# 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 = {}) ⇒ Object

Query the root_node



50
51
52
53
54
# 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

#titleObject

Get rss/channel/title



27
28
29
# File 'lib/semantic_crawler/gdacs/emergency_feed.rb', line 27

def title
    query_root_node("title/text()")
end

#xml_documentObject

Returns the whole RSS feed as XML



57
58
59
# File 'lib/semantic_crawler/gdacs/emergency_feed.rb', line 57

def xml_document
    @root_node.to_s
end