lib/rcap/cap_1_0/alert.rb in rcap-2.7.0 vs lib/rcap/cap_1_0/alert.rb in rcap-2.7.3
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module RCAP
module CAP_1_0
# An Alert object is valid if
# * it has an identifier
# * it has a sender
@@ -23,11 +25,11 @@
# @return [Class]
def info_class
Info
end
- PASSWORD_ELEMENT_NAME = 'password'
+ PASSWORD_ELEMENT_NAME = 'password'
# @return [REXML::Element]
def to_xml_element
xml_element = REXML::Element.new(XML_ELEMENT_NAME)
xml_element.add_namespace(XMLNS)
@@ -59,43 +61,43 @@
xml_element
end
# @return [String]
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 }",
+ 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(' ')}",
+ "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
- PASSWORD_XPATH = "cap:#{ PASSWORD_ELEMENT_NAME }"
+ PASSWORD_XPATH = "cap:#{PASSWORD_ELEMENT_NAME}"
# @param [REXML::Element] alert_xml_element
# @return [RCAP::CAP_1_0::Alert]
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
- PASSWORD_YAML = 'Password'
+ PASSWORD_YAML = 'Password'
# Returns a string containing the YAML representation of the alert.
#
# @return [String]
def to_yaml(options = {})
@@ -123,11 +125,11 @@
super.tap do |alert|
alert.password = RCAP.strip_if_given(alert_yaml_data[PASSWORD_YAML])
end
end
- PASSWORD_KEY = 'password'
+ PASSWORD_KEY = 'password'
# Returns a Hash representation of an Alert object
#
# @return [Hash]
def to_h
@@ -144,10 +146,10 @@
[ADDRESSES_KEY, @addresses],
[CODES_KEY, @codes],
[NOTE_KEY, @note],
[REFERENCES_KEY, @references],
[INCIDENTS_KEY, @incidents],
- [INFOS_KEY, @infos.map { |info| info.to_h }])
+ [INFOS_KEY, @infos.map(&:to_h)])
end
# Initialises an Alert object from a Hash produced by Alert#to_h
#
# @param [Hash] alert_hash