Class: SemanticCrawler::Gdacs::KmlFile

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

Overview

The GDACS.org KML file contains geo information about the latest crises.

Constant Summary collapse

@@NAMESPACES =

XML namespaces used for the parsing process

{
	"k" => "http://www.opengis.net/kml/2.2"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_url = "http://www.gdacs.org/xml/gdacs.kml") ⇒ KmlFile

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.



21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#urlObject (readonly)

The gdacs.org KML file URL. (default: www.gdacs.org/xml/gdacs.kml)



16
17
18
# File 'lib/semantic_crawler/gdacs/kml_file.rb', line 16

def url
  @url
end

Instance Method Details

#nameObject



31
32
33
# File 'lib/semantic_crawler/gdacs/kml_file.rb', line 31

def name
	query_root_node("k:name/text()", @@NAMESPACES)
end

#placemark(crisis_id) ⇒ Object



35
36
37
# 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 = {}) ⇒ Object

Query the root node



40
41
42
43
44
# 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