rcap 2.4.1 → 2.7.3
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 +5 -5
- data/.ruby-version +1 -0
- data/CHANGELOG.md +18 -0
- data/README.md +1 -0
- data/lib/rcap.rb +3 -1
- data/lib/rcap/alert.rb +30 -29
- data/lib/rcap/base/alert.rb +208 -205
- data/lib/rcap/base/area.rb +95 -91
- data/lib/rcap/base/circle.rb +45 -34
- data/lib/rcap/base/event_code.rb +2 -0
- data/lib/rcap/base/geocode.rb +2 -0
- data/lib/rcap/base/info.rb +273 -272
- data/lib/rcap/base/parameter.rb +29 -28
- data/lib/rcap/base/point.rb +26 -24
- data/lib/rcap/base/polygon.rb +43 -35
- data/lib/rcap/base/resource.rb +65 -65
- data/lib/rcap/cap_1_0/alert.rb +85 -86
- data/lib/rcap/cap_1_0/area.rb +2 -2
- data/lib/rcap/cap_1_0/circle.rb +2 -1
- 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 -3
- data/lib/rcap/cap_1_0/parameter.rb +13 -13
- data/lib/rcap/cap_1_0/point.rb +2 -1
- data/lib/rcap/cap_1_0/polygon.rb +3 -3
- data/lib/rcap/cap_1_0/resource.rb +2 -3
- data/lib/rcap/cap_1_1/alert.rb +6 -6
- data/lib/rcap/cap_1_1/area.rb +2 -2
- data/lib/rcap/cap_1_1/circle.rb +2 -1
- 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 +125 -132
- data/lib/rcap/cap_1_1/parameter.rb +2 -3
- data/lib/rcap/cap_1_1/point.rb +2 -1
- data/lib/rcap/cap_1_1/polygon.rb +3 -3
- data/lib/rcap/cap_1_1/resource.rb +37 -38
- data/lib/rcap/cap_1_2/alert.rb +6 -6
- data/lib/rcap/cap_1_2/area.rb +2 -2
- data/lib/rcap/cap_1_2/circle.rb +2 -1
- 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 +120 -123
- data/lib/rcap/cap_1_2/parameter.rb +2 -3
- data/lib/rcap/cap_1_2/point.rb +2 -1
- data/lib/rcap/cap_1_2/polygon.rb +4 -4
- data/lib/rcap/cap_1_2/resource.rb +38 -38
- data/lib/rcap/config.rb +5 -3
- data/lib/rcap/custom_validators.rb +75 -78
- data/lib/rcap/extensions/array.rb +3 -1
- data/lib/rcap/extensions/date.rb +3 -1
- data/lib/rcap/extensions/date_time.rb +5 -2
- data/lib/rcap/extensions/float.rb +2 -0
- data/lib/rcap/extensions/integer.rb +7 -0
- data/lib/rcap/extensions/nil_class.rb +2 -0
- data/lib/rcap/extensions/string.rb +6 -4
- data/lib/rcap/extensions/time.rb +5 -3
- data/lib/rcap/formatters/yaml.rb +5 -0
- data/lib/rcap/info.rb +6 -5
- data/lib/rcap/utilities.rb +27 -30
- data/lib/rcap/validation.rb +22 -21
- data/lib/rcap/version.rb +3 -1
- data/rcap.gemspec +5 -5
- 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 +48 -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 +43 -41
- 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 +43 -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 +43 -41
- 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 +52 -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 +55 -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 +12 -11
- data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class String
|
2
|
-
CAP_LIST_REGEX = Regexp.new(
|
4
|
+
CAP_LIST_REGEX = Regexp.new('"([\w\s]+)"|(\S+)')
|
3
5
|
WHITESPACE_REGEX = Regexp.new('^\s+$')
|
4
6
|
|
5
7
|
# Reformats string for a CAP list. If the string contains whitespace it will
|
@@ -10,8 +12,8 @@ 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
|
14
|
-
'"'+self+'"'
|
15
|
+
if /\s/.match?(self)
|
16
|
+
'"' + self + '"'
|
15
17
|
else
|
16
18
|
self
|
17
19
|
end
|
@@ -24,7 +26,7 @@ class String
|
|
24
26
|
# "one \"two words\" three".unpack_cap_list # => [ "one", "two words", "three" ]
|
25
27
|
# @see Array#to_s_for_cap
|
26
28
|
def unpack_cap_list
|
27
|
-
|
29
|
+
split(CAP_LIST_REGEX).reject { |match| match == '' || match =~ WHITESPACE_REGEX }
|
28
30
|
end
|
29
31
|
|
30
32
|
def blank?
|
data/lib/rcap/extensions/time.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
class Time
|
3
4
|
# Returns a string representaion of the time suitable for CAP.
|
4
5
|
# @return [String]
|
5
6
|
# @example
|
6
7
|
# Time.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
|
7
8
|
def to_s_for_cap
|
8
|
-
t =
|
9
|
+
t = strftime(RCAP::RCAP_TIME_FORMAT) + format(RCAP::RCAP_ZONE_FORMAT, utc_hours_offset)
|
9
10
|
t.sub(/\+(00:\d\d)$/, '-\1')
|
10
11
|
end
|
11
12
|
|
12
13
|
private
|
14
|
+
|
13
15
|
def utc_hours_offset
|
14
|
-
|
16
|
+
localtime.utc_offset / 3600
|
15
17
|
end
|
16
18
|
end
|
data/lib/rcap/info.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RCAP
|
2
4
|
module Info
|
3
|
-
|
4
|
-
def self.from_h( alert, info_hash )
|
5
|
+
def self.from_h(alert, info_hash)
|
5
6
|
case alert.class::CAP_VERSION
|
6
7
|
when CAP_1_0::Alert::CAP_VERSION
|
7
|
-
CAP_1_0::Info.from_h(
|
8
|
+
CAP_1_0::Info.from_h(info_hash)
|
8
9
|
when CAP_1_1::Alert::CAP_VERSION
|
9
|
-
CAP_1_1::Info.from_h(
|
10
|
+
CAP_1_1::Info.from_h(info_hash)
|
10
11
|
else
|
11
|
-
CAP_1_2::Info.from_h(
|
12
|
+
CAP_1_2::Info.from_h(info_hash)
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
data/lib/rcap/utilities.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ALLOWED_CHARACTERS = /[^\s&<]+/
|
2
4
|
|
3
5
|
module RCAP
|
@@ -15,9 +17,9 @@ module RCAP
|
|
15
17
|
# @param [String] xpath XPath expression
|
16
18
|
# @param [String] namespace Namespace in which to do the matching
|
17
19
|
# @return [String,nil] Text content of element matching XPath query or nil
|
18
|
-
def self.xpath_text(
|
19
|
-
element =
|
20
|
-
element.text.strip if element
|
20
|
+
def self.xpath_text(xml_element, xpath, namespace)
|
21
|
+
element = xpath_first(xml_element, xpath, namespace)
|
22
|
+
element.text.strip if element&.text
|
21
23
|
end
|
22
24
|
|
23
25
|
# Returns first descendent that matches the given XPath expression.
|
@@ -26,8 +28,8 @@ module RCAP
|
|
26
28
|
# @param [String] xpath XPath expression
|
27
29
|
# @param [String] namespace Namespace in which to do the matching
|
28
30
|
# @return [REXML::Element,nil] Element matching XPath query or nil
|
29
|
-
def self.xpath_first(
|
30
|
-
REXML::XPath.first(
|
31
|
+
def self.xpath_first(xml_element, xpath, namespace)
|
32
|
+
REXML::XPath.first(xml_element, xpath, 'cap' => namespace)
|
31
33
|
end
|
32
34
|
|
33
35
|
# Returns all descendents that match the given XPath expression.
|
@@ -36,8 +38,8 @@ module RCAP
|
|
36
38
|
# @param [String] xpath XPath expression
|
37
39
|
# @param [String] namespace Namespace in which to do the matching
|
38
40
|
# @return [Array<REXML::Element>] Collection of elements matching XPath query
|
39
|
-
def self.xpath_match(
|
40
|
-
REXML::XPath.match(
|
41
|
+
def self.xpath_match(xml_element, xpath, namespace)
|
42
|
+
REXML::XPath.match(xml_element, xpath, 'cap' => namespace)
|
41
43
|
end
|
42
44
|
|
43
45
|
# Formats output for inspect
|
@@ -56,13 +58,12 @@ module RCAP
|
|
56
58
|
# # | two |
|
57
59
|
# # | three |
|
58
60
|
# # '-------'
|
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
|
-
'|' + '-' * (
|
64
|
-
|
65
|
-
"'" + '-' * ( max_line_length + 2 ) + "'\n"
|
61
|
+
def self.format_lines_for_inspect(header, inspect_string)
|
62
|
+
max_line_length = inspect_string.lines.map { |line| line.strip.length }.max
|
63
|
+
"\n." + '-' * (max_line_length + 2) + ".\n"\
|
64
|
+
'| ' + header.ljust(max_line_length) + " |\n"\
|
65
|
+
'|' + '-' * (max_line_length + 2) + "|\n" + inspect_string.lines.map { |line| '| ' + line.strip.ljust(max_line_length) + ' |' }.join("\n") + "\n" \
|
66
|
+
"'" + '-' * (max_line_length + 2) + "'\n"
|
66
67
|
end
|
67
68
|
|
68
69
|
# Converts an array of key value pairs into a hash, excluding any value that is nil.
|
@@ -72,17 +73,17 @@ module RCAP
|
|
72
73
|
#
|
73
74
|
# @example
|
74
75
|
# RCAP.attribute_values_to_hash( ['a', 1], ['b' , nil ]) # => { 'a' => 1 }
|
75
|
-
def self.attribute_values_to_hash(
|
76
|
-
Hash[
|
76
|
+
def self.attribute_values_to_hash(*attribute_values)
|
77
|
+
Hash[*attribute_values.reject { |_key, value| value.nil? }.flatten(1)]
|
77
78
|
end
|
78
79
|
|
79
80
|
# Calls #to_s_for_cap on the object it it responds to that otherwise just calls #to_s
|
80
81
|
#
|
81
82
|
# @param [#to_s, #to_s_for_cap] object
|
82
83
|
# @return [String]
|
83
|
-
def self.to_s_for_cap(
|
84
|
+
def self.to_s_for_cap(object)
|
84
85
|
if object
|
85
|
-
if object.respond_to?(
|
86
|
+
if object.respond_to?(:to_s_for_cap)
|
86
87
|
object.to_s_for_cap
|
87
88
|
else
|
88
89
|
object.to_s
|
@@ -94,12 +95,10 @@ module RCAP
|
|
94
95
|
#
|
95
96
|
# @param [String] date String to parse
|
96
97
|
# @return [String,nil]
|
97
|
-
def self.parse_datetime(
|
98
|
+
def self.parse_datetime(date)
|
98
99
|
case date
|
99
100
|
when String
|
100
|
-
|
101
|
-
DateTime.parse( date.strip )
|
102
|
-
end
|
101
|
+
DateTime.parse(date.strip) unless date.empty?
|
103
102
|
when DateTime, Time, Date
|
104
103
|
date.to_datetime
|
105
104
|
end
|
@@ -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,10 +121,8 @@ module RCAP
|
|
122
121
|
#
|
123
122
|
# @param [String] string
|
124
123
|
# @return [String,nil]
|
125
|
-
def
|
126
|
-
|
127
|
-
string.strip
|
128
|
-
end
|
124
|
+
def self.strip_if_given(string)
|
125
|
+
string&.strip
|
129
126
|
end
|
130
127
|
|
131
128
|
# if the string is given, String#strip and then String#to_f are applied
|
@@ -133,7 +130,7 @@ module RCAP
|
|
133
130
|
#
|
134
131
|
# @param [String] number
|
135
132
|
# @return [Float,nil]
|
136
|
-
def
|
133
|
+
def self.to_f_if_given(number)
|
137
134
|
if number
|
138
135
|
case number
|
139
136
|
when String
|
@@ -145,13 +142,13 @@ module RCAP
|
|
145
142
|
end
|
146
143
|
end
|
147
144
|
end
|
148
|
-
|
145
|
+
|
149
146
|
# if the string is given, String#strip and then String#to_i are applied
|
150
147
|
# otherwise nil is returned.
|
151
148
|
#
|
152
149
|
# @param [String] number
|
153
150
|
# @return [Integer,nil]
|
154
|
-
def
|
151
|
+
def self.to_i_if_given(number)
|
155
152
|
if number
|
156
153
|
case number
|
157
154
|
when String
|
data/lib/rcap/validation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This file is ripped directly from the no-longer-maintained assistance gem. Other code in that gem
|
2
4
|
# was causing issues, so I'm putting the needed code directly in rcap as a workaround.
|
3
5
|
|
@@ -45,7 +47,7 @@ module Validation
|
|
45
47
|
class Errors
|
46
48
|
# Initializes a new instance of validation errors.
|
47
49
|
def initialize
|
48
|
-
@errors = Hash.new {|h, k| h[k] = []}
|
50
|
+
@errors = Hash.new { |h, k| h[k] = [] }
|
49
51
|
end
|
50
52
|
|
51
53
|
# Returns true if no errors are stored.
|
@@ -62,7 +64,7 @@ module Validation
|
|
62
64
|
def on(att)
|
63
65
|
@errors[att]
|
64
66
|
end
|
65
|
-
|
67
|
+
alias [] on
|
66
68
|
|
67
69
|
# Adds an error for the given attribute.
|
68
70
|
def add(att, msg)
|
@@ -71,9 +73,9 @@ module Validation
|
|
71
73
|
|
72
74
|
# Returns an array of fully-formatted error messages.
|
73
75
|
def full_messages
|
74
|
-
@errors.
|
75
|
-
errors
|
76
|
-
m
|
76
|
+
@errors.each_with_object([]) do |kv, m|
|
77
|
+
att, errors = *kv
|
78
|
+
errors.each { |e| m << "#{att} #{e}" }
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -82,7 +84,7 @@ module Validation
|
|
82
84
|
# the validates {} idiom.
|
83
85
|
class Generator
|
84
86
|
# Initializes a new generator.
|
85
|
-
def initialize(receiver
|
87
|
+
def initialize(receiver, &block)
|
86
88
|
@receiver = receiver
|
87
89
|
instance_eval(&block)
|
88
90
|
end
|
@@ -118,7 +120,7 @@ module Validation
|
|
118
120
|
|
119
121
|
# Returns the validations hash for the class.
|
120
122
|
def validations
|
121
|
-
@validations ||= Hash.new {|h, k| h[k] = []}
|
123
|
+
@validations ||= Hash.new { |h, k| h[k] = [] }
|
122
124
|
end
|
123
125
|
|
124
126
|
# Returns true if validations are defined.
|
@@ -133,7 +135,7 @@ module Validation
|
|
133
135
|
end
|
134
136
|
validations.each do |att, procs|
|
135
137
|
v = o.send(att)
|
136
|
-
procs.each {|p| p[o, att, v]}
|
138
|
+
procs.each { |p| p[o, att, v] }
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
@@ -149,15 +151,15 @@ module Validation
|
|
149
151
|
# object.errors[attribute] << 'is not nice' unless value.nice?
|
150
152
|
# end
|
151
153
|
def validates_each(*atts, &block)
|
152
|
-
atts.each {|a| validations[a] << block}
|
154
|
+
atts.each { |a| validations[a] << block }
|
153
155
|
end
|
154
156
|
|
155
157
|
# Validates acceptance of an attribute.
|
156
158
|
def validates_acceptance_of(*atts)
|
157
159
|
opts = {
|
158
|
-
:
|
159
|
-
:
|
160
|
-
:
|
160
|
+
message: 'is not accepted',
|
161
|
+
allow_nil: true,
|
162
|
+
accept: '1'
|
161
163
|
}.merge!(atts.extract_options!)
|
162
164
|
|
163
165
|
validates_each(*atts) do |o, a, v|
|
@@ -169,7 +171,7 @@ module Validation
|
|
169
171
|
# Validates confirmation of an attribute.
|
170
172
|
def validates_confirmation_of(*atts)
|
171
173
|
opts = {
|
172
|
-
:
|
174
|
+
message: 'is not confirmed'
|
173
175
|
}.merge!(atts.extract_options!)
|
174
176
|
|
175
177
|
validates_each(*atts) do |o, a, v|
|
@@ -182,11 +184,11 @@ module Validation
|
|
182
184
|
# Validates the format of an attribute.
|
183
185
|
def validates_format_of(*atts)
|
184
186
|
opts = {
|
185
|
-
:
|
187
|
+
message: 'is invalid'
|
186
188
|
}.merge!(atts.extract_options!)
|
187
189
|
|
188
190
|
unless opts[:with].is_a?(Regexp)
|
189
|
-
raise ArgumentError,
|
191
|
+
raise ArgumentError, 'A regular expression must be supplied as the :with option of the options hash'
|
190
192
|
end
|
191
193
|
|
192
194
|
validates_each(*atts) do |o, a, v|
|
@@ -198,9 +200,9 @@ module Validation
|
|
198
200
|
# Validates the length of an attribute.
|
199
201
|
def validates_length_of(*atts)
|
200
202
|
opts = {
|
201
|
-
:
|
202
|
-
:
|
203
|
-
:
|
203
|
+
too_long: 'is too long',
|
204
|
+
too_short: 'is too short',
|
205
|
+
wrong_length: 'is the wrong length'
|
204
206
|
}.merge!(atts.extract_options!)
|
205
207
|
|
206
208
|
validates_each(*atts) do |o, a, v|
|
@@ -226,7 +228,7 @@ module Validation
|
|
226
228
|
# Validates whether an attribute is a number.
|
227
229
|
def validates_numericality_of(*atts)
|
228
230
|
opts = {
|
229
|
-
:
|
231
|
+
message: 'is not a number'
|
230
232
|
}.merge!(atts.extract_options!)
|
231
233
|
|
232
234
|
re = opts[:only_integer] ? INTEGER_RE : NUMBER_RE
|
@@ -240,7 +242,7 @@ module Validation
|
|
240
242
|
# Validates the presence of an attribute.
|
241
243
|
def validates_presence_of(*atts)
|
242
244
|
opts = {
|
243
|
-
:
|
245
|
+
message: 'is not present'
|
244
246
|
}.merge!(atts.extract_options!)
|
245
247
|
|
246
248
|
validates_each(*atts) do |o, a, v|
|
@@ -249,4 +251,3 @@ module Validation
|
|
249
251
|
end
|
250
252
|
end
|
251
253
|
end
|
252
|
-
|
data/lib/rcap/version.rb
CHANGED
data/rcap.gemspec
CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
|
22
22
|
s.extra_rdoc_files = ['README.md','CHANGELOG.md']
|
23
|
-
s.add_dependency('json'
|
24
|
-
s.add_dependency('uuidtools'
|
23
|
+
s.add_dependency('json')
|
24
|
+
s.add_dependency('uuidtools')
|
25
25
|
|
26
|
-
s.add_development_dependency(
|
27
|
-
s.add_development_dependency(
|
28
|
-
s.add_development_dependency(
|
26
|
+
s.add_development_dependency('rspec')
|
27
|
+
s.add_development_dependency('yard')
|
28
|
+
s.add_development_dependency('webmock')
|
29
29
|
end
|
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
|