rcap 2.7.0 → 2.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/lib/rcap.rb +2 -0
- data/lib/rcap/alert.rb +4 -2
- data/lib/rcap/base/alert.rb +57 -55
- data/lib/rcap/base/area.rb +19 -13
- data/lib/rcap/base/circle.rb +6 -4
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +65 -59
- data/lib/rcap/base/parameter.rb +6 -4
- data/lib/rcap/base/point.rb +4 -2
- data/lib/rcap/base/polygon.rb +8 -6
- data/lib/rcap/base/resource.rb +9 -9
- data/lib/rcap/cap_1_0/alert.rb +22 -20
- data/lib/rcap/cap_1_0/area.rb +2 -0
- data/lib/rcap/cap_1_0/circle.rb +2 -0
- data/lib/rcap/cap_1_0/event_code.rb +3 -1
- data/lib/rcap/cap_1_0/geocode.rb +3 -1
- data/lib/rcap/cap_1_0/info.rb +3 -1
- data/lib/rcap/cap_1_0/parameter.rb +3 -1
- data/lib/rcap/cap_1_0/point.rb +2 -0
- data/lib/rcap/cap_1_0/polygon.rb +2 -0
- data/lib/rcap/cap_1_0/resource.rb +2 -0
- data/lib/rcap/cap_1_1/alert.rb +4 -2
- data/lib/rcap/cap_1_1/area.rb +2 -0
- data/lib/rcap/cap_1_1/circle.rb +2 -0
- data/lib/rcap/cap_1_1/event_code.rb +3 -1
- data/lib/rcap/cap_1_1/geocode.rb +3 -1
- data/lib/rcap/cap_1_1/info.rb +34 -32
- data/lib/rcap/cap_1_1/parameter.rb +2 -0
- data/lib/rcap/cap_1_1/point.rb +2 -0
- data/lib/rcap/cap_1_1/polygon.rb +2 -0
- data/lib/rcap/cap_1_1/resource.rb +6 -4
- data/lib/rcap/cap_1_2/alert.rb +4 -2
- data/lib/rcap/cap_1_2/area.rb +2 -0
- data/lib/rcap/cap_1_2/circle.rb +2 -0
- data/lib/rcap/cap_1_2/event_code.rb +3 -1
- data/lib/rcap/cap_1_2/geocode.rb +3 -1
- data/lib/rcap/cap_1_2/info.rb +42 -38
- data/lib/rcap/cap_1_2/parameter.rb +2 -0
- data/lib/rcap/cap_1_2/point.rb +2 -0
- data/lib/rcap/cap_1_2/polygon.rb +2 -0
- data/lib/rcap/cap_1_2/resource.rb +8 -5
- data/lib/rcap/config.rb +2 -0
- data/lib/rcap/custom_validators.rb +11 -11
- data/lib/rcap/extensions/array.rb +2 -0
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +4 -1
- data/lib/rcap/extensions/float.rb +2 -0
- data/lib/rcap/extensions/integer.rb +2 -0
- data/lib/rcap/extensions/nil_class.rb +2 -0
- data/lib/rcap/extensions/string.rb +3 -1
- data/lib/rcap/extensions/time.rb +3 -0
- data/lib/rcap/formatters/yaml.rb +3 -2
- data/lib/rcap/info.rb +2 -0
- data/lib/rcap/utilities.rb +7 -9
- data/lib/rcap/validation.rb +11 -9
- data/lib/rcap/version.rb +3 -1
- metadata +3 -4
data/lib/rcap/cap_1_1/point.rb
CHANGED
data/lib/rcap/cap_1_1/polygon.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_1
|
3
5
|
# A Resource object is valid if
|
@@ -6,8 +8,8 @@ module RCAP
|
|
6
8
|
# @return [String] Dereferenced URI - contents of URI Base64 encoded
|
7
9
|
attr_accessor(:deref_uri)
|
8
10
|
|
9
|
-
DEREF_URI_ELEMENT_NAME
|
10
|
-
DEREF_URI_XPATH
|
11
|
+
DEREF_URI_ELEMENT_NAME = 'derefUri'
|
12
|
+
DEREF_URI_XPATH = "cap:#{DEREF_URI_ELEMENT_NAME}"
|
11
13
|
|
12
14
|
# @return [REXML::Element]
|
13
15
|
def to_xml_element
|
@@ -50,7 +52,7 @@ module RCAP
|
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
DEREF_URI_YAML
|
55
|
+
DEREF_URI_YAML = 'Derefrenced URI Data'
|
54
56
|
|
55
57
|
def to_yaml_data
|
56
58
|
RCAP.attribute_values_to_hash([RESOURCE_DESC_YAML, @resource_desc],
|
@@ -75,7 +77,7 @@ module RCAP
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
DEREF_URI_KEY
|
80
|
+
DEREF_URI_KEY = 'deref_uri'
|
79
81
|
|
80
82
|
# @return [Hash]
|
81
83
|
def to_h
|
data/lib/rcap/cap_1_2/alert.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
5
|
# An Alert object is valid if
|
@@ -12,9 +14,9 @@ module RCAP
|
|
12
14
|
XMLNS = 'urn:oasis:names:tc:emergency:cap:1.2'
|
13
15
|
CAP_VERSION = '1.2'
|
14
16
|
|
15
|
-
STATUS_DRAFT
|
17
|
+
STATUS_DRAFT = 'Draft'
|
16
18
|
# Valid values for status
|
17
|
-
VALID_STATUSES = [STATUS_ACTUAL, STATUS_EXERCISE, STATUS_SYSTEM, STATUS_TEST, STATUS_DRAFT]
|
19
|
+
VALID_STATUSES = [STATUS_ACTUAL, STATUS_EXERCISE, STATUS_SYSTEM, STATUS_TEST, STATUS_DRAFT].freeze
|
18
20
|
|
19
21
|
# @return [String]
|
20
22
|
def xmlns
|
data/lib/rcap/cap_1_2/area.rb
CHANGED
data/lib/rcap/cap_1_2/circle.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
5
|
# Subclass of {Parameter}
|
4
6
|
class EventCode < RCAP::Base::EventCode
|
5
7
|
XML_ELEMENT_NAME = 'eventCode'
|
6
|
-
XPATH = "cap:#{
|
8
|
+
XPATH = "cap:#{XML_ELEMENT_NAME}"
|
7
9
|
|
8
10
|
# @return [String]
|
9
11
|
def xmlns
|
data/lib/rcap/cap_1_2/geocode.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
5
|
# Subclass of {Parameter}
|
4
6
|
class Geocode < RCAP::Base::Geocode
|
5
7
|
XML_ELEMENT_NAME = 'geocode'
|
6
|
-
XPATH = "cap:#{
|
8
|
+
XPATH = "cap:#{XML_ELEMENT_NAME}"
|
7
9
|
|
8
10
|
# @return [String]
|
9
11
|
def xmlns
|
data/lib/rcap/cap_1_2/info.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
5
|
# In Info object is valid if
|
@@ -9,26 +11,28 @@ module RCAP
|
|
9
11
|
# * all Resource objects in the resources collection are valid
|
10
12
|
# * all Area objects in the areas collection are valid
|
11
13
|
class Info < RCAP::Base::Info
|
12
|
-
RESPONSE_TYPE_SHELTER
|
13
|
-
RESPONSE_TYPE_EVACUATE
|
14
|
-
RESPONSE_TYPE_PREPARE
|
15
|
-
RESPONSE_TYPE_EXECUTE
|
16
|
-
RESPONSE_TYPE_MONITOR
|
17
|
-
|
18
|
-
|
14
|
+
RESPONSE_TYPE_SHELTER = 'Shelter'
|
15
|
+
RESPONSE_TYPE_EVACUATE = 'Evacuate'
|
16
|
+
RESPONSE_TYPE_PREPARE = 'Prepare'
|
17
|
+
RESPONSE_TYPE_EXECUTE = 'Execute'
|
18
|
+
RESPONSE_TYPE_MONITOR = 'Monitor'
|
19
|
+
RESPONSE_TYPE_AVOID = 'Avoid'
|
20
|
+
RESPONSE_TYPE_ASSESS = 'Assess'
|
21
|
+
RESPONSE_TYPE_ALL_CLEAR = 'AllClear'
|
22
|
+
RESPONSE_TYPE_NONE = 'None'
|
19
23
|
# Valid values for response_type
|
20
|
-
VALID_RESPONSE_TYPES = [RESPONSE_TYPE_SHELTER, RESPONSE_TYPE_EVACUATE, RESPONSE_TYPE_PREPARE, RESPONSE_TYPE_EXECUTE, RESPONSE_TYPE_MONITOR, RESPONSE_TYPE_ASSESS, RESPONSE_TYPE_NONE]
|
24
|
+
VALID_RESPONSE_TYPES = [RESPONSE_TYPE_SHELTER, RESPONSE_TYPE_EVACUATE, RESPONSE_TYPE_PREPARE, RESPONSE_TYPE_EXECUTE, RESPONSE_TYPE_MONITOR, RESPONSE_TYPE_AVOID, RESPONSE_TYPE_ASSESS, RESPONSE_TYPE_ALL_CLEAR, RESPONSE_TYPE_NONE].freeze
|
21
25
|
|
22
26
|
CERTAINTY_OBSERVED = 'Observed'
|
23
27
|
# Valid valies for certainty
|
24
|
-
VALID_CERTAINTIES = [CERTAINTY_OBSERVED, CERTAINTY_LIKELY, CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN]
|
28
|
+
VALID_CERTAINTIES = [CERTAINTY_OBSERVED, CERTAINTY_LIKELY, CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN].freeze
|
25
29
|
|
26
30
|
RESPONSE_TYPE_ELEMENT_NAME = 'responseType'
|
27
|
-
RESPONSE_TYPE_XPATH = "cap:#{
|
31
|
+
RESPONSE_TYPE_XPATH = "cap:#{RESPONSE_TYPE_ELEMENT_NAME}"
|
28
32
|
|
29
33
|
validates_length_of(:categories, minimum: 1)
|
30
34
|
validates_inclusion_of_members_of(:response_types, in: VALID_RESPONSE_TYPES, allow_blank: true)
|
31
|
-
validates_inclusion_of(:certainty, allow_nil: true, in: VALID_CERTAINTIES, message: "can only be assigned the following values: #{
|
35
|
+
validates_inclusion_of(:certainty, allow_nil: true, in: VALID_CERTAINTIES, message: "can only be assigned the following values: #{VALID_CERTAINTIES.join(', ')}")
|
32
36
|
|
33
37
|
# @return [Array<String>] Collection of textual response types; elements must be from {VALID_RESPONSE_TYPES}
|
34
38
|
attr_reader(:response_types)
|
@@ -113,27 +117,27 @@ module RCAP
|
|
113
117
|
|
114
118
|
# @return [String]
|
115
119
|
def inspect
|
116
|
-
info_inspect = "Language: #{
|
117
|
-
"Categories: #{
|
118
|
-
"Event: #{
|
119
|
-
"Response Types: #{
|
120
|
-
"Urgency: #{
|
121
|
-
"Severity: #{
|
122
|
-
"Certainty: #{
|
123
|
-
"Audience: #{
|
124
|
-
"Event Codes: #{
|
125
|
-
"Effective: #{
|
126
|
-
"Onset: #{
|
127
|
-
"Expires: #{
|
128
|
-
"Sender Name: #{
|
129
|
-
"Headline: #{
|
130
|
-
"Description:\n" +
|
131
|
-
"Instruction: #{
|
132
|
-
"Web: #{
|
133
|
-
"Contact: #{
|
134
|
-
"Parameters:\n" +
|
135
|
-
"Resources:\n" +
|
136
|
-
"Area:\n" +
|
120
|
+
info_inspect = "Language: #{@language}\n"\
|
121
|
+
"Categories: #{@categories.to_s_for_cap}\n"\
|
122
|
+
"Event: #{@event}\n"\
|
123
|
+
"Response Types: #{@response_types.to_s_for_cap}\n"\
|
124
|
+
"Urgency: #{@urgency}\n"\
|
125
|
+
"Severity: #{@severity}\n"\
|
126
|
+
"Certainty: #{@certainty}\n"\
|
127
|
+
"Audience: #{@audience}\n"\
|
128
|
+
"Event Codes: #{@event_codes.inspect}\n"\
|
129
|
+
"Effective: #{@effective}\n"\
|
130
|
+
"Onset: #{@onset}\n"\
|
131
|
+
"Expires: #{@expires}\n"\
|
132
|
+
"Sender Name: #{@sender_name}\n"\
|
133
|
+
"Headline: #{@headline}\n"\
|
134
|
+
"Description:\n" + @description.to_s.lines.map { |line| ' ' + line }.join("\n") + "\n"\
|
135
|
+
"Instruction: #{@instruction}\n"\
|
136
|
+
"Web: #{@web}\n"\
|
137
|
+
"Contact: #{@contact}\n"\
|
138
|
+
"Parameters:\n" + @parameters.map { |parameter| ' ' + parameter.inspect }.join("\n") + "\n"\
|
139
|
+
"Resources:\n" + @resources.map { |resource| ' ' + resource.inspect }.join("\n") + "\n"\
|
140
|
+
"Area:\n" + @areas.map { |area| " #{area}" }.join("\n") + "\n"
|
137
141
|
RCAP.format_lines_for_inspect('INFO', info_inspect)
|
138
142
|
end
|
139
143
|
|
@@ -142,7 +146,7 @@ module RCAP
|
|
142
146
|
#
|
143
147
|
# @return [String]
|
144
148
|
def to_s
|
145
|
-
"#{
|
149
|
+
"#{@event}(#{@urgency}/#{@severity}/#{@certainty})"
|
146
150
|
end
|
147
151
|
|
148
152
|
# @param [REXML::Element] info_xml_element
|
@@ -159,7 +163,7 @@ module RCAP
|
|
159
163
|
|
160
164
|
# @return [Hash]
|
161
165
|
def to_yaml_data
|
162
|
-
parameter_to_hash =
|
166
|
+
parameter_to_hash = ->(hash, parameter) { hash.merge(parameter.name => parameter.value) }
|
163
167
|
|
164
168
|
RCAP.attribute_values_to_hash([LANGUAGE_YAML, @language],
|
165
169
|
[CATEGORIES_YAML, @categories],
|
@@ -220,10 +224,10 @@ module RCAP
|
|
220
224
|
[INSTRUCTION_KEY, @instruction],
|
221
225
|
[WEB_KEY, @web],
|
222
226
|
[CONTACT_KEY, @contact],
|
223
|
-
[RESOURCES_KEY, @resources.map
|
224
|
-
[EVENT_CODES_KEY, @event_codes.map
|
225
|
-
[PARAMETERS_KEY, @parameters.map
|
226
|
-
[AREAS_KEY, @areas.map
|
227
|
+
[RESOURCES_KEY, @resources.map(&:to_h)],
|
228
|
+
[EVENT_CODES_KEY, @event_codes.map(&:to_h)],
|
229
|
+
[PARAMETERS_KEY, @parameters.map(&:to_h)],
|
230
|
+
[AREAS_KEY, @areas.map(&:to_h)])
|
227
231
|
end
|
228
232
|
|
229
233
|
# @param [Hash] info_hash
|
data/lib/rcap/cap_1_2/point.rb
CHANGED
data/lib/rcap/cap_1_2/polygon.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module CAP_1_2
|
3
5
|
# A Resource object is valid if
|
@@ -9,9 +11,9 @@ module RCAP
|
|
9
11
|
|
10
12
|
validates_presence_of(:mime_type)
|
11
13
|
|
12
|
-
DEREF_URI_ELEMENT_NAME
|
14
|
+
DEREF_URI_ELEMENT_NAME = 'derefUri'
|
13
15
|
|
14
|
-
DEREF_URI_XPATH
|
16
|
+
DEREF_URI_XPATH = "cap:#{DEREF_URI_ELEMENT_NAME}"
|
15
17
|
|
16
18
|
# @return [REXML::Element]
|
17
19
|
def to_xml_element
|
@@ -54,7 +56,7 @@ module RCAP
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
DEREF_URI_YAML
|
59
|
+
DEREF_URI_YAML = 'Derefrenced URI Data'
|
58
60
|
|
59
61
|
# @param [Hash] options
|
60
62
|
# @return [String]
|
@@ -65,7 +67,8 @@ module RCAP
|
|
65
67
|
[MIME_TYPE_YAML, @mime_type],
|
66
68
|
[DEREF_URI_YAML, @deref_uri],
|
67
69
|
[SIZE_YAML, @size],
|
68
|
-
[DIGEST_YAML, @digest]
|
70
|
+
[DIGEST_YAML, @digest]
|
71
|
+
).to_yaml(options)
|
69
72
|
end
|
70
73
|
|
71
74
|
# @param [Hash] resource_yaml_data
|
@@ -76,7 +79,7 @@ module RCAP
|
|
76
79
|
end
|
77
80
|
end
|
78
81
|
|
79
|
-
DEREF_URI_KEY
|
82
|
+
DEREF_URI_KEY = 'deref_uri'
|
80
83
|
|
81
84
|
# @return [Hash]
|
82
85
|
def to_h
|
data/lib/rcap/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Validation
|
2
4
|
module ClassMethods
|
3
5
|
CAP_NUMBER_REGEX = Regexp.new('^-{0,1}\d*\.{0,1}\d+$')
|
@@ -27,7 +29,7 @@ module Validation
|
|
27
29
|
}.merge!(attributes.extract_options!)
|
28
30
|
|
29
31
|
validates_each(*attributes) do |object, attribute, collection|
|
30
|
-
next if (
|
32
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
31
33
|
unless collection.all? { |member| options[:in].include?(member) }
|
32
34
|
object.errors[attribute] << options[:message]
|
33
35
|
end
|
@@ -40,7 +42,7 @@ module Validation
|
|
40
42
|
}.merge!(attributes.extract_options!)
|
41
43
|
|
42
44
|
validates_each(*attributes) do |object, attribute, collection|
|
43
|
-
next if (
|
45
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
44
46
|
unless options[:minimum] && collection.length >= options[:minimum]
|
45
47
|
object.errors[attribute] << options[:message]
|
46
48
|
end
|
@@ -54,9 +56,7 @@ module Validation
|
|
54
56
|
|
55
57
|
validates_each(*attributes) do |object, attribute, value|
|
56
58
|
next if value.nil? && options[:allow_nil]
|
57
|
-
|
58
|
-
object.errors[attribute] << options[:message]
|
59
|
-
end
|
59
|
+
object.errors[attribute] << options[:message] unless value&.valid?
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -66,8 +66,8 @@ module Validation
|
|
66
66
|
}.merge!(attributes.extract_options!)
|
67
67
|
|
68
68
|
validates_each(*attributes) do |object, attribute, collection|
|
69
|
-
next if (
|
70
|
-
unless collection.all?
|
69
|
+
next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
|
70
|
+
unless collection.all?(&:valid?)
|
71
71
|
object.errors[attribute] << options[:message]
|
72
72
|
end
|
73
73
|
end
|
@@ -107,16 +107,16 @@ module Validation
|
|
107
107
|
|
108
108
|
def validates_numericality_of(*attributes)
|
109
109
|
options = {
|
110
|
-
message: 'is not a number or does not meet a conditional requirement'
|
110
|
+
message: 'is not a number or does not meet a conditional requirement'
|
111
111
|
}.merge!(attributes.extract_options!)
|
112
112
|
|
113
113
|
re = options[:only_integer] ? CAP_INTEGER_REGEX : CAP_NUMBER_REGEX
|
114
114
|
|
115
115
|
validates_each(*attributes) do |object, attribute, value|
|
116
116
|
next if value.nil? && options[:allow_nil]
|
117
|
-
unless (
|
118
|
-
|
119
|
-
|
117
|
+
unless (value.to_s =~ re) &&
|
118
|
+
(options[:greater_than].nil? || value && value > options[:greater_than]) &&
|
119
|
+
(options[:greater_than_or_equal].nil? || value && value >= options[:greater_than_or_equal])
|
120
120
|
object.errors[attribute] << options[:message]
|
121
121
|
end
|
122
122
|
end
|
data/lib/rcap/extensions/date.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class DateTime
|
2
|
-
|
4
|
+
alias inspect to_s
|
3
5
|
|
4
6
|
# Returns a string representaion of the time suitable for CAP.
|
5
7
|
# @return [String]
|
@@ -15,6 +17,7 @@ class DateTime
|
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
20
|
+
|
18
21
|
def utc_hours_offset
|
19
22
|
offset * 24
|
20
23
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class String
|
2
4
|
CAP_LIST_REGEX = Regexp.new('"([\w\s]+)"|(\S+)')
|
3
5
|
WHITESPACE_REGEX = Regexp.new('^\s+$')
|
@@ -10,7 +12,7 @@ class String
|
|
10
12
|
# "one".for_cap_list # => "one"
|
11
13
|
# "two words".for_cap_list # => "\"two words\""
|
12
14
|
def for_cap_list
|
13
|
-
if
|
15
|
+
if /\s/.match?(self)
|
14
16
|
'"' + self + '"'
|
15
17
|
else
|
16
18
|
self
|