Class: Info

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Validation
Defined in:
lib/generators/rcap/models/templates/models/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

CATEGORY_GEO =

:nodoc:

"Geo"
CATEGORY_MET =

:nodoc:

"Met"
CATEGORY_SAFETY =

:nodoc:

"Safety"
CATEGORY_SECURITY =

:nodoc:

"Security"
CATEGORY_RESCUE =

:nodoc:

"Rescue"
CATEGORY_FIRE =

:nodoc:

"Fire"
CATEGORY_HEALTH =

:nodoc:

"Health"
CATEGORY_ENV =

:nodoc:

"Env"
CATEGORY_TRANSPORT =

:nodoc:

"Transport"
CATEGORY_INFRA =

:nodoc:

"Infra"
CATEGORY_CBRNE =

:nodoc:

"CBRNE"
CATEGORY_OTHER =

:nodoc:

"Other"
VALID_CATEGORIES =

Valid values for categories

[ CATEGORY_GEO, CATEGORY_MET, CATEGORY_SAFETY,
CATEGORY_SECURITY, CATEGORY_RESCUE,   CATEGORY_FIRE, CATEGORY_HEALTH,
CATEGORY_ENV, CATEGORY_TRANSPORT, CATEGORY_INFRA, CATEGORY_CBRNE,
CATEGORY_OTHER ]
RESPONSE_TYPE_SHELTER =

:nodoc:

"Shelter"
RESPONSE_TYPE_EVACUATE =

:nodoc:

"Evacuate"
RESPONSE_TYPE_PREPARE =

:nodoc:

"Prepare"
RESPONSE_TYPE_EXECUTE =

:nodoc:

"Execute"
RESPONSE_TYPE_MONITOR =

:nodoc:

"Monitor"
RESPONSE_TYPE_ASSESS =

:nodoc:

"Assess"
RESPONSE_TYPE_NONE =

:nodoc:

"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 ]
URGENCY_IMMEDIATE =

:nodoc:

"Immediate"
URGENCY_EXPECTED =

:nodoc:

"Expected"
URGENCY_FUTURE =

:nodoc:

"Future"
URGENCY_PAST =

:nodoc:

"Past"
URGENCY_UNKNOWN =

:nodoc:

"Unknown"
VALID_URGENCIES =

Valid values for urgency

[ URGENCY_IMMEDIATE, URGENCY_EXPECTED, URGENCY_FUTURE,
URGENCY_PAST, URGENCY_UNKNOWN ]
SEVERITY_EXTREME =

:nodoc:

"Extreme"
SEVERITY_SEVERE =

:nodoc:

"Severe"
SEVERITY_MODERATE =

:nodoc:

"Moderate"
SEVERITY_MINOR =

:nodoc:

"Minor"
SEVERITY_UNKNOWN =

:nodoc:

"Unknown"
VALID_SEVERITIES =

Valid values for severity

[ SEVERITY_EXTREME, SEVERITY_SEVERE, SEVERITY_MODERATE,
SEVERITY_MINOR, SEVERITY_UNKNOWN ]
CERTAINTY_OBSERVED =

:nodoc:

"Observed"
CERTAINTY_LIKELY =

:nodoc:

"Likely"
CERTAINTY_POSSIBLE =

:nodoc:

"Possible"
CERTAINTY_UNLIKELY =

:nodoc:

"Unlikely"
CERTAINTY_UNKNOWN =

:nodoc:

"Unknown"
VALID_CERTAINTIES =

Valid valies for certainty

[ CERTAINTY_OBSERVED, CERTAINTY_LIKELY,
CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN ]
XML_ELEMENT_NAME =

:nodoc:

'info'
LANGUAGE_ELEMENT_NAME =

:nodoc:

'language'
CATEGORY_ELEMENT_NAME =

:nodoc:

'category'
EVENT_ELEMENT_NAME =

:nodoc:

'event'
RESPONSE_TYPE_ELEMENT_NAME =

:nodoc:

'responseType'
URGENCY_ELEMENT_NAME =

:nodoc:

'urgency'
SEVERITY_ELEMENT_NAME =

:nodoc:

'severity'
CERTAINTY_ELEMENT_NAME =

:nodoc:

'certainty'
AUDIENCE_ELEMENT_NAME =

:nodoc:

'audience'
EVENT_CODE_ELEMENT_NAME =

:nodoc:

'eventCode'
EFFECTIVE_ELEMENT_NAME =

:nodoc:

'effective'
ONSET_ELEMENT_NAME =

:nodoc:

'onset'
EXPIRES_ELEMENT_NAME =

:nodoc:

'expires'
SENDER_NAME_ELEMENT_NAME =

:nodoc:

'sernderName'
HEADLINE_ELEMENT_NAME =

:nodoc:

'headline'
DESCRIPTION_ELEMENT_NAME =

:nodoc:

'description'
INSTRUCTION_ELEMENT_NAME =

:nodoc:

'instruction'
WEB_ELEMENT_NAME =

:nodoc:

'web'
CONTACT_ELEMENT_NAME =

:nodoc:

'contact'
XPATH =

:nodoc:

"cap:#{ XML_ELEMENT_NAME }"
LANGUAGE_XPATH =

:nodoc:

"cap:#{ LANGUAGE_ELEMENT_NAME }"
EVENT_XPATH =

:nodoc:

"cap:#{ EVENT_ELEMENT_NAME }"
URGENCY_XPATH =

:nodoc:

"cap:#{ URGENCY_ELEMENT_NAME }"
RESPONSE_TYPE_XPATH =

:nodoc:

"cap:#{ RESPONSE_TYPE_ELEMENT_NAME }"
CATEGORY_XPATH =

:nodoc:

"cap:#{ CATEGORY_ELEMENT_NAME }"
SEVERITY_XPATH =

:nodoc:

"cap:#{ SEVERITY_ELEMENT_NAME }"
CERTAINTY_XPATH =

:nodoc:

"cap:#{ CERTAINTY_ELEMENT_NAME }"
AUDIENCE_XPATH =

:nodoc:

"cap:#{ AUDIENCE_ELEMENT_NAME }"
EVENT_CODE_XPATH =

:nodoc:

"cap:#{ EVENT_CODE_ELEMENT_NAME }"
EFFECTIVE_XPATH =

:nodoc:

"cap:#{ EFFECTIVE_ELEMENT_NAME }"
ONSET_XPATH =

:nodoc:

"cap:#{ ONSET_ELEMENT_NAME }"
EXPIRES_XPATH =

:nodoc:

"cap:#{ EXPIRES_ELEMENT_NAME }"
SENDER_NAME_XPATH =

:nodoc:

"cap:#{ SENDER_NAME_ELEMENT_NAME }"
HEADLINE_XPATH =

:nodoc:

"cap:#{ HEADLINE_ELEMENT_NAME }"
DESCRIPTION_XPATH =

:nodoc:

"cap:#{ DESCRIPTION_ELEMENT_NAME }"
INSTRUCTION_XPATH =

:nodoc:

"cap:#{ INSTRUCTION_ELEMENT_NAME }"
WEB_XPATH =

:nodoc:

"cap:#{ WEB_ELEMENT_NAME }"
CONTACT_XPATH =

:nodoc:

"cap:#{ CONTACT_ELEMENT_NAME }"
DEFAULT_LANGUAGE =
'en-US'
LANGUAGE_YAML =

:nodoc:

'Language'
CATEGORIES_YAML =

:nodoc:

'Categories'
EVENT_YAML =

:nodoc:

'Event'
RESPONSE_TYPES_YAML =

:nodoc:

'Response Types'
URGENCY_YAML =

:nodoc:

'Urgency'
SEVERITY_YAML =

:nodoc:

'Severity'
CERTAINTY_YAML =

:nodoc:

'Certainty'
AUDIENCE_YAML =

:nodoc:

'Audience'
EFFECTIVE_YAML =

:nodoc:

'Effective'
ONSET_YAML =

:nodoc:

'Onset'
EXPIRES_YAML =

:nodoc:

'Expires'
SENDER_NAME_YAML =

:nodoc:

'Sender Name'
HEADLINE_YAML =

:nodoc:

'Headline'
DESCRIPTION_YAML =

:nodoc:

'Description'
INSTRUCTION_YAML =

:nodoc:

