rcap 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rcap/alert.rb +28 -29
- data/lib/rcap/base/alert.rb +192 -192
- data/lib/rcap/base/area.rb +84 -86
- data/lib/rcap/base/circle.rb +32 -32
- data/lib/rcap/base/info.rb +248 -253
- data/lib/rcap/base/parameter.rb +23 -24
- data/lib/rcap/base/point.rb +23 -23
- data/lib/rcap/base/polygon.rb +32 -32
- data/lib/rcap/base/resource.rb +57 -57
- data/lib/rcap/cap_1_0/alert.rb +79 -83
- data/lib/rcap/cap_1_0/area.rb +0 -2
- data/lib/rcap/cap_1_0/circle.rb +0 -1
- data/lib/rcap/cap_1_0/info.rb +1 -3
- data/lib/rcap/cap_1_0/parameter.rb +11 -12
- data/lib/rcap/cap_1_0/point.rb +0 -1
- data/lib/rcap/cap_1_0/polygon.rb +0 -2
- data/lib/rcap/cap_1_0/resource.rb +0 -3
- data/lib/rcap/cap_1_1/alert.rb +4 -6
- data/lib/rcap/cap_1_1/area.rb +0 -2
- data/lib/rcap/cap_1_1/circle.rb +0 -1
- data/lib/rcap/cap_1_1/info.rb +120 -129
- data/lib/rcap/cap_1_1/parameter.rb +0 -2
- data/lib/rcap/cap_1_1/point.rb +0 -1
- data/lib/rcap/cap_1_1/polygon.rb +0 -2
- data/lib/rcap/cap_1_1/resource.rb +32 -34
- data/lib/rcap/cap_1_2/alert.rb +4 -6
- data/lib/rcap/cap_1_2/area.rb +0 -2
- data/lib/rcap/cap_1_2/circle.rb +0 -1
- data/lib/rcap/cap_1_2/info.rb +114 -121
- data/lib/rcap/cap_1_2/parameter.rb +0 -2
- data/lib/rcap/cap_1_2/point.rb +0 -1
- data/lib/rcap/cap_1_2/polygon.rb +1 -3
- data/lib/rcap/cap_1_2/resource.rb +32 -34
- data/lib/rcap/config.rb +3 -3
- data/lib/rcap/custom_validators.rb +72 -76
- data/lib/rcap/extensions/array.rb +1 -1
- data/lib/rcap/extensions/date.rb +2 -2
- data/lib/rcap/extensions/date_time.rb +3 -3
- data/lib/rcap/extensions/string.rb +3 -3
- data/lib/rcap/extensions/time.rb +2 -3
- data/lib/rcap/info.rb +4 -5
- data/lib/rcap/utilities.rb +24 -25
- data/lib/rcap/validation.rb +19 -20
- data/lib/rcap/version.rb +1 -1
- data/spec/alert_spec.rb +141 -141
- data/spec/cap_1_0/alert_spec.rb +92 -94
- data/spec/cap_1_0/area_spec.rb +86 -86
- data/spec/cap_1_0/circle_spec.rb +39 -39
- data/spec/cap_1_0/event_code_spec.rb +15 -15
- data/spec/cap_1_0/geocode_spec.rb +16 -16
- data/spec/cap_1_0/info_spec.rb +175 -177
- data/spec/cap_1_0/parameter_spec.rb +27 -27
- data/spec/cap_1_0/point_spec.rb +18 -18
- data/spec/cap_1_0/polygon_spec.rb +38 -38
- data/spec/cap_1_0/resource_spec.rb +63 -64
- data/spec/cap_1_1/alert_spec.rb +107 -109
- data/spec/cap_1_1/area_spec.rb +90 -90
- data/spec/cap_1_1/circle_spec.rb +34 -34
- data/spec/cap_1_1/event_code_spec.rb +15 -16
- data/spec/cap_1_1/geocode_spec.rb +16 -16
- data/spec/cap_1_1/info_spec.rb +194 -196
- data/spec/cap_1_1/parameter_spec.rb +17 -17
- data/spec/cap_1_1/point_spec.rb +18 -18
- data/spec/cap_1_1/polygon_spec.rb +36 -36
- data/spec/cap_1_1/resource_spec.rb +106 -107
- data/spec/cap_1_2/alert_spec.rb +98 -99
- data/spec/cap_1_2/area_spec.rb +90 -90
- data/spec/cap_1_2/circle_spec.rb +43 -43
- data/spec/cap_1_2/event_code_spec.rb +19 -20
- data/spec/cap_1_2/geocode_spec.rb +20 -20
- data/spec/cap_1_2/info_spec.rb +196 -198
- data/spec/cap_1_2/parameter_spec.rb +19 -19
- data/spec/cap_1_2/point_spec.rb +21 -21
- data/spec/cap_1_2/polygon_spec.rb +47 -47
- data/spec/cap_1_2/resource_spec.rb +96 -97
- data/spec/extensions_spec.rb +29 -29
- data/spec/info_spec.rb +15 -15
- data/spec/spec_helper.rb +3 -3
- data/spec/validations_spec.rb +73 -73
- metadata +2 -2
data/lib/rcap/extensions/time.rb
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
class Time
|
|
2
|
-
|
|
3
2
|
# Returns a string representaion of the time suitable for CAP.
|
|
4
3
|
# @return [String]
|
|
5
4
|
# @example
|
|
6
5
|
# Time.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
|
|
7
6
|
def to_s_for_cap
|
|
8
|
-
t =
|
|
7
|
+
t = strftime(RCAP::RCAP_TIME_FORMAT) + format(RCAP::RCAP_ZONE_FORMAT, utc_hours_offset)
|
|
9
8
|
t.sub(/\+(00:\d\d)$/, '-\1')
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
private
|
|
13
12
|
def utc_hours_offset
|
|
14
|
-
|
|
13
|
+
localtime.utc_offset / 3600
|
|
15
14
|
end
|
|
16
15
|
end
|
data/lib/rcap/info.rb
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
module RCAP
|
|
2
2
|
module Info
|
|
3
|
-
|
|
4
|
-
def self.from_h( alert, info_hash )
|
|
3
|
+
def self.from_h(alert, info_hash)
|
|
5
4
|
case alert.class::CAP_VERSION
|
|
6
5
|
when CAP_1_0::Alert::CAP_VERSION
|
|
7
|
-
CAP_1_0::Info.from_h(
|
|
6
|
+
CAP_1_0::Info.from_h(info_hash)
|
|
8
7
|
when CAP_1_1::Alert::CAP_VERSION
|
|
9
|
-
CAP_1_1::Info.from_h(
|
|
8
|
+
CAP_1_1::Info.from_h(info_hash)
|
|
10
9
|
else
|
|
11
|
-
CAP_1_2::Info.from_h(
|
|
10
|
+
CAP_1_2::Info.from_h(info_hash)
|
|
12
11
|
end
|
|
13
12
|
end
|
|
14
13
|
end
|
data/lib/rcap/utilities.rb
CHANGED
|
@@ -15,8 +15,8 @@ module RCAP
|
|
|
15
15
|
# @param [String] xpath XPath expression
|
|
16
16
|
# @param [String] namespace Namespace in which to do the matching
|
|
17
17
|
# @return [String,nil] Text content of element matching XPath query or nil
|
|
18
|
-
def self.xpath_text(
|
|
19
|
-
element =
|
|
18
|
+
def self.xpath_text(xml_element, xpath, namespace)
|
|
19
|
+
element = xpath_first(xml_element, xpath, namespace)
|
|
20
20
|
element.text.strip if element && element.text
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -26,8 +26,8 @@ module RCAP
|
|
|
26
26
|
# @param [String] xpath XPath expression
|
|
27
27
|
# @param [String] namespace Namespace in which to do the matching
|
|
28
28
|
# @return [REXML::Element,nil] Element matching XPath query or nil
|
|
29
|
-
def self.xpath_first(
|
|
30
|
-
REXML::XPath.first(
|
|
29
|
+
def self.xpath_first(xml_element, xpath, namespace)
|
|
30
|
+
REXML::XPath.first(xml_element, xpath, 'cap' => namespace)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Returns all descendents that match the given XPath expression.
|
|
@@ -36,8 +36,8 @@ module RCAP
|
|
|
36
36
|
# @param [String] xpath XPath expression
|
|
37
37
|
# @param [String] namespace Namespace in which to do the matching
|
|
38
38
|
# @return [Array<REXML::Element>] Collection of elements matching XPath query
|
|
39
|
-
def self.xpath_match(
|
|
40
|
-
REXML::XPath.match(
|
|
39
|
+
def self.xpath_match(xml_element, xpath, namespace)
|
|
40
|
+
REXML::XPath.match(xml_element, xpath, 'cap' => namespace)
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
# Formats output for inspect
|
|
@@ -56,13 +56,12 @@ module RCAP
|
|
|
56
56
|
# # | two |
|
|
57
57
|
# # | three |
|
|
58
58
|
# # '-------'
|
|
59
|
-
def self.format_lines_for_inspect(
|
|
60
|
-
max_line_length = inspect_string.lines.map{ |line| line.strip.length }.max
|
|
61
|
-
"\n." + '-' * (max_line_length + 2) + ".\n"
|
|
62
|
-
'| ' + header.ljust(
|
|
63
|
-
'|' + '-' * ( max_line_length + 2
|
|
64
|
-
|
|
65
|
-
"'" + '-' * ( max_line_length + 2 ) + "'\n"
|
|
59
|
+
def self.format_lines_for_inspect(header, inspect_string)
|
|
60
|
+
max_line_length = inspect_string.lines.map { |line| line.strip.length }.max
|
|
61
|
+
"\n." + '-' * (max_line_length + 2) + ".\n"\
|
|
62
|
+
'| ' + header.ljust(max_line_length) + " |\n"\
|
|
63
|
+
'|' + '-' * ( max_line_length + 2) + "|\n" + inspect_string.lines.map { |line| '| ' + line.strip.ljust(max_line_length) + ' |' }.join("\n") + "\n" \
|
|
64
|
+
"'" + '-' * ( max_line_length + 2) + "'\n"
|
|
66
65
|
end
|
|
67
66
|
|
|
68
67
|
# Converts an array of key value pairs into a hash, excluding any value that is nil.
|
|
@@ -72,17 +71,17 @@ module RCAP
|
|
|
72
71
|
#
|
|
73
72
|
# @example
|
|
74
73
|
# RCAP.attribute_values_to_hash( ['a', 1], ['b' , nil ]) # => { 'a' => 1 }
|
|
75
|
-
def self.attribute_values_to_hash(
|
|
76
|
-
Hash[
|
|
74
|
+
def self.attribute_values_to_hash(*attribute_values)
|
|
75
|
+
Hash[*attribute_values.reject { |_key, value| value.nil? }.flatten(1)]
|
|
77
76
|
end
|
|
78
77
|
|
|
79
78
|
# Calls #to_s_for_cap on the object it it responds to that otherwise just calls #to_s
|
|
80
79
|
#
|
|
81
80
|
# @param [#to_s, #to_s_for_cap] object
|
|
82
81
|
# @return [String]
|
|
83
|
-
def self.to_s_for_cap(
|
|
82
|
+
def self.to_s_for_cap(object)
|
|
84
83
|
if object
|
|
85
|
-
if object.respond_to?(
|
|
84
|
+
if object.respond_to?(:to_s_for_cap)
|
|
86
85
|
object.to_s_for_cap
|
|
87
86
|
else
|
|
88
87
|
object.to_s
|
|
@@ -94,11 +93,11 @@ module RCAP
|
|
|
94
93
|
#
|
|
95
94
|
# @param [String] date String to parse
|
|
96
95
|
# @return [String,nil]
|
|
97
|
-
def self.parse_datetime(
|
|
96
|
+
def self.parse_datetime(date)
|
|
98
97
|
case date
|
|
99
98
|
when String
|
|
100
|
-
|
|
101
|
-
DateTime.parse(
|
|
99
|
+
unless date.empty?
|
|
100
|
+
DateTime.parse(date.strip)
|
|
102
101
|
end
|
|
103
102
|
when DateTime, Time, Date
|
|
104
103
|
date.to_datetime
|
|
@@ -110,7 +109,7 @@ module RCAP
|
|
|
110
109
|
#
|
|
111
110
|
# @param [String] list List to split
|
|
112
111
|
# @return [Array]
|
|
113
|
-
def
|
|
112
|
+
def self.unpack_if_given(list)
|
|
114
113
|
if list
|
|
115
114
|
list.unpack_cap_list
|
|
116
115
|
else
|
|
@@ -122,7 +121,7 @@ module RCAP
|
|
|
122
121
|
#
|
|
123
122
|
# @param [String] string
|
|
124
123
|
# @return [String,nil]
|
|
125
|
-
def
|
|
124
|
+
def self.strip_if_given(string)
|
|
126
125
|
if string
|
|
127
126
|
string.strip
|
|
128
127
|
end
|
|
@@ -133,7 +132,7 @@ module RCAP
|
|
|
133
132
|
#
|
|
134
133
|
# @param [String] number
|
|
135
134
|
# @return [Float,nil]
|
|
136
|
-
def
|
|
135
|
+
def self.to_f_if_given(number)
|
|
137
136
|
if number
|
|
138
137
|
case number
|
|
139
138
|
when String
|
|
@@ -145,13 +144,13 @@ module RCAP
|
|
|
145
144
|
end
|
|
146
145
|
end
|
|
147
146
|
end
|
|
148
|
-
|
|
147
|
+
|
|
149
148
|
# if the string is given, String#strip and then String#to_i are applied
|
|
150
149
|
# otherwise nil is returned.
|
|
151
150
|
#
|
|
152
151
|
# @param [String] number
|
|
153
152
|
# @return [Integer,nil]
|
|
154
|
-
def
|
|
153
|
+
def self.to_i_if_given(number)
|
|
155
154
|
if number
|
|
156
155
|
case number
|
|
157
156
|
when String
|
data/lib/rcap/validation.rb
CHANGED
|
@@ -45,7 +45,7 @@ module Validation
|
|
|
45
45
|
class Errors
|
|
46
46
|
# Initializes a new instance of validation errors.
|
|
47
47
|
def initialize
|
|
48
|
-
@errors = Hash.new {|h, k| h[k] = []}
|
|
48
|
+
@errors = Hash.new { |h, k| h[k] = [] }
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Returns true if no errors are stored.
|
|
@@ -71,9 +71,9 @@ module Validation
|
|
|
71
71
|
|
|
72
72
|
# Returns an array of fully-formatted error messages.
|
|
73
73
|
def full_messages
|
|
74
|
-
@errors.
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
@errors.reduce([]) do |m, kv| att, errors = *kv
|
|
75
|
+
errors.each { |e| m << "#{att} #{e}" }
|
|
76
|
+
m
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
end
|
|
@@ -82,7 +82,7 @@ module Validation
|
|
|
82
82
|
# the validates {} idiom.
|
|
83
83
|
class Generator
|
|
84
84
|
# Initializes a new generator.
|
|
85
|
-
def initialize(receiver
|
|
85
|
+
def initialize(receiver, &block)
|
|
86
86
|
@receiver = receiver
|
|
87
87
|
instance_eval(&block)
|
|
88
88
|
end
|
|
@@ -118,7 +118,7 @@ module Validation
|
|
|
118
118
|
|
|
119
119
|
# Returns the validations hash for the class.
|
|
120
120
|
def validations
|
|
121
|
-
@validations ||= Hash.new {|h, k| h[k] = []}
|
|
121
|
+
@validations ||= Hash.new { |h, k| h[k] = [] }
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
# Returns true if validations are defined.
|
|
@@ -133,7 +133,7 @@ module Validation
|
|
|
133
133
|
end
|
|
134
134
|
validations.each do |att, procs|
|
|
135
135
|
v = o.send(att)
|
|
136
|
-
procs.each {|p| p[o, att, v]}
|
|
136
|
+
procs.each { |p| p[o, att, v] }
|
|
137
137
|
end
|
|
138
138
|
end
|
|
139
139
|
|
|
@@ -149,15 +149,15 @@ module Validation
|
|
|
149
149
|
# object.errors[attribute] << 'is not nice' unless value.nice?
|
|
150
150
|
# end
|
|
151
151
|
def validates_each(*atts, &block)
|
|
152
|
-
atts.each {|a| validations[a] << block}
|
|
152
|
+
atts.each { |a| validations[a] << block }
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
# Validates acceptance of an attribute.
|
|
156
156
|
def validates_acceptance_of(*atts)
|
|
157
157
|
opts = {
|
|
158
|
-
:
|
|
159
|
-
:
|
|
160
|
-
:
|
|
158
|
+
message: 'is not accepted',
|
|
159
|
+
allow_nil: true,
|
|
160
|
+
accept: '1'
|
|
161
161
|
}.merge!(atts.extract_options!)
|
|
162
162
|
|
|
163
163
|
validates_each(*atts) do |o, a, v|
|
|
@@ -169,7 +169,7 @@ module Validation
|
|
|
169
169
|
# Validates confirmation of an attribute.
|
|
170
170
|
def validates_confirmation_of(*atts)
|
|
171
171
|
opts = {
|
|
172
|
-
:
|
|
172
|
+
message: 'is not confirmed',
|
|
173
173
|
}.merge!(atts.extract_options!)
|
|
174
174
|
|
|
175
175
|
validates_each(*atts) do |o, a, v|
|
|
@@ -182,11 +182,11 @@ module Validation
|
|
|
182
182
|
# Validates the format of an attribute.
|
|
183
183
|
def validates_format_of(*atts)
|
|
184
184
|
opts = {
|
|
185
|
-
:
|
|
185
|
+
message: 'is invalid',
|
|
186
186
|
}.merge!(atts.extract_options!)
|
|
187
187
|
|
|
188
188
|
unless opts[:with].is_a?(Regexp)
|
|
189
|
-
|
|
189
|
+
fail ArgumentError, 'A regular expression must be supplied as the :with option of the options hash'
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
validates_each(*atts) do |o, a, v|
|
|
@@ -198,9 +198,9 @@ module Validation
|
|
|
198
198
|
# Validates the length of an attribute.
|
|
199
199
|
def validates_length_of(*atts)
|
|
200
200
|
opts = {
|
|
201
|
-
:
|
|
202
|
-
:
|
|
203
|
-
:
|
|
201
|
+
too_long: 'is too long',
|
|
202
|
+
too_short: 'is too short',
|
|
203
|
+
wrong_length: 'is the wrong length'
|
|
204
204
|
}.merge!(atts.extract_options!)
|
|
205
205
|
|
|
206
206
|
validates_each(*atts) do |o, a, v|
|
|
@@ -226,7 +226,7 @@ module Validation
|
|
|
226
226
|
# Validates whether an attribute is a number.
|
|
227
227
|
def validates_numericality_of(*atts)
|
|
228
228
|
opts = {
|
|
229
|
-
:
|
|
229
|
+
message: 'is not a number',
|
|
230
230
|
}.merge!(atts.extract_options!)
|
|
231
231
|
|
|
232
232
|
re = opts[:only_integer] ? INTEGER_RE : NUMBER_RE
|
|
@@ -240,7 +240,7 @@ module Validation
|
|
|
240
240
|
# Validates the presence of an attribute.
|
|
241
241
|
def validates_presence_of(*atts)
|
|
242
242
|
opts = {
|
|
243
|
-
:
|
|
243
|
+
message: 'is not present',
|
|
244
244
|
}.merge!(atts.extract_options!)
|
|
245
245
|
|
|
246
246
|
validates_each(*atts) do |o, a, v|
|
|
@@ -249,4 +249,3 @@ module Validation
|
|
|
249
249
|
end
|
|
250
250
|
end
|
|
251
251
|
end
|
|
252
|
-
|
data/lib/rcap/version.rb
CHANGED
data/spec/alert_spec.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe(
|
|
4
|
-
describe(
|
|
3
|
+
describe(RCAP::Alert) do
|
|
4
|
+
describe('initialising') do
|
|
5
5
|
|
|
6
|
-
context(
|
|
7
|
-
before(
|
|
6
|
+
context('a CAP 1.0 alert') do
|
|
7
|
+
before(:each) do
|
|
8
8
|
@original_alert = RCAP::CAP_1_0::Alert.new do |alert|
|
|
9
9
|
alert.sender = 'Sender'
|
|
10
10
|
alert.sent = DateTime.now
|
|
@@ -12,71 +12,71 @@ describe( RCAP::Alert ) do
|
|
|
12
12
|
alert.scope = RCAP::CAP_1_0::Alert::SCOPE_PUBLIC
|
|
13
13
|
alert.source = 'Source'
|
|
14
14
|
alert.restriction = 'No Restriction'
|
|
15
|
-
[
|
|
15
|
+
['Address 1', 'Address 2'].each do |address|
|
|
16
16
|
alert.addresses << address
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
%w(Code1 Code2).each do |code|
|
|
19
19
|
alert.codes << code
|
|
20
20
|
end
|
|
21
21
|
alert.note = 'Note'
|
|
22
|
-
[
|
|
22
|
+
['1.0,1', '1.0,2'].each do |reference|
|
|
23
23
|
alert.references << reference
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
%w(Incident1 Incident2).each do |incident|
|
|
26
26
|
alert.incidents << incident
|
|
27
27
|
end
|
|
28
|
-
2.times{ alert.add_info }
|
|
28
|
+
2.times { alert.add_info }
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
shared_examples_for(
|
|
33
|
-
it(
|
|
34
|
-
it(
|
|
35
|
-
it(
|
|
36
|
-
it(
|
|
37
|
-
it(
|
|
38
|
-
it(
|
|
39
|
-
it(
|
|
40
|
-
it(
|
|
41
|
-
it(
|
|
42
|
-
it(
|
|
43
|
-
it(
|
|
44
|
-
it(
|
|
45
|
-
it(
|
|
46
|
-
it(
|
|
47
|
-
it(
|
|
32
|
+
shared_examples_for('it has parsed a CAP 1.0 alert correctly') do
|
|
33
|
+
it('should use the correct CAP Version') { @alert.class.should == RCAP::CAP_1_0::Alert }
|
|
34
|
+
it('should parse identifier correctly') { @alert.identifier.should == @original_alert.identifier }
|
|
35
|
+
it('should parse sender correctly') { @alert.sender.should == @original_alert.sender }
|
|
36
|
+
it('should parse sent correctly') { @alert.sent.should(be_within(1).of(@original_alert.sent)) }
|
|
37
|
+
it('should parse status correctly') { @alert.status.should == @original_alert.status }
|
|
38
|
+
it('should parse msg_type correctly') { @alert.msg_type.should == @original_alert.msg_type }
|
|
39
|
+
it('should parse source correctly') { @alert.source.should == @original_alert.source }
|
|
40
|
+
it('should parse scope correctly') { @alert.scope.should == @original_alert.scope }
|
|
41
|
+
it('should parse restriction correctly') { @alert.restriction.should == @original_alert.restriction }
|
|
42
|
+
it('should parse addresses correctly') { @alert.addresses.should == @original_alert.addresses }
|
|
43
|
+
it('should parse code correctly') { @alert.codes.should == @original_alert.codes }
|
|
44
|
+
it('should parse note correctly') { @alert.note.should == @original_alert.note }
|
|
45
|
+
it('should parse references correctly') { @alert.references.should == @original_alert.references }
|
|
46
|
+
it('should parse incidents correctly') { @alert.incidents.should == @original_alert.incidents }
|
|
47
|
+
it('should parse infos correctly') do
|
|
48
48
|
@alert.infos.size.should == @original_alert.infos.size
|
|
49
|
-
@alert.infos.each{ |info| info.class.should == RCAP::CAP_1_0::Info }
|
|
49
|
+
@alert.infos.each { |info| info.class.should == RCAP::CAP_1_0::Info }
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
context(
|
|
54
|
-
before(
|
|
55
|
-
@alert = RCAP::Alert.from_xml(
|
|
53
|
+
context('from XML') do
|
|
54
|
+
before(:each) do
|
|
55
|
+
@alert = RCAP::Alert.from_xml(@original_alert.to_xml)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
it_should_behave_like(
|
|
58
|
+
it_should_behave_like('it has parsed a CAP 1.0 alert correctly')
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
context(
|
|
62
|
-
before(
|
|
63
|
-
@alert = RCAP::Alert.from_yaml(
|
|
61
|
+
context('from YAML') do
|
|
62
|
+
before(:each) do
|
|
63
|
+
@alert = RCAP::Alert.from_yaml(@original_alert.to_yaml)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
it_should_behave_like(
|
|
66
|
+
it_should_behave_like('it has parsed a CAP 1.0 alert correctly')
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
context(
|
|
70
|
-
before(
|
|
71
|
-
@alert = RCAP::Alert.from_json(
|
|
69
|
+
context('from JSON') do
|
|
70
|
+
before(:each) do
|
|
71
|
+
@alert = RCAP::Alert.from_json(@original_alert.to_json)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
it_should_behave_like(
|
|
74
|
+
it_should_behave_like('it has parsed a CAP 1.0 alert correctly')
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
context(
|
|
79
|
-
before(
|
|
78
|
+
context('a CAP 1.1 alert') do
|
|
79
|
+
before(:each) do
|
|
80
80
|
@original_alert = RCAP::CAP_1_1::Alert.new do |alert|
|
|
81
81
|
alert.sender = 'Sender'
|
|
82
82
|
alert.sent = DateTime.now
|
|
@@ -84,71 +84,71 @@ describe( RCAP::Alert ) do
|
|
|
84
84
|
alert.scope = RCAP::CAP_1_1::Alert::SCOPE_PUBLIC
|
|
85
85
|
alert.source = 'Source'
|
|
86
86
|
alert.restriction = 'No Restriction'
|
|
87
|
-
[
|
|
87
|
+
['Address 1', 'Address 2'].each do |address|
|
|
88
88
|
alert.addresses << address
|
|
89
89
|
end
|
|
90
|
-
|
|
90
|
+
%w(Code1 Code2).each do |code|
|
|
91
91
|
alert.codes << code
|
|
92
92
|
end
|
|
93
93
|
alert.note = 'Note'
|
|
94
|
-
[
|
|
94
|
+
['1,1,1', '1,1,2'].each do |reference|
|
|
95
95
|
alert.references << reference
|
|
96
96
|
end
|
|
97
|
-
|
|
97
|
+
%w(Incident1 Incident2).each do |incident|
|
|
98
98
|
alert.incidents << incident
|
|
99
99
|
end
|
|
100
|
-
2.times{ alert.add_info }
|
|
100
|
+
2.times { alert.add_info }
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
shared_examples_for(
|
|
105
|
-
it(
|
|
106
|
-
it(
|
|
107
|
-
it(
|
|
108
|
-
it(
|
|
109
|
-
it(
|
|
110
|
-
it(
|
|
111
|
-
it(
|
|
112
|
-
it(
|
|
113
|
-
it(
|
|
114
|
-
it(
|
|
115
|
-
it(
|
|
116
|
-
it(
|
|
117
|
-
it(
|
|
118
|
-
it(
|
|
119
|
-
it(
|
|
104
|
+
shared_examples_for('it has parsed a CAP 1.1 alert correctly') do
|
|
105
|
+
it('should use the correct CAP Version') { @alert.class.should == RCAP::CAP_1_1::Alert }
|
|
106
|
+
it('should parse identifier correctly') { @alert.identifier.should == @original_alert.identifier }
|
|
107
|
+
it('should parse sender correctly') { @alert.sender.should == @original_alert.sender }
|
|
108
|
+
it('should parse sent correctly') { @alert.sent.should(be_within(1).of(@original_alert.sent)) }
|
|
109
|
+
it('should parse status correctly') { @alert.status.should == @original_alert.status }
|
|
110
|
+
it('should parse msg_type correctly') { @alert.msg_type.should == @original_alert.msg_type }
|
|
111
|
+
it('should parse source correctly') { @alert.source.should == @original_alert.source }
|
|
112
|
+
it('should parse scope correctly') { @alert.scope.should == @original_alert.scope }
|
|
113
|
+
it('should parse restriction correctly') { @alert.restriction.should == @original_alert.restriction }
|
|
114
|
+
it('should parse addresses correctly') { @alert.addresses.should == @original_alert.addresses }
|
|
115
|
+
it('should parse code correctly') { @alert.codes.should == @original_alert.codes }
|
|
116
|
+
it('should parse note correctly') { @alert.note.should == @original_alert.note }
|
|
117
|
+
it('should parse references correctly') { @alert.references.should == @original_alert.references }
|
|
118
|
+
it('should parse incidents correctly') { @alert.incidents.should == @original_alert.incidents }
|
|
119
|
+
it('should parse infos correctly') do
|
|
120
120
|
@alert.infos.size.should == @original_alert.infos.size
|
|
121
|
-
@alert.infos.each{ |info| info.class.should == RCAP::CAP_1_1::Info }
|
|
121
|
+
@alert.infos.each { |info| info.class.should == RCAP::CAP_1_1::Info }
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
context(
|
|
126
|
-
before(
|
|
127
|
-
@alert = RCAP::Alert.from_xml(
|
|
125
|
+
context('from XML') do
|
|
126
|
+
before(:each) do
|
|
127
|
+
@alert = RCAP::Alert.from_xml(@original_alert.to_xml)
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
it_should_behave_like(
|
|
130
|
+
it_should_behave_like('it has parsed a CAP 1.1 alert correctly')
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
context(
|
|
134
|
-
before(
|
|
135
|
-
@alert = RCAP::Alert.from_yaml(
|
|
133
|
+
context('from YAML') do
|
|
134
|
+
before(:each) do
|
|
135
|
+
@alert = RCAP::Alert.from_yaml(@original_alert.to_yaml)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
-
it_should_behave_like(
|
|
138
|
+
it_should_behave_like('it has parsed a CAP 1.1 alert correctly')
|
|
139
139
|
end
|
|
140
140
|
|
|
141
|
-
context(
|
|
142
|
-
before(
|
|
143
|
-
@alert = RCAP::Alert.from_json(
|
|
141
|
+
context('from JSON') do
|
|
142
|
+
before(:each) do
|
|
143
|
+
@alert = RCAP::Alert.from_json(@original_alert.to_json)
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
it_should_behave_like(
|
|
146
|
+
it_should_behave_like('it has parsed a CAP 1.1 alert correctly')
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
149
|
|
|
150
|
-
context(
|
|
151
|
-
before(
|
|
150
|
+
context('a CAP 1.2 alert') do
|
|
151
|
+
before(:each) do
|
|
152
152
|
@original_alert = RCAP::CAP_1_2::Alert.new do |alert|
|
|
153
153
|
alert.sender = 'Sender'
|
|
154
154
|
alert.sent = DateTime.now
|
|
@@ -156,108 +156,108 @@ describe( RCAP::Alert ) do
|
|
|
156
156
|
alert.scope = RCAP::CAP_1_2::Alert::SCOPE_PUBLIC
|
|
157
157
|
alert.source = 'Source'
|
|
158
158
|
alert.restriction = 'No Restriction'
|
|
159
|
-
[
|
|
159
|
+
['Address 1', 'Address 2'].each do |address|
|
|
160
160
|
alert.addresses << address
|
|
161
161
|
end
|
|
162
|
-
|
|
162
|
+
%w(Code1 Code2).each do |code|
|
|
163
163
|
alert.codes << code
|
|
164
164
|
end
|
|
165
165
|
alert.note = 'Note'
|
|
166
|
-
[
|
|
166
|
+
['1,1,1', '1,1,2'].each do |reference|
|
|
167
167
|
alert.references << reference
|
|
168
168
|
end
|
|
169
|
-
|
|
169
|
+
%w(Incident1 Incident2).each do |incident|
|
|
170
170
|
alert.incidents << incident
|
|
171
171
|
end
|
|
172
|
-
2.times{ alert.add_info }
|
|
172
|
+
2.times { alert.add_info }
|
|
173
173
|
end
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
shared_examples_for(
|
|
177
|
-
it(
|
|
178
|
-
it(
|
|
179
|
-
it(
|
|
180
|
-
it(
|
|
181
|
-
it(
|
|
182
|
-
it(
|
|
183
|
-
it(
|
|
184
|
-
it(
|
|
185
|
-
it(
|
|
186
|
-
it(
|
|
187
|
-
it(
|
|
188
|
-
it(
|
|
189
|
-
it(
|
|
190
|
-
it(
|
|
191
|
-
it(
|
|
176
|
+
shared_examples_for('it has parsed a CAP 1.2 alert correctly') do
|
|
177
|
+
it('should use the correct CAP Version') { @alert.class.should == RCAP::CAP_1_2::Alert }
|
|
178
|
+
it('should parse identifier correctly') { @alert.identifier.should == @original_alert.identifier }
|
|
179
|
+
it('should parse sender correctly') { @alert.sender.should == @original_alert.sender }
|
|
180
|
+
it('should parse sent correctly') { @alert.sent.should(be_within(1).of(@original_alert.sent)) }
|
|
181
|
+
it('should parse status correctly') { @alert.status.should == @original_alert.status }
|
|
182
|
+
it('should parse msg_type correctly') { @alert.msg_type.should == @original_alert.msg_type }
|
|
183
|
+
it('should parse source correctly') { @alert.source.should == @original_alert.source }
|
|
184
|
+
it('should parse scope correctly') { @alert.scope.should == @original_alert.scope }
|
|
185
|
+
it('should parse restriction correctly') { @alert.restriction.should == @original_alert.restriction }
|
|
186
|
+
it('should parse addresses correctly') { @alert.addresses.should == @original_alert.addresses }
|
|
187
|
+
it('should parse codes correctly') { @alert.codes.should == @original_alert.codes }
|
|
188
|
+
it('should parse note correctly') { @alert.note.should == @original_alert.note }
|
|
189
|
+
it('should parse references correctly') { @alert.references.should == @original_alert.references }
|
|
190
|
+
it('should parse incidents correctly') { @alert.incidents.should == @original_alert.incidents }
|
|
191
|
+
it('should parse infos correctly') do
|
|
192
192
|
@alert.infos.size.should == @original_alert.infos.size
|
|
193
|
-
@alert.infos.each{ |info| info.class.should == RCAP::CAP_1_2::Info }
|
|
193
|
+
@alert.infos.each { |info| info.class.should == RCAP::CAP_1_2::Info }
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
196
|
|
|
197
|
-
context(
|
|
198
|
-
before(
|
|
199
|
-
@alert = RCAP::Alert.from_xml(
|
|
197
|
+
context('from XML') do
|
|
198
|
+
before(:each) do
|
|
199
|
+
@alert = RCAP::Alert.from_xml(@original_alert.to_xml)
|
|
200
200
|
end
|
|
201
201
|
|
|
202
|
-
it_should_behave_like(
|
|
202
|
+
it_should_behave_like('it has parsed a CAP 1.2 alert correctly')
|
|
203
203
|
end
|
|
204
204
|
|
|
205
|
-
context(
|
|
206
|
-
before(
|
|
207
|
-
@alert = RCAP::Alert.from_yaml(
|
|
205
|
+
context('from YAML') do
|
|
206
|
+
before(:each) do
|
|
207
|
+
@alert = RCAP::Alert.from_yaml(@original_alert.to_yaml)
|
|
208
208
|
end
|
|
209
209
|
|
|
210
|
-
it_should_behave_like(
|
|
210
|
+
it_should_behave_like('it has parsed a CAP 1.2 alert correctly')
|
|
211
211
|
end
|
|
212
212
|
|
|
213
|
-
context(
|
|
214
|
-
before(
|
|
215
|
-
@alert = RCAP::Alert.from_json(
|
|
213
|
+
context('from JSON') do
|
|
214
|
+
before(:each) do
|
|
215
|
+
@alert = RCAP::Alert.from_json(@original_alert.to_json)
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
-
it_should_behave_like(
|
|
218
|
+
it_should_behave_like('it has parsed a CAP 1.2 alert correctly')
|
|
219
219
|
end
|
|
220
220
|
end
|
|
221
221
|
end
|
|
222
222
|
|
|
223
|
-
describe(
|
|
224
|
-
def load_file(
|
|
225
|
-
File.open(
|
|
223
|
+
describe('external file') do
|
|
224
|
+
def load_file(file_name)
|
|
225
|
+
File.open(File.join(File.dirname(__FILE__), 'assets', file_name)) { |f| f.read }
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
-
describe(
|
|
229
|
-
before(
|
|
230
|
-
@alert = RCAP::Alert.from_xml(
|
|
228
|
+
describe("'invalid.cap'") do
|
|
229
|
+
before(:each) do
|
|
230
|
+
@alert = RCAP::Alert.from_xml(load_file('invalid.cap'))
|
|
231
231
|
end
|
|
232
232
|
|
|
233
|
-
it(
|
|
234
|
-
@alert.should_not(
|
|
233
|
+
it('should not be valid') do
|
|
234
|
+
@alert.should_not(be_valid)
|
|
235
235
|
end
|
|
236
236
|
|
|
237
|
-
it(
|
|
237
|
+
it('should be invalid because scope is missing') do
|
|
238
238
|
@alert.valid?
|
|
239
|
-
@alert.errors.on(
|
|
239
|
+
@alert.errors.on(:scope).should_not(be_empty)
|
|
240
240
|
end
|
|
241
241
|
end
|
|
242
242
|
|
|
243
|
-
describe(
|
|
244
|
-
before(
|
|
245
|
-
@alert = RCAP::Alert.from_xml(
|
|
243
|
+
describe("'earthquake.cap'") do
|
|
244
|
+
before(:each) do
|
|
245
|
+
@alert = RCAP::Alert.from_xml(load_file('earthquake.cap'))
|
|
246
246
|
end
|
|
247
247
|
|
|
248
|
-
it(
|
|
249
|
-
@alert.should(
|
|
248
|
+
it('should be valid') do
|
|
249
|
+
@alert.should(be_valid)
|
|
250
250
|
end
|
|
251
251
|
|
|
252
|
-
it(
|
|
253
|
-
@alert.class.should
|
|
254
|
-
@alert.status.should
|
|
252
|
+
it('should parse the alert correctly') do
|
|
253
|
+
@alert.class.should == RCAP::CAP_1_1::Alert
|
|
254
|
+
@alert.status.should == RCAP::CAP_1_1::Alert::STATUS_ACTUAL
|
|
255
255
|
@alert.msg_type.should == RCAP::CAP_1_1::Alert::MSG_TYPE_ALERT
|
|
256
|
-
@alert.scope.should
|
|
256
|
+
@alert.scope.should == RCAP::CAP_1_1::Alert::SCOPE_PUBLIC
|
|
257
257
|
|
|
258
258
|
@alert.infos.size.should == 2
|
|
259
259
|
info = @alert.infos.first
|
|
260
|
-
info.categories.include?(
|
|
260
|
+
info.categories.include?(RCAP::CAP_1_1::Info::CATEGORY_GEO).should eq true
|
|
261
261
|
|
|
262
262
|
info.areas.size.should == 1
|
|
263
263
|
area = info.areas.first
|
|
@@ -270,21 +270,21 @@ describe( RCAP::Alert ) do
|
|
|
270
270
|
end
|
|
271
271
|
end
|
|
272
272
|
|
|
273
|
-
describe(
|
|
274
|
-
before(
|
|
275
|
-
@alert = RCAP::Alert.from_xml(
|
|
273
|
+
describe("'canada.cap'") do
|
|
274
|
+
before(:each) do
|
|
275
|
+
@alert = RCAP::Alert.from_xml(load_file('canada.cap'))
|
|
276
276
|
end
|
|
277
277
|
|
|
278
|
-
it(
|
|
279
|
-
@alert.should(
|
|
278
|
+
it('should be valid') do
|
|
279
|
+
@alert.should(be_valid)
|
|
280
280
|
end
|
|
281
281
|
|
|
282
|
-
it(
|
|
283
|
-
@alert.class.should
|
|
284
|
-
@alert.status.should
|
|
285
|
-
@alert.msg_type.should
|
|
286
|
-
@alert.scope.should
|
|
287
|
-
@alert.identifier.should ==
|
|
282
|
+
it('should parse the alert correctly') do
|
|
283
|
+
@alert.class.should == RCAP::CAP_1_1::Alert
|
|
284
|
+
@alert.status.should == RCAP::CAP_1_1::Alert::STATUS_ACTUAL
|
|
285
|
+
@alert.msg_type.should == RCAP::CAP_1_1::Alert::MSG_TYPE_UPDATE
|
|
286
|
+
@alert.scope.should == RCAP::CAP_1_1::Alert::SCOPE_PUBLIC
|
|
287
|
+
@alert.identifier.should == 'CA-EC-CWTO-2011-138776'
|
|
288
288
|
|
|
289
289
|
@alert.infos.size.should == 2
|
|
290
290
|
info = @alert.infos.first
|