Class: RCAP::CAP_1_1::Info

Inherits:
Base::Info show all
Defined in:
lib/rcap/cap_1_1/info.rb

Overview

In Info object is valid if

  • it has an event

  • it has an urgency with a valid value

  • it has a severity with a valid value

  • it has a certainty with a valid value

  • all categories are valid and categories has at minimum 1 entry

  • all Resource objects in the resources collection are valid

  • all Area objects in the areas collection are valid

Constant Summary

RESPONSE_TYPE_SHELTER =
"Shelter"
RESPONSE_TYPE_EVACUATE =
"Evacuate"
RESPONSE_TYPE_PREPARE =
"Prepare"
RESPONSE_TYPE_EXECUTE =
"Execute"
RESPONSE_TYPE_MONITOR =
"Monitor"
RESPONSE_TYPE_ASSESS =
"Assess"
RESPONSE_TYPE_NONE =
"None"
VALID_RESPONSE_TYPES =

Valid values for response_type

[ RESPONSE_TYPE_SHELTER, RESPONSE_TYPE_EVACUATE,
RESPONSE_TYPE_PREPARE, RESPONSE_TYPE_EXECUTE, RESPONSE_TYPE_MONITOR,
RESPONSE_TYPE_ASSESS, RESPONSE_TYPE_NONE ]
CERTAINTY_OBSERVED =
"Observed"
VALID_CERTAINTIES =

Valid valies for certainty

[ CERTAINTY_OBSERVED, CERTAINTY_LIKELY,
CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN ]
RESPONSE_TYPE_ELEMENT_NAME =
'responseType'
RESPONSE_TYPE_XPATH =
"cap:#{ RESPONSE_TYPE_ELEMENT_NAME }"
RESPONSE_TYPES_YAML =
'Response Types'
RESPONSE_TYPES_KEY =
'response_types'

Constants inherited from Base::Info

Base::Info::AREAS_KEY, Base::Info::AREAS_YAML, Base::Info::AUDIENCE_ELEMENT_NAME, Base::Info::AUDIENCE_KEY, Base::Info::AUDIENCE_XPATH, Base::Info::AUDIENCE_YAML, Base::Info::CATEGORIES_KEY, Base::Info::CATEGORIES_YAML, Base::Info::CATEGORY_CBRNE, Base::Info::CATEGORY_ELEMENT_NAME, Base::Info::CATEGORY_ENV, Base::Info::CATEGORY_FIRE, Base::Info::CATEGORY_GEO, Base::Info::CATEGORY_HEALTH, Base::Info::CATEGORY_INFRA, Base::Info::CATEGORY_MET, Base::Info::CATEGORY_OTHER, Base::Info::CATEGORY_RESCUE, Base::Info::CATEGORY_SAFETY, Base::Info::CATEGORY_SECURITY, Base::Info::CATEGORY_TRANSPORT, Base::Info::CATEGORY_XPATH, Base::Info::CERTAINTY_ELEMENT_NAME, Base::Info::CERTAINTY_KEY, Base::Info::CERTAINTY_LIKELY, Base::Info::CERTAINTY_POSSIBLE, Base::Info::CERTAINTY_UNKNOWN, Base::Info::CERTAINTY_UNLIKELY, Base::Info::CERTAINTY_VERY_LIKELY, Base::Info::CERTAINTY_XPATH, Base::Info::CERTAINTY_YAML, Base::Info::CONTACT_ELEMENT_NAME, Base::Info::CONTACT_KEY, Base::Info::CONTACT_XPATH, Base::Info::CONTACT_YAML, Base::Info::DEFAULT_LANGUAGE, Base::Info::DESCRIPTION_ELEMENT_NAME, Base::Info::DESCRIPTION_KEY, Base::Info::DESCRIPTION_XPATH, Base::Info::DESCRIPTION_YAML, Base::Info::EFFECTIVE_ELEMENT_NAME, Base::Info::EFFECTIVE_KEY, Base::Info::EFFECTIVE_XPATH, Base::Info::EFFECTIVE_YAML, Base::Info::EVENT_CODES_KEY, Base::Info::EVENT_CODES_YAML, Base::Info::EVENT_CODE_ELEMENT_NAME, Base::Info::EVENT_CODE_XPATH, Base::Info::EVENT_ELEMENT_NAME, Base::Info::EVENT_KEY, Base::Info::EVENT_XPATH, Base::Info::EVENT_YAML, Base::Info::EXPIRES_ELEMENT_NAME, Base::Info::EXPIRES_KEY, Base::Info::EXPIRES_XPATH, Base::Info::EXPIRES_YAML, Base::Info::HEADLINE_ELEMENT_NAME, Base::Info::HEADLINE_KEY, Base::Info::HEADLINE_XPATH, Base::Info::HEADLINE_YAML, Base::Info::INSTRUCTION_ELEMENT_NAME, Base::Info::INSTRUCTION_KEY, Base::Info::INSTRUCTION_XPATH, Base::Info::INSTRUCTION_YAML, Base::Info::LANGUAGE_ELEMENT_NAME, Base::Info::LANGUAGE_KEY, Base::Info::LANGUAGE_XPATH, Base::Info::LANGUAGE_YAML, Base::Info::ONSET_ELEMENT_NAME, Base::Info::ONSET_KEY, Base::Info::ONSET_XPATH, Base::Info::ONSET_YAML, Base::Info::PARAMETERS_KEY, Base::Info::PARAMETERS_YAML, Base::Info::RESOURCES_KEY, Base::Info::RESOURCES_YAML, Base::Info::SENDER_NAME_ELEMENT_NAME, Base::Info::SENDER_NAME_KEY, Base::Info::SENDER_NAME_XPATH, Base::Info::SENDER_NAME_YAML, Base::Info::SEVERITY_ELEMENT_NAME, Base::Info::SEVERITY_EXTREME, Base::Info::SEVERITY_KEY, Base::Info::SEVERITY_MINOR, Base::Info::SEVERITY_MODERATE, Base::Info::SEVERITY_SEVERE, Base::Info::SEVERITY_UNKNOWN, Base::Info::SEVERITY_XPATH, Base::Info::SEVERITY_YAML, Base::Info::URGENCY_ELEMENT_NAME, Base::Info::URGENCY_EXPECTED, Base::Info::URGENCY_FUTURE, Base::Info::URGENCY_IMMEDIATE, Base::Info::URGENCY_KEY, Base::Info::URGENCY_PAST, Base::Info::URGENCY_UNKNOWN, Base::Info::URGENCY_XPATH, Base::Info::URGENCY_YAML, Base::Info::VALID_CATEGORIES, Base::Info::VALID_SEVERITIES, Base::Info::VALID_URGENCIES, Base::Info::WEB_ELEMENT_NAME, Base::Info::WEB_KEY, Base::Info::WEB_XPATH, Base::Info::WEB_YAML, Base::Info::XML_ELEMENT_NAME, Base::Info::XPATH

