Class: RCAP::CAP_1_0::Alert

Inherits:
Base::Alert show all
Defined in:
lib/rcap/cap_1_0/alert.rb

Overview

An Alert object is valid if

  • it has an identifier

  • it has a sender

  • it has a sent time

  • it has a valid status value

  • it has a valid messge type value

  • it has a valid scope value

  • all Info objects contained in infos are valid

Constant Summary

XMLNS =
"http://www.incident.com/cap/1.0"
CAP_VERSION =
"1.0"
PASSWORD_ELEMENT_NAME =
'password'
PASSWORD_XPATH =
"cap:#{ PASSWORD_ELEMENT_NAME }"
PASSWORD_YAML =
"Password"
PASSWORD_KEY =
'password'

Constants inherited from Base::Alert

Base::Alert::ADDRESSES_ELEMENT_NAME, Base::Alert::ADDRESSES_KEY, Base::Alert::ADDRESSES_XPATH, Base::Alert::ADDRESSES_YAML, Base::Alert::CAP_VERSION_KEY, Base::Alert::CAP_VERSION_YAML, Base::Alert::CODES_KEY, Base::Alert::CODES_YAML, Base::Alert::CODE_ELEMENT_NAME, Base::Alert::CODE_XPATH, Base::Alert::IDENTIFIER_ELEMENT_NAME, Base::Alert::IDENTIFIER_KEY, Base::Alert::IDENTIFIER_XPATH, Base::Alert::IDENTIFIER_YAML, Base::Alert::INCIDENTS_ELEMENT_NAME, Base::Alert::INCIDENTS_KEY, Base::Alert::INCIDENTS_XPATH, Base::Alert::INCIDENTS_YAML, Base::Alert::INFOS_KEY, Base::Alert::INFOS_YAML, Base::Alert::MSG_TYPE_ACK, Base::Alert::MSG_TYPE_ALERT, Base::Alert::MSG_TYPE_CANCEL, Base::Alert::MSG_TYPE_ELEMENT_NAME, Base::Alert::MSG_TYPE_ERROR, Base::Alert::MSG_TYPE_KEY, Base::Alert::MSG_TYPE_UPDATE, Base::Alert::MSG_TYPE_XPATH, Base::Alert::MSG_TYPE_YAML, Base::Alert::NOTE_ELEMENT_NAME, Base::Alert::NOTE_KEY, Base::Alert::NOTE_XPATH, Base::Alert::NOTE_YAML, Base::Alert::REFERENCES_ELEMENT_NAME, Base::Alert::REFERENCES_KEY, Base::Alert::REFERENCES_XPATH, Base::Alert::REFERENCES_YAML, Base::Alert::RESTRICTION_ELEMENT_NAME, Base::Alert::RESTRICTION_KEY, Base::Alert::RESTRICTION_XPATH, Base::Alert::RESTRICTION_YAML, Base::Alert::SCOPE_ELEMENT_NAME, Base::Alert::SCOPE_KEY, Base::Alert::SCOPE_PRIVATE, Base::Alert::SCOPE_PUBLIC, Base::Alert::SCOPE_RESTRICTED, Base::Alert::SCOPE_XPATH, Base::Alert::SCOPE_YAML, Base::Alert::SENDER_ELEMENT_NAME, Base::Alert::SENDER_KEY, Base::Alert::SENDER_XPATH, Base::Alert::SENDER_YAML, Base::Alert::SENT_ELEMENT_NAME, Base::Alert::SENT_KEY, Base::Alert::SENT_XPATH, Base::Alert::SENT_YAML, Base::Alert::SOURCE_ELEMENT_NAME, Base::Alert::SOURCE_KEY, Base::Alert::SOURCE_XPATH, Base::Alert::SOURCE_YAML, Base::Alert::STATUS_ACTUAL, Base::Alert::STATUS_ELEMENT_NAME, Base::Alert::STATUS_EXERCISE, Base::Alert::STATUS_KEY, Base::Alert::STATUS_SYSTEM, Base::Alert::STATUS_TEST, Base::Alert::STATUS_XPATH, Base::Alert::STATUS_YAML, Base::Alert::VALID_MSG_TYPES, Base::Alert::VALID_SCOPES, Base::Alert::VALID_STATUSES, Base::Alert::XML_ELEMENT_NAME, Base::Alert::XPATH

