rcap 2.7.0 → 2.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/lib/rcap.rb +2 -0
  4. data/lib/rcap/alert.rb +4 -2
  5. data/lib/rcap/base/alert.rb +57 -55
  6. data/lib/rcap/base/area.rb +19 -13
  7. data/lib/rcap/base/circle.rb +6 -4
  8. data/lib/rcap/base/event_code.rb +2 -0
  9. data/lib/rcap/base/geocode.rb +2 -0
  10. data/lib/rcap/base/info.rb +65 -59
  11. data/lib/rcap/base/parameter.rb +6 -4
  12. data/lib/rcap/base/point.rb +4 -2
  13. data/lib/rcap/base/polygon.rb +8 -6
  14. data/lib/rcap/base/resource.rb +9 -9
  15. data/lib/rcap/cap_1_0/alert.rb +22 -20
  16. data/lib/rcap/cap_1_0/area.rb +2 -0
  17. data/lib/rcap/cap_1_0/circle.rb +2 -0
  18. data/lib/rcap/cap_1_0/event_code.rb +3 -1
  19. data/lib/rcap/cap_1_0/geocode.rb +3 -1
  20. data/lib/rcap/cap_1_0/info.rb +3 -1
  21. data/lib/rcap/cap_1_0/parameter.rb +3 -1
  22. data/lib/rcap/cap_1_0/point.rb +2 -0
  23. data/lib/rcap/cap_1_0/polygon.rb +2 -0
  24. data/lib/rcap/cap_1_0/resource.rb +2 -0
  25. data/lib/rcap/cap_1_1/alert.rb +4 -2
  26. data/lib/rcap/cap_1_1/area.rb +2 -0
  27. data/lib/rcap/cap_1_1/circle.rb +2 -0
  28. data/lib/rcap/cap_1_1/event_code.rb +3 -1
  29. data/lib/rcap/cap_1_1/geocode.rb +3 -1
  30. data/lib/rcap/cap_1_1/info.rb +34 -32
  31. data/lib/rcap/cap_1_1/parameter.rb +2 -0
  32. data/lib/rcap/cap_1_1/point.rb +2 -0
  33. data/lib/rcap/cap_1_1/polygon.rb +2 -0
  34. data/lib/rcap/cap_1_1/resource.rb +6 -4
  35. data/lib/rcap/cap_1_2/alert.rb +4 -2
  36. data/lib/rcap/cap_1_2/area.rb +2 -0
  37. data/lib/rcap/cap_1_2/circle.rb +2 -0
  38. data/lib/rcap/cap_1_2/event_code.rb +3 -1
  39. data/lib/rcap/cap_1_2/geocode.rb +3 -1
  40. data/lib/rcap/cap_1_2/info.rb +42 -38
  41. data/lib/rcap/cap_1_2/parameter.rb +2 -0
  42. data/lib/rcap/cap_1_2/point.rb +2 -0
  43. data/lib/rcap/cap_1_2/polygon.rb +2 -0
  44. data/lib/rcap/cap_1_2/resource.rb +8 -5
  45. data/lib/rcap/config.rb +2 -0
  46. data/lib/rcap/custom_validators.rb +11 -11
  47. data/lib/rcap/extensions/array.rb +2 -0
  48. data/lib/rcap/extensions/date.rb +3 -1
  49. data/lib/rcap/extensions/date_time.rb +4 -1
  50. data/lib/rcap/extensions/float.rb +2 -0
  51. data/lib/rcap/extensions/integer.rb +2 -0
  52. data/lib/rcap/extensions/nil_class.rb +2 -0
  53. data/lib/rcap/extensions/string.rb +3 -1
  54. data/lib/rcap/extensions/time.rb +3 -0
  55. data/lib/rcap/formatters/yaml.rb +3 -2
  56. data/lib/rcap/info.rb +2 -0
  57. data/lib/rcap/utilities.rb +7 -9
  58. data/lib/rcap/validation.rb +11 -9
  59. data/lib/rcap/version.rb +3 -1
  60. metadata +3 -4
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Time
2
4
  # Returns a string representaion of the time suitable for CAP.
3
5
  # @return [String]
@@ -9,6 +11,7 @@ class Time
9
11
  end
10
12
 
11
13
  private
14
+
12
15
  def utc_hours_offset
13
16
  localtime.utc_offset / 3600
14
17
  end
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RCAP::Base::Alert
2
- def to_yaml
3
- end
4
+ def to_yaml; end
4
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RCAP
2
4
  module Info
3
5
  def self.from_h(alert, info_hash)
@@ -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 && element.text
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
- '|' + '-' * ( 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"
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 date.empty?
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
- if string
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
@@ -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
- alias_method :[], :on
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.reduce([]) do |m, kv| att, errors = *kv
75
- errors.each { |e| m << "#{att} #{e}" }
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
@@ -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
- fail ArgumentError, 'A regular expression must be supplied as the :with option of the options hash'
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|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RCAP
2
- VERSION = '2.7.0'
4
+ VERSION = '2.7.3'
3
5
  end
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.0
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: 2017-03-22 00:00:00.000000000 Z
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.6.8
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: