Class: SemanticCrawler::Gdacs::FeedItem

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

Overview

One crisis entity with related resources. Could be one of the following crisis types:

  • Floods

  • Earthquakes

  • Tropical Cyclones

  • Volcanoes

Constant Summary collapse

@@NAMESPACES =

XML namespaces used for the parsing process

{
    "gdacs" => "http://www.gdacs.org",
    "asgard" => "http://asgard.jrc.it",
    "geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#",
    "dc" => "http://purl.org/dc/elements/1.1/"
}

Instance Method Summary collapse

Constructor Details

#initialize(new_root_node) ⇒ FeedItem

Returns a new instance of FeedItem.



21
22
23
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 21

def initialize(new_root_node)
    @root_node = new_root_node
end

Instance Method Details

#alertlevelObject

Returns the alert level, could be GREEN, ORANGE or RED



103
104
105
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 103

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

#countryObject

Returns the country name(s)



168
169
170
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 168

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

#descriptionObject

Returns the crisis description



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

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

#enclosure_lengthObject

Returns the enclosure length, e.g. 1



46
47
48
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 46

def enclosure_length
    query_root_node("enclosure/@length")
end

#enclosure_typeObject

Returns the enclosure type, e.g. image/png



41
42
43
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 41

def enclosure_type
    query_root_node("enclosure/@type")
end

#enclosure_urlObject

Returns the enclosure URL



36
37
38
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 36

def enclosure_url
    query_root_node("enclosure/@url")
end

#episodeidObject

Returns the episode id



118
119
120
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 118

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

#eventidObject

Returns the event id



113
114
115
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 113

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

#eventnameObject

Returns the event name if available



108
109
110
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 108

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

#eventtypeObject

Returns the event type abbreviation, e.g. VO (for volcanic eruption, EQ (for earthquake), FL (for flood), TC (for tropical cyclone)



98
99
100
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 98

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

#fromdateObject

Returns the crisis start date



61
62
63
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 61

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

#glideObject

Returns …



173
174
175
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 173

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

#guidObject

Returns an unique crisis identifier (could be non permanent)



76
77
78
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 76

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

#iso3Object

Returns the country iso3 code if available



163
164
165
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 163

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

#latitudeObject

Returns the latitude GPS coordinate where the crisis has occurred



81
82
83
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 81

def latitude
    query_root_node("geo:Point/geo:lat/text()", @@NAMESPACES)
end

Returns the crisis gdacs link



51
52
53
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 51

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

#longitudeObject

Returns the longitude GPS coordinate where the crisis has occurred



86
87
88
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 86

def longitude
    query_root_node("geo:Point/geo:long/text()", @@NAMESPACES)
end

#populationObject

Returns the population as human readable string



138
139
140
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 138

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

#population_unitObject

Returns the population unit (without further text)



148
149
150
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 148

def population_unit
    query_root_node("gdacs:population/@unit", @@NAMESPACES)
end

#population_valueObject

Returns the population value (without further text)



143
144
145
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 143

def population_value
    query_root_node("gdacs:population/@value", @@NAMESPACES)
end

#pubDateObject

Returns the publication date



56
57
58
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 56

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

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

Query the root_node



191
192
193
194
195
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 191

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

#resourcesObject

Returns an array of SemanticCrawler::Gdacs::Resource objects



178
179
180
181
182
183
184
185
186
187
188
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 178

def resources
   nodeset = query_root_node("gdacs:resources/gdacs:resource", @@NAMESPACES)
   @items = []
   if !nodeset.nil?
       nodeset.each do |item|
           item_obj = SemanticCrawler::Gdacs::Resource.new(item)
           @items << item_obj
       end
   end
   @items
end

#severityObject

Returns the severity as human readable string



123
124
125
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 123

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

#severity_unitObject

Returns the severity unit (without further text)



133
134
135
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 133

def severity_unit
    query_root_node("gdacs:severity/@unit", @@NAMESPACES)
end

#severity_valueObject

Returns the severity value (without further text)



128
129
130
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 128

def severity_value
    query_root_node("gdacs:severity/@value", @@NAMESPACES)
end

#subjectObject

Returns the crisis subject abbreviation



71
72
73
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 71

def subject
    query_root_node("dc:subject/text()", @@NAMESPACES)
end

#titleObject

Returns the crisis title



26
27
28
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 26

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

#todateObject

Returns the crisis end date



66
67
68
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 66

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

#versionObject

Returns the version



91
92
93
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 91

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

#vulnerabilityObject

Returns the vulnerability as human readable string



153
154
155
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 153

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

#vulnerability_valueObject

Returns the vulnerability as number



158
159
160
# File 'lib/semantic_crawler/gdacs/feed_item.rb', line 158

def vulnerability_value
    query_root_node("gdacs:vulnerability/@value", @@NAMESPACES)
end