Instance Attribute Summary (collapse)

Attributes inherited from Base::Alert

#addresses, #codes, #identifier, #incidents, #infos, #msg_type, #note, #references, #restriction, #scope, #sender, #sent, #source, #status

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base::Alert

#add_info, from_json, from_xml, from_xml_document, from_yaml, #initialize, #to_json, #to_reference, #to_s, #to_xml, #to_xml_document

Constructor Details

This class inherits a constructor from RCAP::Base::Alert

Instance Attribute Details

- (String) password

Returns:



18
19
20
# File 'lib/rcap/cap_1_0/alert.rb', line 18

def password
  @password
end

Class Method Details

+ (RCAP::CAP_1_0::Alert) from_h(alert_hash)

Initialises an Alert object from a Hash produced by Alert#to_h

Parameters:

  • alert_hash (Hash)

Returns:



159
160
161
162
163
# File 'lib/rcap/cap_1_0/alert.rb', line 159

def self.from_h( alert_hash )
  super.tap do |alert|
    alert.password = RCAP.strip_if_given( alert_hash[ PASSWORD_KEY ])
  end
end

+ (RCAP::CAP_1_0::Alert) from_xml_element(alert_xml_element)

Parameters:

  • alert_xml_element (REXML::Element)

Returns:



92
93
94
95
96
# File 'lib/rcap/cap_1_0/alert.rb', line 92

def self.from_xml_element( alert_xml_element )
  super.tap do |alert|
    alert.password = RCAP.xpath_text( alert_xml_element, PASSWORD_XPATH, Alert::XMLNS )
  end
end

+ (RCAP::CAP_1_0::Alert) from_yaml_data(alert_yaml_data)

Parameters:

  • alert_yaml_data (Hash)

Returns:



125
126
127
128
129
# File 'lib/rcap/cap_1_0/alert.rb', line 125

def self.from_yaml_data( alert_yaml_data )
  super.tap do |alert|
    alert.password = RCAP.strip_if_given( alert_yaml_data[ PASSWORD_YAML ])
  end
end

Instance Method Details

- (Class) info_class

Returns:

  • (Class)


26
27
28
# File 'lib/rcap/cap_1_0/alert.rb', line 26

def info_class
  Info
end

- (String) inspect

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rcap/cap_1_0/alert.rb', line 65

def inspect
  alert_inspect = [ "CAP Version:  #{ CAP_VERSION }",
                    "Identifier:   #{ @identifier }",
                    "Sender:       #{ @sender }",
                    "Sent:         #{ @sent }",
                    "Status:       #{ @status }",
                    "Message Type: #{ @msg_type }",
                    "Password:     #{ @password }",
                    "Source:       #{ @source }",
                    "Scope:        #{ @scope }",
                    "Restriction:  #{ @restriction }",
                    "Addresses:    #{ @addresses.to_s_for_cap }",
                    "Codes:",
                    @codes.map{ |code| "  " + code }.join("\n"),
                    "Note:         #{ @note }",
                    "References:   #{ @references.join( ' ' )}",
                    "Incidents:    #{ @incidents.join( ' ')}",
                    "Information:",
                    @infos.map{ |info| "  " + info.to_s }.join( "\n" )].join("\n")
  RCAP.format_lines_for_inspect( 'ALERT', alert_inspect )
end

- (Hash) to_h

Returns a Hash representation of an Alert object

Returns:

  • (Hash)


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rcap/cap_1_0/alert.rb', line 136