'Instruction'
WEB_YAML =

:nodoc:

'Web'
CONTACT_YAML =

:nodoc:

'Contact'
EVENT_CODES_YAML =

:nodoc:

'Event Codes'
PARAMETERS_YAML =

:nodoc:

'Parameters'
RESOURCES_YAML =

:nodoc:

'Resources'
AREAS_YAML =

:nodoc:

'Areas'
LANGUAGE_KEY =

:nodoc:

'language'
CATEGORIES_KEY =

:nodoc:

'categories'
EVENT_KEY =

:nodoc:

'event'
RESPONSE_TYPES_KEY =

:nodoc:

'response_types'
URGENCY_KEY =

:nodoc:

'urgency'
SEVERITY_KEY =

:nodoc:

'severity'
CERTAINTY_KEY =

:nodoc:

'certainty'
AUDIENCE_KEY =

:nodoc:

'audience'
EFFECTIVE_KEY =

:nodoc:

'effective'
ONSET_KEY =

:nodoc:

'onset'
EXPIRES_KEY =

:nodoc:

'expires'
SENDER_NAME_KEY =

:nodoc:

'sender_name'
HEADLINE_KEY =

:nodoc:

'headline'
DESCRIPTION_KEY =

:nodoc:

'description'
INSTRUCTION_KEY =

:nodoc:

'instruction'
WEB_KEY =

:nodoc:

'web'
CONTACT_KEY =

:nodoc:

'contact'
RESOURCES_KEY =

:nodoc:

'resources'
EVENT_CODES_KEY =

:nodoc:

'event_codes'
PARAMETERS_KEY =

:nodoc:

'parameters'
AREAS_KEY =

:nodoc:

'areas'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_h(info_hash) ⇒ Object

:nodoc:



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
# File 'lib/generators/rcap/models/templates/models/info.rb', line 423

def self.from_h( info_hash ) # :nodoc:
  self.new( :language       => info_hash[ LANGUAGE_KEY ],
            :categories     => info_hash[ CATEGORIES_KEY ],
            :event          => info_hash[ EVENT_KEY ],
            :response_types => info_hash[ RESPONSE_TYPES_KEY ],
            :urgency        => info_hash[ URGENCY_KEY ],
            :severity       => info_hash[ SEVERITY_KEY ],
            :certainty      => info_hash[ CERTAINTY_KEY ],
            :audience       => info_hash[ AUDIENCE_KEY ],
            :effective_at      => RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ]),
            :onset_at          => RCAP.parse_datetime( info_hash[ ONSET_KEY ]),
            :expires_at        => RCAP.parse_datetime( info_hash[ EXPIRES_KEY ]),
            :sender_name    => info_hash[ SENDER_NAME_KEY ],
            :headline       => info_hash[ HEADLINE_KEY ],
            :description    => info_hash[ DESCRIPTION_KEY ],
            :instruction    => info_hash[ INSTRUCTION_KEY ],
            :web            => info_hash[ WEB_KEY ],
            :contact        => info_hash[ CONTACT_KEY ],
            :resources      => Array( info_hash[ RESOURCES_KEY ]).map{ |resource_hash| RCAP::Resource.from_h( resource_hash ) },
            :event_codes    => Array( info_hash[ EVENT_CODES_KEY ]).map{ |event_code_hash| RCAP::EventCode.from_h( event_code_hash )},
            :parameters     => Array( info_hash[ PARAMETERS_KEY ]).map{ |parameter_hash| RCAP::Parameter.from_h( parameter_hash )},
            :areas          => Array( info_hash[ AREAS_KEY ]).map{ |area_hash| RCAP::Area.from_h( area_hash )})
end

.from_xml_element(info_xml_element) ⇒ Object

:nodoc:



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/generators/rcap/models/templates/models/info.rb', line 269