Instance Attribute Summary (collapse)

Attributes inherited from Base::Info

#audience, #categories, #certainty, #contact, #description, #effective, #event, #expires, #headline, #instruction, #language, #onset, #sender_name, #severity, #urgency, #web

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base::Info

#add_area, #add_event_code, #add_parameter, #add_resource

Constructor Details

- (Info) initialize

A new instance of Info

Parameters:

  • attributes (Hash)


70
71
72
73
# File 'lib/rcap/cap_1_1/info.rb', line 70

def initialize
  @response_types =  []
  super
end

Instance Attribute Details

- (Array<Area>) areas (readonly)

Collection of Area objects

Returns:



46
47
48
# File 'lib/rcap/cap_1_1/info.rb', line 46

def areas
  @areas
end

- (Array<EventCode>) event_codes (readonly)

Collection of EventCode objects

Returns:



40
41
42
# File 'lib/rcap/cap_1_1/info.rb', line 40

def event_codes
  @event_codes
end

- (Array<Parameter>) parameters (readonly)

Collection of Parameter objects

Returns:



42
43
44
# File 'lib/rcap/cap_1_1/info.rb', line 42

def parameters
  @parameters
end

- (Array<Resource> Collection of {Resource} objects) resources (readonly)

Array<Resource> Collection of Resource objects

Returns:



44
45
46
# File 'lib/rcap/cap_1_1/info.rb', line 44

def resources
  @resources
end

- (Array<String>) response_types (readonly)

Collection of textual response types; elements must be from VALID_RESPONSE_TYPES

Returns:



38
39
40
# File 'lib/rcap/cap_1_1/info.rb', line 38

def response_types
  @response_types
end

Class Method Details

+ (Info) from_h(info_hash)

Parameters:

  • info_hash (Hash)

Returns:



259
260
261
262
263
264
265
# File 'lib/rcap/cap_1_1/info.rb', line 259

def self.from_h( info_hash )
  super.tap do |info|
    Array( info_hash[ RESPONSE_TYPES_KEY ]).each do |response_type|
      info.response_types << RCAP.strip_if_given( response_type )
    end
  end
end

+ (Info) from_xml_element(info_xml_element)

Parameters:

  • info_xml_element (REXML::Element)

Returns:



144
145
146
147
148
149
150
# File 'lib/rcap/cap_1_1/info.rb', line 144

