Class: RCAP::CAP_1_0::Alert
- Inherits:
-
Base::Alert
- Object
- Base::Alert
- RCAP::CAP_1_0::Alert
- 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 collapse
- 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
-
.from_h(alert_hash) ⇒ RCAP::CAP_1_0::Alert
Initialises an Alert object from a Hash produced by Alert#to_h.
- .from_xml_element(alert_xml_element) ⇒ RCAP::CAP_1_0::Alert
- .from_yaml_data(alert_yaml_data) ⇒ RCAP::CAP_1_0::Alert
Instance Method Summary collapse
- #info_class ⇒ Class
- #inspect ⇒ String
-
#to_h ⇒ Hash
Returns a Hash representation of an Alert object.
- #to_xml_element ⇒ REXML::Element
-
#to_yaml(options = {}) ⇒ String
Returns a string containing the YAML representation of the alert.
- #xmlns ⇒ String
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
Methods included from Validation
#errors, included, #valid?, #validate
Constructor Details
This class inherits a constructor from RCAP::Base::Alert
Instance Attribute Details
Class Method Details
.from_h(alert_hash) ⇒ RCAP::CAP_1_0::Alert
Initialises an Alert object from a Hash produced by Alert#to_h
156 157 158 159 160 |
# File 'lib/rcap/cap_1_0/alert.rb', line 156 def self.from_h(alert_hash) super.tap do |alert| alert.password = RCAP.strip_if_given(alert_hash[PASSWORD_KEY]) end end |
.from_xml_element(alert_xml_element) ⇒ RCAP::CAP_1_0::Alert
90 91 92 93 94 |
# File 'lib/rcap/cap_1_0/alert.rb', line 90 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 |
.from_yaml_data(alert_yaml_data) ⇒ RCAP::CAP_1_0::Alert
122 123 124 125 126 |
# File 'lib/rcap/cap_1_0/alert.rb', line 122 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
#info_class ⇒ Class
24 25 26 |
# File 'lib/rcap/cap_1_0/alert.rb', line 24 def info_class Info end |
#inspect ⇒ String
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rcap/cap_1_0/alert.rb', line 63 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("\n "), "Incidents: #{ @incidents.join(' ')}", 'Information:', @infos.map { |info| ' ' + info.to_s }.join("\n")].join("\n") RCAP.format_lines_for_inspect('ALERT', alert_inspect) end |
#to_h ⇒ Hash
Returns a Hash representation of an Alert object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/rcap/cap_1_0/alert.rb', line 133 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 |
#to_xml_element ⇒ REXML::Element
31 32 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 |
# File 'lib/rcap/cap_1_0/alert.rb', line 31 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 |
#to_yaml(options = {}) ⇒ String
Returns a string containing the YAML representation of the alert.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rcap/cap_1_0/alert.rb', line 101 def to_yaml( = {}) 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.map(&:to_yaml_data)]).to_yaml() end |