class SemanticCrawler::Gdacs::KmlFile
The GDACS.org KML file contains geo information about the latest crises.
Attributes
url[R]
The gdacs.org KML file URL. (default: www.gdacs.org/xml/gdacs.kml)
Public Class Methods
new(new_url = "http://www.gdacs.org/xml/gdacs.kml")
click to toggle source
Initializes the gdacs.org KML file URL. If not specified the default URL (www..gdacs.org/xml/gdacs.kml) is used. Normally the file URL should not be changed.
# File lib/semantic_crawler/gdacs/kml_file.rb, line 21 def initialize(new_url = "http://www.gdacs.org/xml/gdacs.kml") @url = new_url @root_node = nil begin fetch_file rescue => e $log.error("Not able to get country information, through exception: #{e}") end end
Public Instance Methods
name()
click to toggle source
# File lib/semantic_crawler/gdacs/kml_file.rb, line 31 def name query_root_node("k:name/text()", @@NAMESPACES) end
placemark(crisis_id)
click to toggle source
# File lib/semantic_crawler/gdacs/kml_file.rb, line 35 def placemark(crisis_id) query_root_node("//k:Placemark[@id='#{crisis_id}']", @@NAMESPACES) end
query_root_node(xpath_query, namespace = {})
click to toggle source
Query the root node
# File lib/semantic_crawler/gdacs/kml_file.rb, line 40 def query_root_node(xpath_query, namespace = {}) if !@root_node.nil? @root_node.xpath(xpath_query, namespace) end end
Private Instance Methods
fetch_file()
click to toggle source
Retrieves the RSS feed
# File lib/semantic_crawler/gdacs/kml_file.rb, line 48 def fetch_file @doc = Nokogiri::XML(open(@url)) @root_node = @doc.xpath("/k:kml/k:Document", @@NAMESPACES) end