def self.from_xml_element( info_xml_element )
  super.tap do |info|
    RCAP.xpath_match( info_xml_element, RESPONSE_TYPE_XPATH, info.xmlns ).each do |element|
      info.response_types << RCAP.strip_if_given( element.text )
    end
  end
end

+ (Info) from_yaml_data(info_yaml_data)

Parameters:

  • info_yaml_data (Hash)

Returns:



222
223
224
225
226
227
228
# File 'lib/rcap/cap_1_1/info.rb', line 222

def self.from_yaml_data( info_yaml_data )
  super.tap do |info|
    Array( info_yaml_data [ RESPONSE_TYPES_YAML ] ).each do |response_type|
      info.response_types << RCAP.strip_if_given( response_type )
    end
  end
end

Instance Method Details

- (Object) area_class



87
88
89
# File 'lib/rcap/cap_1_1/info.rb', line 87

def area_class
  Area
end

- (Object) event_code_class



75
76
77
# File 'lib/rcap/cap_1_1/info.rb', line 75

def event_code_class
  EventCode
end

- (String) inspect

Returns:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rcap/cap_1_1/info.rb', line 153

def inspect
  info_inspect = "Language:       #{ @language }\n"+
  "Categories:     #{ @categories.to_s_for_cap }\n"+
  "Event:          #{ @event }\n"+
  "Response Types: #{ @response_types.to_s_for_cap }\n"+
  "Urgency:        #{ @urgency }\n"+
  "Severity:       #{ @severity }\n"+
  "Certainty:      #{ @certainty }\n"+
  "Audience:       #{ @audience }\n"+
  "Event Codes:    #{ @event_codes.inspect }\n"+
  "Effective:      #{ @effective }\n"+
  "Onset:          #{ @onset }\n"+
  "Expires:        #{ @expires }\n"+
  "Sender Name:    #{ @sender_name }\n"+
  "Headline:       #{ @headline }\n"+
  "Description:\n"+
    @description.to_s.lines.map{ |line| "  " + line }.join( "\n")+"\n"+
    "Instruction:    #{ @instruction }\n"+
  "Web:            #{ @web }\n"+
  "Contact:        #{ @contact }\n"+
  "Parameters:\n"+
    @parameters.map{ |parameter| "  " + parameter.inspect }.join( "\n" )+"\n"+
    "Resources:\n"+
    @resources.map{ |resource| "  " + resource.inspect }.join( "\n" )+"\n"+
    "Area:\n"+
    @areas.map{ |area| "  #{ area }" }.join( "\n" )+"\n"
  RCAP.format_lines_for_inspect( 'INFO', info_inspect )
end

- (Object) parameter_class



79
80
81
# File 'lib/rcap/cap_1_1/info.rb', line 79

def parameter_class
  Parameter
end

- (Object) resource_class



83
84
85
# File 'lib/rcap/cap_1_1/info.rb', line 83

def resource_class
  Resource
end

- (Hash) to_h

Returns:

  • (Hash)


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/rcap/cap_1_1/info.rb', line 233

def to_h
  RCAP.attribute_values_to_hash( [ LANGUAGE_KEY,       @language ],
                                 [ CATEGORIES_KEY,     @categories ],
                                 [ EVENT_KEY,          @event ],
                                 [ RESPONSE_TYPES_KEY, @response_types ],
                                 [ URGENCY_KEY,        @urgency ],
                                 [ SEVERITY_KEY,       @severity ],
                                 [ CERTAINTY_KEY,      @certainty ],
                                 [ AUDIENCE_KEY,       @audience ],
                                 [ EFFECTIVE_KEY,      RCAP.to_s_for_cap( @effective )],
                                 [ ONSET_KEY,          RCAP.to_s_for_cap( @onset )],
                                 [ EXPIRES_KEY,        RCAP.to_s_for_cap( @expires )],
                                 [ SENDER_NAME_KEY,    @sender_name ],
                                 [ HEADLINE_KEY,       @headline ],
                                 [ DESCRIPTION_KEY,    @description ],
                                 [ INSTRUCTION_KEY,    @instruction ],
                                 [ WEB_KEY,            @web ],
                                 [ CONTACT_KEY,        @contact ],
                                 [ RESOURCES_KEY,      @resources.map{ |resource| resource.to_h } ],
                                 [ EVENT_CODES_KEY,    @event_codes.map{ |event_code| event_code.to_h } ],
                                 [ PARAMETERS_KEY,     @parameters.map{ |parameter| parameter.to_h } ],
                                 [ AREAS_KEY,          @areas.map{ |area| area.to_h }])
end

- (String) to_s

Returns a string representation of the event of the form