def to_h
  RCAP.attribute_values_to_hash( [ CAP_VERSION_KEY, CAP_VERSION ],
                                 [ IDENTIFIER_KEY,   @identifier ],
                                 [ SENDER_KEY,       @sender ],
                                 [ SENT_KEY,         RCAP.to_s_for_cap( @sent )],
                                 [ STATUS_KEY,       @status ],
                                 [ MSG_TYPE_KEY,     @msg_type ],
                                 [ PASSWORD_KEY,     @password ],
                                 [ SOURCE_KEY,       @source ],
                                 [ SCOPE_KEY,        @scope ],
                                 [ RESTRICTION_KEY,  @restriction ],
                                 [ ADDRESSES_KEY,    @addresses ],
                                 [ CODES_KEY,        @codes ],
                                 [ NOTE_KEY,         @note ],
                                 [ REFERENCES_KEY,   @references ],
                                 [ INCIDENTS_KEY,    @incidents ],
                                 [ INFOS_KEY,        @infos.map{ |info| info.to_h  }])
end

- (REXML::Element) to_xml_element

Returns:

  • (REXML::Element)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rcap/cap_1_0/alert.rb', line 33

def to_xml_element
  xml_element = REXML::Element.new( XML_ELEMENT_NAME )
  xml_element.add_namespace( XMLNS )
  xml_element.add_element( IDENTIFIER_ELEMENT_NAME ).add_text( @identifier )   if @identifier
  xml_element.add_element( SENDER_ELEMENT_NAME ).add_text( @sender )           if @sender
  xml_element.add_element( SENT_ELEMENT_NAME ).add_text( @sent.to_s_for_cap )  if @sent
  xml_element.add_element( STATUS_ELEMENT_NAME ).add_text( @status )           if @status
  xml_element.add_element( MSG_TYPE_ELEMENT_NAME ).add_text( @msg_type )       if @msg_type
  xml_element.add_element( PASSWORD_ELEMENT_NAME ).add_text( @password )       if @password
  xml_element.add_element( SOURCE_ELEMENT_NAME ).add_text( @source )           if @source
  xml_element.add_element( SCOPE_ELEMENT_NAME ).add_text( @scope )             if @scope
  xml_element.add_element( RESTRICTION_ELEMENT_NAME ).add_text( @restriction ) if @restriction
  if @addresses.any?
    xml_element.add_element( ADDRESSES_ELEMENT_NAME ).add_text( @addresses.to_s_for_cap )
  end
  @codes.each do |code|
    xml_element.add_element( CODE_ELEMENT_NAME ).add_text( code )
  end
  xml_element.add_element( NOTE_ELEMENT_NAME ).add_text( @note ) if @note
  if @references.any?
    xml_element.add_element( REFERENCES_ELEMENT_NAME ).add_text( @references.join( ' ' ))
  end
  if @incidents.any?
    xml_element.add_element( INCIDENTS_ELEMENT_NAME ).add_text( @incidents.join( ' ' ))
  end
  @infos.each do |info|
    xml_element.add_element( info.to_xml_element )
  end
  xml_element
end

- (String) to_yaml(options = {})

Returns a string containing the YAML representation of the alert.

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rcap/cap_1_0/alert.rb', line 104

def to_yaml( options = {} )
  RCAP.attribute_values_to_hash( [ CAP_VERSION_YAML, CAP_VERSION ],
                                 [ IDENTIFIER_YAML,  @identifier ],
                                 [ SENDER_YAML,      @sender ],
                                 [ SENT_YAML,        @sent ],
                                 [ STATUS_YAML,      @status ],
                                 [ MSG_TYPE_YAML,    @msg_type ],
                                 [ PASSWORD_YAML,    @password ],
                                 [ SOURCE_YAML,      @source ],
                                 [ SCOPE_YAML,       @scope ],
                                 [ RESTRICTION_YAML, @restriction ],
                                 [ ADDRESSES_YAML,   @addresses ],
                                 [ CODES_YAML,       @codes ],
                                 [ NOTE_YAML,        @note ],
                                 [ REFERENCES_YAML,  @references ],
                                 [ INCIDENTS_YAML,   @incidents ],
                                 [ INFOS_YAML,       @infos ]).to_yaml( options )
end

- (String) xmlns

Returns:



21
22
23
# File 'lib/rcap/cap_1_0/alert.rb', line 21

def xmlns
  XMLNS
end