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/extensions/time.rb
CHANGED
data/lib/rcap/formatters/yaml.rb
CHANGED
data/lib/rcap/info.rb
CHANGED
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
|
@@ -17,7 +19,7 @@ module RCAP
|
|
17
19
|
# @return [String,nil] Text content of element matching XPath query or nil
|
18
20
|
def self.xpath_text(xml_element, xpath, namespace)
|
19
21
|
element = xpath_first(xml_element, xpath, namespace)
|
20
|
-
element.text.strip if element
|
22
|
+
element.text.strip if element&.text
|
21
23
|
end
|
22
24
|
|
23
25
|
# Returns first descendent that matches the given XPath expression.
|
@@ -60,8 +62,8 @@ module RCAP
|
|
60
62
|
max_line_length = inspect_string.lines.map { |line| line.strip.length }.max
|
61
63
|
"\n." + '-' * (max_line_length + 2) + ".\n"\
|
62
64
|
'| ' + header.ljust(max_line_length) + " |\n"\
|
63
|
-
'|' + '-' * (
|
64
|
-
"'" + '-' * (
|
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"
|
65
67
|
end
|
66
68
|
|
67
69
|
# Converts an array of key value pairs into a hash, excluding any value that is nil.
|
@@ -96,9 +98,7 @@ module RCAP
|
|
96
98
|
def self.parse_datetime(date)
|
97
99
|
case date
|
98
100
|
when String
|
99
|
-
unless
|
100
|
-
DateTime.parse(date.strip)
|
101
|
-
end
|
101
|
+
DateTime.parse(date.strip) unless date.empty?
|
102
102
|
when DateTime, Time, Date
|
103
103
|
date.to_datetime
|
104
104
|
end
|
@@ -122,9 +122,7 @@ module RCAP
|
|
122
122
|
# @param [String] string
|
123
123
|
# @return [String,nil]
|
124
124
|
def self.strip_if_given(string)
|
125
|
-
|
126
|
-
string.strip
|
127
|
-
end
|
125
|
+
string&.strip
|
128
126
|
end
|
129
127
|
|
130
128
|
# if the string is given, String#strip and then String#to_f are applied
|
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
|
|
@@ -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
|
-
|
76
|
-
|
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
|
@@ -169,7 +171,7 @@ module Validation
|
|
169
171
|
# Validates confirmation of an attribute.
|
170
172
|
def validates_confirmation_of(*atts)
|
171
173
|
opts = {
|
172
|
-
message: 'is not confirmed'
|
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
|
-
message: 'is invalid'
|
187
|
+
message: 'is invalid'
|
186
188
|
}.merge!(atts.extract_options!)
|
187
189
|
|
188
190
|
unless opts[:with].is_a?(Regexp)
|
189
|
-
|
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|
|
@@ -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
|
-
message: 'is not a number'
|
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
|
-
message: 'is not present'
|
245
|
+
message: 'is not present'
|
244
246
|
}.merge!(atts.extract_options!)
|
245
247
|
|
246
248
|
validates_each(*atts) do |o, a, v|
|
data/lib/rcap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Farrel Lifson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
version: '0'
|
223
223
|
requirements: []
|
224
224
|
rubyforge_project: rcap
|
225
|
-
rubygems_version: 2.
|
225
|
+
rubygems_version: 2.7.3
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: CAP(Common Alerting Protocol) API
|
@@ -276,4 +276,3 @@ test_files:
|
|
276
276
|
- spec/spec.opts
|
277
277
|
- spec/spec_helper.rb
|
278
278
|
- spec/validations_spec.rb
|
279
|
-
has_rdoc:
|