event(urgency/severity/certainty)

Returns:



186
187
188
# File 'lib/rcap/cap_1_1/info.rb', line 186

def to_s
  "#{ @event }(#{ @urgency }/#{ @severity }/#{ @certainty })"
end

- (String) to_xml

Returns:



138
139
140
# File 'lib/rcap/cap_1_1/info.rb', line 138

def to_xml
  self.to_xml_element.to_s
end

- (REXML::Element) to_xml_element

Returns:

  • (REXML::Element)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rcap/cap_1_1/info.rb', line 99

def to_xml_element
  xml_element = REXML::Element.new( XML_ELEMENT_NAME )
  xml_element.add_element( LANGUAGE_ELEMENT_NAME ).add_text( @language ) if @language
  @categories.each do |category|
    xml_element.add_element( CATEGORY_ELEMENT_NAME ).add_text( category )
  end
  xml_element.add_element( EVENT_ELEMENT_NAME ).add_text( @event )
  @response_types.each do |response_type|
    xml_element.add_element( RESPONSE_TYPE_ELEMENT_NAME ).add_text( response_type )
  end
  xml_element.add_element( URGENCY_ELEMENT_NAME ).add_text( @urgency )
  xml_element.add_element( SEVERITY_ELEMENT_NAME ).add_text( @severity )
  xml_element.add_element( CERTAINTY_ELEMENT_NAME ).add_text( @certainty )
  xml_element.add_element( AUDIENCE_ELEMENT_NAME ).add_text( @audience ) if @audience
  @event_codes.each do |event_code|
    xml_element.add_element( event_code.to_xml_element )
  end
  xml_element.add_element( EFFECTIVE_ELEMENT_NAME ).add_text( @effective.to_s_for_cap ) if @effective
  xml_element.add_element( ONSET_ELEMENT_NAME ).add_text( @onset.to_s_for_cap )         if @onset
  xml_element.add_element( EXPIRES_ELEMENT_NAME ).add_text( @expires.to_s_for_cap )     if @expires
  xml_element.add_element( SENDER_NAME_ELEMENT_NAME ).add_text( @sender_name )          if @sender_name
  xml_element.add_element( HEADLINE_ELEMENT_NAME ).add_text( @headline )                if @headline
  xml_element.add_element( DESCRIPTION_ELEMENT_NAME ).add_text( @description )          if @description
  xml_element.add_element( INSTRUCTION_ELEMENT_NAME ).add_text( @instruction )          if @instruction
  xml_element.add_element( WEB_ELEMENT_NAME ).add_text( @web )                          if @web
  xml_element.add_element( CONTACT_ELEMENT_NAME ).add_text( @contact )                  if @contact
  @parameters.each do |parameter|
    xml_element.add_element( parameter.to_xml_element )
  end
  @resources.each do |resource|
    xml_element.add_element( resource.to_xml_element )
  end
  @areas.each do |area|
    xml_element.add_element( area.to_xml_element )
  end
  xml_element
end

- (String) to_yaml(options = {})

Returns:



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/rcap/cap_1_1/info.rb', line 194

def to_yaml( options = {} )
  parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}

  RCAP.attribute_values_to_hash( [ LANGUAGE_YAML,       @language ],
                                 [ CATEGORIES_YAML,     @categories ],
                                 [ EVENT_YAML,          @event ],
                                 [ RESPONSE_TYPES_YAML, @response_types ],
                                 [ URGENCY_YAML,        @urgency ],
                                 [ SEVERITY_YAML,       @severity ],
                                 [ CERTAINTY_YAML,      @certainty ],
                                 [ AUDIENCE_YAML,       @audience ],
                                 [ EFFECTIVE_YAML,      @effective ],
                                 [ ONSET_YAML,          @onset ],
                                 [ EXPIRES_YAML,        @expires ],
                                 [ SENDER_NAME_YAML,    @sender_name ],
                                 [ HEADLINE_YAML,       @headline ],
                                 [ DESCRIPTION_YAML,    @description ],
                                 [ INSTRUCTION_YAML,    @instruction ],
                                 [ WEB_YAML,            @web ],
                                 [ CONTACT_YAML,        @contact ],
                                 [ EVENT_CODES_YAML,    @event_codes.inject({}, &parameter_to_hash )],
                                 [ PARAMETERS_YAML,     @parameters.inject({}, &parameter_to_hash )],
                                 [ RESOURCES_YAML,      @resources ],
                                 [ AREAS_YAML,          @areas ]).to_yaml( options )
end

- (Object) xmlns



91
92
93
# File 'lib/rcap/cap_1_1/info.rb', line 91

def xmlns
  Alert::XMLNS
end