Class: RCAP::CAP_1_2::Info

Inherits:
Base::Info show all
Defined in:
lib/rcap/cap_1_2/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

#areas, #audience, #categories, #certainty, #contact, #description, #effective, #event, #event_codes, #expires, #headline, #instruction, #language, #onset, #parameters, #resources, #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 {|info| ... }

Initialises a new Info object which will be yielded to an attached block if given

Yield Parameters:

  • info (Info)

    An instance of an Info object



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

def initialize
  @response_types = []
  super
end

Instance Attribute Details

- (Array<String>) response_types (readonly)

Collection of textual response types; elements must be from VALID_RESPONSE_TYPES

Returns:



37
38
39
# File 'lib/rcap/cap_1_2/info.rb', line 37

def response_types
  @response_types
end

Class Method Details

+ (Info) from_h(info_hash)

Parameters:

  • info_hash (Hash)

Returns:



233
234
235
236
237
238
239
# File 'lib/rcap/cap_1_2/info.rb', line 233

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:



157
158
159
160
161
162
163
# File 'lib/rcap/cap_1_2/info.rb', line 157

def self.from_xml_element( info_xml_element )
  super.tap do |info|
    RCAP.xpath_match( info_xml_element, RESPONSE_TYPE_XPATH, Alert::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:



196
197
198
199
200
201
202
# File 'lib/rcap/cap_1_2/info.rb', line 196

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

- (Class) area_class

Returns:

  • (Class)


59
60
61
# File 'lib/rcap/cap_1_2/info.rb', line 59

def area_class
  Area
end

- (Class) event_code_class

Returns:

  • (Class)


49
50
51
# File 'lib/rcap/cap_1_2/info.rb', line 49

def event_code_class
  EventCode
end

- (String) inspect

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/rcap/cap_1_2/info.rb', line 118

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

- (Class) parameter_class

Returns:

  • (Class)


54
55
56
# File 'lib/rcap/cap_1_2/info.rb', line 54

def parameter_class
  Parameter
end

- (Class) resource_class

Returns:

  • (Class)


64
65
66
# File 'lib/rcap/cap_1_2/info.rb', line 64

def resource_class
  Resource
end

- (Hash) to_h

Returns:

  • (Hash)


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/rcap/cap_1_2/info.rb', line 207

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:



151
152
153
# File 'lib/rcap/cap_1_2/info.rb', line 151

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

- (String) to_xml

Returns:



113
114
115
# File 'lib/rcap/cap_1_2/info.rb', line 113

def to_xml
  self.to_xml_element.to_s
end

- (REXML::Element) to_xml_element

Returns:

  • (REXML::Element)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rcap/cap_1_2/info.rb', line 74

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:



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/rcap/cap_1_2/info.rb', line 168

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,      RCAP.to_s_for_cap( @effective )],
                                 [ ONSET_YAML,          RCAP.to_s_for_cap( @onset )],
                                 [ EXPIRES_YAML,        RCAP.to_s_for_cap( @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

- (String) xmlns

Returns:



69
70
71
# File 'lib/rcap/cap_1_2/info.rb', line 69

def xmlns
  Alert::XMLNS
end