Class: SemanticCrawler::Gdacs::Resource

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

Overview

A resource is always related to one FeedItem and could have different types. For example xml, map and a lot more.

Constant Summary collapse

@@NAMESPACES =

XML namespaces used for the parsing process

{
    "gdacs" => "http://www.gdacs.org"
}

Instance Method Summary collapse

Constructor Details

#initialize(new_root_node) ⇒ Resource

Initializes a resource that is related to a crisis element.



14
15
16
# File 'lib/semantic_crawler/gdacs/resource.rb', line 14

def initialize(new_root_node)
    @root_node = new_root_node
end

Instance Method Details

#accesslevelObject

OPTIONAL

Returns the gdacs:accesslevel



49
50
51
# File 'lib/semantic_crawler/gdacs/resource.rb', line 49

def accesslevel
    query_root_node("gdacs:accesslevel/text()", @@NAMESPACES)
end

#acknowledgementsObject

OPTIONAL

Returns the gdacs:acknowledgements



44
45
46
# File 'lib/semantic_crawler/gdacs/resource.rb', line 44

def acknowledgements
    query_root_node("gdacs:acknowledgements/text()", @@NAMESPACES)
end

#descriptionObject

OPTIONAL

Returns the gdacs:description



39
40
41
# File 'lib/semantic_crawler/gdacs/resource.rb', line 39

def description
    query_root_node("gdacs:description/text()", @@NAMESPACES)
end

#query_root_node(xpath_query, namespaces = {}) ⇒ Object

Query the root_node



59
60
61
62
63
# File 'lib/semantic_crawler/gdacs/resource.rb', line 59

def query_root_node(xpath_query, namespaces = {})
    if !@root_node.nil?
        @root_node.xpath(xpath_query, namespaces)
    end
end

#sourceObject

Returns the source organization abbreviation (‘source’ attribute in gdacs:resource)



34
35
36
# File 'lib/semantic_crawler/gdacs/resource.rb', line 34

def source
    query_root_node("@source")
end

#titleObject

Returns the gdacs:title



24
25
26
# File 'lib/semantic_crawler/gdacs/resource.rb', line 24

def title
    query_root_node("gdacs:title/text()", @@NAMESPACES)
end

#typeObject

Returns the type (attribute in gdacs:resource)



29
30
31
# File 'lib/semantic_crawler/gdacs/resource.rb', line 29

def type
    query_root_node("@type")
end

#urlObject

Returns the resource URL



19
20
21
# File 'lib/semantic_crawler/gdacs/resource.rb', line 19

def url
    query_root_node("@url", @@NAMESPACES).to_s.gsub("[gdacs]", "http://www.gdacs.org")
end

#xsltObject

OPTIONAL

Returns the gdacs:xslt. Only for XML resources!



54
55
56
# File 'lib/semantic_crawler/gdacs/resource.rb', line 54

def xslt
    query_root_node("gdacs:xslt/text()", @@NAMESPACES)
end