def self.from_xml_element( info_xml_element ) # :nodoc:
  self.new(
    :language       => RCAP.xpath_text( info_xml_element, LANGUAGE_XPATH ) || DEFAULT_LANGUAGE,
    :categories     => RCAP.xpath_match( info_xml_element, CATEGORY_XPATH ).map{ |element| element.text },
    :event          => RCAP.xpath_text( info_xml_element, EVENT_XPATH ),
    :response_types => RCAP.xpath_match( info_xml_element, RESPONSE_TYPE_XPATH ).map{ |element| element.text },
    :urgency        => RCAP.xpath_text( info_xml_element, URGENCY_XPATH ),
    :severity       => RCAP.xpath_text( info_xml_element, SEVERITY_XPATH ),
    :certainty      => RCAP.xpath_text( info_xml_element, CERTAINTY_XPATH ),
    :audience       => RCAP.xpath_text( info_xml_element, AUDIENCE_XPATH ),
    :effective_at      => (( effective = RCAP.xpath_first( info_xml_element, EFFECTIVE_XPATH )) ? DateTime.parse( effective.text ) : nil ),
    :onset_at          => (( onset = RCAP.xpath_first( info_xml_element, ONSET_XPATH )) ? DateTime.parse( onset.text ) : nil ),
    :expires_at        => (( expires = RCAP.xpath_first( info_xml_element, EXPIRES_XPATH )) ? DateTime.parse( expires.text ) : nil ),
    :sender_name    => RCAP.xpath_text( info_xml_element, SENDER_NAME_XPATH ),
    :headline       => RCAP.xpath_text( info_xml_element, HEADLINE_XPATH ),
    :description    => RCAP.xpath_text( info_xml_element, DESCRIPTION_XPATH ),
    :instruction    => RCAP.xpath_text( info_xml_element, INSTRUCTION_XPATH ),
    :web            => RCAP.xpath_text( info_xml_element, WEB_XPATH ),
    :contact        => RCAP.xpath_text( info_xml_element, CONTACT_XPATH ),
    :event_codes    => RCAP.xpath_match( info_xml_element, RCAP::EventCode::XPATH ).map{ |element| RCAP::EventCode.from_xml_element( element )},
    :parameters     => RCAP.xpath_match( info_xml_element, RCAP::Parameter::XPATH ).map{ |element| RCAP::Parameter.from_xml_element( element )},
    :resources      => RCAP.xpath_match( info_xml_element, RCAP::Resource::XPATH ).map{ |element| RCAP::Resource.from_xml_element( element )},
    :areas          => RCAP.xpath_match( info_xml_element, RCAP::Area::XPATH ).map{ |element| RCAP::Area.from_xml_element( element )}
  )
end

.from_yaml_data(info_yaml_data) ⇒ Object

:nodoc:



351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/generators/rcap/models/templates/models/info.rb', line 351

def self.from_yaml_data( info_yaml_data ) # :nodoc:
  self.new(
    :language       => info_yaml_data [ LANGUAGE_YAML ],
    :categories     => info_yaml_data [ CATEGORIES_YAML ],
    :event          => info_yaml_data [ EVENT_YAML ],
    :response_types => info_yaml_data [ RESPONSE_TYPES_YAML ],
    :urgency        => info_yaml_data [ URGENCY_YAML ],
    :severity       => info_yaml_data [ SEVERITY_YAML ],
    :certainty      => info_yaml_data [ CERTAINTY_YAML ],
    :audience       => info_yaml_data [ AUDIENCE_YAML ],
    :effective_at      => ( effective = info_yaml_data[ EFFECTIVE_YAML ]).blank? ? nil : DateTime.parse( effective.to_s ),
    :onset_at          => ( onset = info_yaml_data[ ONSET_YAML ]).blank? ? nil : DateTime.parse( onset.to_s ),
    :expires_at        => ( expires = info_yaml_data[ EXPIRES_YAML ]).blank? ? nil : DateTime.parse( expires.to_s ),
    :sender_name    => info_yaml_data [ SENDER_NAME_YAML ],
    :headline       => info_yaml_data [ HEADLINE_YAML ],
    :description    => info_yaml_data [ DESCRIPTION_YAML ],
    :instruction    => info_yaml_data [ INSTRUCTION_YAML ],
    :web            => info_yaml_data [ WEB_YAML ],
    :contact        => info_yaml_data [ CONTACT_YAML ],
    :event_codes    => Array( info_yaml_data [ EVENT_CODES_YAML ]).map{ |name,value| RCAP::EventCode.new( :name => name, :value => value )},
    :parameters     => Array( info_yaml_data [ PARAMETERS_YAML ]).map{ |parameter_yaml_data| RCAP::Parameter.new( :name => name, :value => value )},
    :resources      => Array( info_yaml_data [ RESOURCES_YAML ]).map{ |resource_yaml_data| RCAP::Resource.from_yaml_data( resource_yaml_data )},
    :areas          => Array( info_yaml_data [ AREAS_YAML ]).map{ |area_yaml_data| RCAP::Area.from_yaml_data( area_yaml_data )}
  )
