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 collapse

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

Methods included from Validation

#errors, included, #valid?, #validate

Constructor Details

#initialize {|info| ... } ⇒ 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


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

def initialize
  @response_types = []
  super
end

Instance Attribute Details

#response_typesArray<String> (readonly)


34
35
36
# File 'lib/rcap/cap_1_2/info.rb', line 34

def response_types
  @response_types
end

Class Method Details

.from_h(info_hash) ⇒ Info


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

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

.from_xml_element(info_xml_element) ⇒ Info


150
151
152
153
154
155
156
# File 'lib/rcap/cap_1_2/info.rb', line 150

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

.from_yaml_data(info_yaml_data) ⇒ Info


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

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

#area_classClass


56
57
58
# File 'lib/rcap/cap_1_2/info.rb', line 56

def area_class
  Area
end

#event_code_classClass


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

def event_code_class
  EventCode
end

#inspectString


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/rcap/cap_1_2/info.rb', line 115

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

#parameter_classClass


51
52
53
# File 'lib/rcap/cap_1_2/info.rb', line 51

def parameter_class
  Parameter
end

#resource_classClass


61
62
63
# File 'lib/rcap/cap_1_2/info.rb', line 61

def resource_class
  Resource
end

#to_hHash


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

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

#to_sString

Returns a string representation of the event of the form

event(urgency/severity/certainty)

144
145
146
# File 'lib/rcap/cap_1_2/info.rb', line 144

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

#to_xmlString


110
111
112
# File 'lib/rcap/cap_1_2/info.rb', line 110

def to_xml
  to_xml_element.to_s
end

#to_xml_elementREXML::Element


71
72
73
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
# File 'lib/rcap/cap_1_2/info.rb', line 71

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

#to_yaml(options = {}) ⇒ String


188
189
190
# File 'lib/rcap/cap_1_2/info.rb', line 188

def to_yaml(options = {})
  to_yaml_data.to_yaml(options)
end

#to_yaml_dataHash


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/rcap/cap_1_2/info.rb', line 161

def to_yaml_data
  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.map(&:to_yaml_data)],
                                [AREAS_YAML,          @areas.map(&:to_yaml_data)])
end

#xmlnsString


66
67
68
# File 'lib/rcap/cap_1_2/info.rb', line 66

def xmlns
  Alert::XMLNS
end