end

Instance Method Details

#inspectObject

:nodoc:



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/generators/rcap/models/templates/models/info.rb', line 232

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

#to_hObject

:nodoc:



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/generators/rcap/models/templates/models/info.rb', line 399

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

#to_sObject

Returns a string representation of the event of the form

event(urgency/severity/certainty)


265
266
267
# File 'lib/generators/rcap/models/templates/models/info.rb', line 265

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

#to_xmlObject

:nodoc:



228
229
230
# File 'lib/generators/rcap/models/templates/models/info.rb', line 228

def to_xml # :nodoc:
  self.to_xml_element.to_s
end

#to_xml_elementObject

def initialize( attributes = {} )

@language       = attributes[ :language ] || DEFAULT_LANGUAGE
@categories     = Array( attributes[ :categories ])
@event          = attributes [ :event ]
@response_types = Array( attributes[ :response_types ])
@urgency        = attributes[ :urgency ]
@severity       = attributes[ :severity ]
@certainty      = attributes[ :certainty ]
@effective      = attributes[ :effective ]
@onset          = attributes[ :onset ]
@expires        = attributes[ :expires ]
@event_codes    = Array( attributes[ :event_codes ])
@sender_name    = attributes[ :sender_name ]
@headline       = attributes[ :headline ]
@description    = attributes[ :description ]
@instruction    = attributes[ :instruction ]
@web            = attributes[ :web ]
@contact        = attributes[ :contact ]
@parameters     = Array( attributes[ :parameters ])
@resources      = Array( attributes[ :resources ])
@areas          = Array( attributes[ :areas ])

end



190
191
192
193
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
219
220
221
222
223
224
225
226
# File 'lib/generators/rcap/models/templates/models/info.rb', line 190

def to_xml_element # :nodoc:
  xml_element = REXML::Element.new( XML_ELEMENT_NAME )
  xml_element.add_element( LANGUAGE_ELEMENT_NAME ).add_text( self.language ) if self.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( self.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( self.urgency )
  xml_element.add_element( SEVERITY_ELEMENT_NAME ).add_text( self.severity )
  xml_element.add_element( CERTAINTY_ELEMENT_NAME ).add_text( self.certainty )
  xml_element.add_element( AUDIENCE_ELEMENT_NAME ).add_text( self.audience ) if self.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( self.effective_at.to_s_for_cap ) if self.effective_at
  xml_element.add_element( ONSET_ELEMENT_NAME ).add_text( self.onset_at.to_s_for_cap )         if self.onset_at
  xml_element.add_element( EXPIRES_ELEMENT_NAME ).add_text( self.expires_at.to_s_for_cap )     if self.expires_at
  xml_element.add_element( SENDER_NAME_ELEMENT_NAME ).add_text( self.sender_name )          if self.sender_name
  xml_element.add_element( HEADLINE_ELEMENT_NAME ).add_text( self.headline )                if self.headline
  xml_element.add_element( DESCRIPTION_ELEMENT_NAME ).add_text( self.description )          if self.description
  xml_element.add_element( INSTRUCTION_ELEMENT_NAME ).add_text( self.instruction )          if self.instruction
  xml_element.add_element( WEB_ELEMENT_NAME ).add_text( self.web )                          if self.web
  xml_element.add_element( CONTACT_ELEMENT_NAME ).add_text( self.contact )                  if self.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 = {}) ⇒ Object

:nodoc:



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/generators/rcap/models/templates/models/info.rb', line 317

def to_yaml( options = {} ) # :nodoc:
  response_types_yaml = self.response_types
  def response_types_yaml.to_yaml_style; :inline; end

  categories_yaml = self.categories
  def categories_yaml.to_yaml_style; :inline; end

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

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