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.
Files changed (99) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +18 -0
  4. data/README.md +1 -0
  5. data/lib/rcap.rb +3 -1
  6. data/lib/rcap/alert.rb +30 -29
  7. data/lib/rcap/base/alert.rb +208 -205
  8. data/lib/rcap/base/area.rb +95 -91
  9. data/lib/rcap/base/circle.rb +45 -34
  10. data/lib/rcap/base/event_code.rb +2 -0
  11. data/lib/rcap/base/geocode.rb +2 -0
  12. data/lib/rcap/base/info.rb +273 -272
  13. data/lib/rcap/base/parameter.rb +29 -28
  14. data/lib/rcap/base/point.rb +26 -24
  15. data/lib/rcap/base/polygon.rb +43 -35
  16. data/lib/rcap/base/resource.rb +65 -65
  17. data/lib/rcap/cap_1_0/alert.rb +85 -86
  18. data/lib/rcap/cap_1_0/area.rb +2 -2
  19. data/lib/rcap/cap_1_0/circle.rb +2 -1
  20. data/lib/rcap/cap_1_0/event_code.rb +3 -1
  21. data/lib/rcap/cap_1_0/geocode.rb +3 -1
  22. data/lib/rcap/cap_1_0/info.rb +3 -3
  23. data/lib/rcap/cap_1_0/parameter.rb +13 -13
  24. data/lib/rcap/cap_1_0/point.rb +2 -1
  25. data/lib/rcap/cap_1_0/polygon.rb +3 -3
  26. data/lib/rcap/cap_1_0/resource.rb +2 -3
  27. data/lib/rcap/cap_1_1/alert.rb +6 -6
  28. data/lib/rcap/cap_1_1/area.rb +2 -2
  29. data/lib/rcap/cap_1_1/circle.rb +2 -1
  30. data/lib/rcap/cap_1_1/event_code.rb +3 -1
  31. data/lib/rcap/cap_1_1/geocode.rb +3 -1
  32. data/lib/rcap/cap_1_1/info.rb +125 -132
  33. data/lib/rcap/cap_1_1/parameter.rb +2 -3
  34. data/lib/rcap/cap_1_1/point.rb +2 -1
  35. data/lib/rcap/cap_1_1/polygon.rb +3 -3
  36. data/lib/rcap/cap_1_1/resource.rb +37 -38
  37. data/lib/rcap/cap_1_2/alert.rb +6 -6
  38. data/lib/rcap/cap_1_2/area.rb +2 -2
  39. data/lib/rcap/cap_1_2/circle.rb +2 -1
  40. data/lib/rcap/cap_1_2/event_code.rb +3 -1
  41. data/lib/rcap/cap_1_2/geocode.rb +3 -1
  42. data/lib/rcap/cap_1_2/info.rb +120 -123
  43. data/lib/rcap/cap_1_2/parameter.rb +2 -3
  44. data/lib/rcap/cap_1_2/point.rb +2 -1
  45. data/lib/rcap/cap_1_2/polygon.rb +4 -4
  46. data/lib/rcap/cap_1_2/resource.rb +38 -38
  47. data/lib/rcap/config.rb +5 -3
  48. data/lib/rcap/custom_validators.rb +75 -78
  49. data/lib/rcap/extensions/array.rb +3 -1
  50. data/lib/rcap/extensions/date.rb +3 -1
  51. data/lib/rcap/extensions/date_time.rb +5 -2
  52. data/lib/rcap/extensions/float.rb +2 -0
  53. data/lib/rcap/extensions/integer.rb +7 -0
  54. data/lib/rcap/extensions/nil_class.rb +2 -0
  55. data/lib/rcap/extensions/string.rb +6 -4
  56. data/lib/rcap/extensions/time.rb +5 -3
  57. data/lib/rcap/formatters/yaml.rb +5 -0
  58. data/lib/rcap/info.rb +6 -5
  59. data/lib/rcap/utilities.rb +27 -30
  60. data/lib/rcap/validation.rb +22 -21
  61. data/lib/rcap/version.rb +3 -1
  62. data/rcap.gemspec +5 -5
  63. data/spec/alert_spec.rb +141 -141
  64. data/spec/cap_1_0/alert_spec.rb +92 -94
  65. data/spec/cap_1_0/area_spec.rb +86 -86
  66. data/spec/cap_1_0/circle_spec.rb +48 -39
  67. data/spec/cap_1_0/event_code_spec.rb +15 -15
  68. data/spec/cap_1_0/geocode_spec.rb +16 -16
  69. data/spec/cap_1_0/info_spec.rb +175 -177
  70. data/spec/cap_1_0/parameter_spec.rb +27 -27
  71. data/spec/cap_1_0/point_spec.rb +18 -18
  72. data/spec/cap_1_0/polygon_spec.rb +43 -41
  73. data/spec/cap_1_0/resource_spec.rb +63 -64
  74. data/spec/cap_1_1/alert_spec.rb +107 -109
  75. data/spec/cap_1_1/area_spec.rb +90 -90
  76. data/spec/cap_1_1/circle_spec.rb +43 -34
  77. data/spec/cap_1_1/event_code_spec.rb +15 -16
  78. data/spec/cap_1_1/geocode_spec.rb +16 -16
  79. data/spec/cap_1_1/info_spec.rb +194 -196
  80. data/spec/cap_1_1/parameter_spec.rb +17 -17
  81. data/spec/cap_1_1/point_spec.rb +18 -18
  82. data/spec/cap_1_1/polygon_spec.rb +43 -41
  83. data/spec/cap_1_1/resource_spec.rb +106 -107
  84. data/spec/cap_1_2/alert_spec.rb +98 -99
  85. data/spec/cap_1_2/area_spec.rb +90 -90
  86. data/spec/cap_1_2/circle_spec.rb +52 -43
  87. data/spec/cap_1_2/event_code_spec.rb +19 -20
  88. data/spec/cap_1_2/geocode_spec.rb +20 -20
  89. data/spec/cap_1_2/info_spec.rb +196 -198
  90. data/spec/cap_1_2/parameter_spec.rb +19 -19
  91. data/spec/cap_1_2/point_spec.rb +21 -21
  92. data/spec/cap_1_2/polygon_spec.rb +55 -47
  93. data/spec/cap_1_2/resource_spec.rb +96 -97
  94. data/spec/extensions_spec.rb +29 -29
  95. data/spec/info_spec.rb +15 -15
  96. data/spec/spec_helper.rb +3 -3
  97. data/spec/validations_spec.rb +73 -73
  98. metadata +12 -11
  99. data/lib/rcap/extensions/fixnum.rb +0 -5
@@ -1,30 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RCAP
2
4
  module CAP_1_2
3
-
4
5
  # A Resource object is valid if
5
6
  # * it has a resource description
6
7
  # * it has a mime_type
7
8
  class Resource < RCAP::Base::Resource
8
-
9
9
  # @return [String] Dereferenced URI - contents of URI Base64 encoded
10
- attr_accessor( :deref_uri )
10
+ attr_accessor(:deref_uri)
11
11
 
12
- validates_presence_of( :mime_type )
12
+ validates_presence_of(:mime_type)
13
13
 
14
- DEREF_URI_ELEMENT_NAME = 'derefUri'
14
+ DEREF_URI_ELEMENT_NAME = 'derefUri'
15
15
 
16
- DEREF_URI_XPATH = "cap:#{ DEREF_URI_ELEMENT_NAME }"
16
+ DEREF_URI_XPATH = "cap:#{DEREF_URI_ELEMENT_NAME}"
17
17
 
18
18
  # @return [REXML::Element]
19
19
  def to_xml_element
20
- xml_element = super
21
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
22
- xml_element.add_element( RESOURCE_DESC_ELEMENT_NAME ).add_text( @resource_desc )
23
- xml_element.add_element( MIME_TYPE_ELEMENT_NAME ).add_text( @mime_type ) if @mime_type
24
- xml_element.add_element( SIZE_ELEMENT_NAME ).add_text( @size.to_s ) if @size
25
- xml_element.add_element( URI_ELEMENT_NAME ).add_text( @uri ) if @uri
26
- xml_element.add_element( DEREF_URI_ELEMENT_NAME ).add_text( @deref_uri ) if @deref_uri
27
- xml_element.add_element( DIGEST_ELEMENT_NAME ).add_text( @digest ) if @digest
20
+ xml_element = REXML::Element.new(XML_ELEMENT_NAME)
21
+ xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
22
+ xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
23
+ xml_element.add_element(SIZE_ELEMENT_NAME).add_text(@size.to_s) if @size
24
+ xml_element.add_element(URI_ELEMENT_NAME).add_text(@uri) if @uri
25
+ xml_element.add_element(DEREF_URI_ELEMENT_NAME).add_text(@deref_uri) if @deref_uri
26
+ xml_element.add_element(DIGEST_ELEMENT_NAME).add_text(@digest) if @digest
28
27
  xml_element
29
28
  end
30
29
 
@@ -39,9 +38,9 @@ module RCAP
39
38
  #
40
39
  # @return [Array(Integer,String)]
41
40
  def dereference_uri!
42
- content = URI.parse( self.uri ).read
43
- @deref_uri = Base64.encode64( content )
44
- self.calculate_hash_and_size
41
+ content = URI.parse(uri).read
42
+ @deref_uri = Base64.encode64(content)
43
+ calculate_hash_and_size
45
44
  end
46
45
 
47
46
  # @return [String]
@@ -51,51 +50,52 @@ module RCAP
51
50
 
52
51
  # @param [REXML::Element] resource_xml_element
53
52
  # @return [Resource]
54
- def self.from_xml_element( resource_xml_element )
53
+ def self.from_xml_element(resource_xml_element)
55
54
  super.tap do |resource|
56
- resource.deref_uri = RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH, resource.xmlns )
55
+ resource.deref_uri = RCAP.xpath_text(resource_xml_element, DEREF_URI_XPATH, resource.xmlns)
57
56
  end
58
57
  end
59
58
 
60
- DEREF_URI_YAML = "Derefrenced URI Data"
59
+ DEREF_URI_YAML = 'Derefrenced URI Data'
61
60
 
62
61
  # @param [Hash] options
63
62
  # @return [String]
64
- def to_yaml( options = {} )
63
+ def to_yaml(options = {})
65
64
  RCAP.attribute_values_to_hash(
66
- [ RESOURCE_DESC_YAML, @resource_desc ],
67
- [ URI_YAML, @uri ],
68
- [ MIME_TYPE_YAML, @mime_type ],
69
- [ DEREF_URI_YAML, @deref_uri ],
70
- [ SIZE_YAML, @size ],
71
- [ DIGEST_YAML, @digest ]).to_yaml( options )
65
+ [RESOURCE_DESC_YAML, @resource_desc],
66
+ [URI_YAML, @uri],
67
+ [MIME_TYPE_YAML, @mime_type],
68
+ [DEREF_URI_YAML, @deref_uri],
69
+ [SIZE_YAML, @size],
70
+ [DIGEST_YAML, @digest]
71
+ ).to_yaml(options)
72
72
  end
73
73
 
74
74
  # @param [Hash] resource_yaml_data
75
75
  # @return [Resource]
76
- def self.from_yaml_data( resource_yaml_data )
76
+ def self.from_yaml_data(resource_yaml_data)
77
77
  super.tap do |resource|
78
- resource.deref_uri = resource_yaml_data[ DEREF_URI_YAML ].strip if resource_yaml_data[ DEREF_URI_YAML ]
78
+ resource.deref_uri = resource_yaml_data[DEREF_URI_YAML].strip if resource_yaml_data[DEREF_URI_YAML]
79
79
  end
80
80
  end
81
81
 
82
- DEREF_URI_KEY = 'deref_uri'
82
+ DEREF_URI_KEY = 'deref_uri'
83
83
 
84
84
  # @return [Hash]
85
85
  def to_h
86
- RCAP.attribute_values_to_hash( [ RESOURCE_DESC_KEY, @resource_desc ],
87
- [ URI_KEY, @uri],
88
- [ MIME_TYPE_KEY, @mime_type],
89
- [ DEREF_URI_KEY, @deref_uri],
90
- [ SIZE_KEY, @size ],
91
- [ DIGEST_KEY, @digest ])
86
+ RCAP.attribute_values_to_hash([RESOURCE_DESC_KEY, @resource_desc],
87
+ [URI_KEY, @uri],
88
+ [MIME_TYPE_KEY, @mime_type],
89
+ [DEREF_URI_KEY, @deref_uri],
90
+ [SIZE_KEY, @size],
91
+ [DIGEST_KEY, @digest])
92
92
  end
93
93
 
94
94
  # @param [Hash] resource_hash
95
95
  # @return [Resource]
96
- def self.from_h( resource_hash )
96
+ def self.from_h(resource_hash)
97
97
  super.tap do |resource|
98
- resource.deref_uri = resource_hash[ DEREF_URI_KEY ].strip if resource_hash[ DEREF_URI_KEY ]
98
+ resource.deref_uri = resource_hash[DEREF_URI_KEY].strip if resource_hash[DEREF_URI_KEY]
99
99
  end
100
100
  end
101
101
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RCAP
2
- XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new( 2 )
4
+ XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new(2)
3
5
  XML_PRETTY_PRINTER.compact = true
4
6
 
5
- RCAP_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
6
- RCAP_ZONE_FORMAT = "%+03i:00"
7
+ RCAP_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
8
+ RCAP_ZONE_FORMAT = '%+03i:00'
7
9
  end
@@ -1,20 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Validation
2
4
  module ClassMethods
3
-
4
- CAP_NUMBER_REGEX = Regexp.new( '^-{0,1}\d*\.{0,1}\d+$' )
5
- CAP_INTEGER_REGEX = Regexp.new( '\-{0,1}A[+-]?\d+\Z' )
5
+ CAP_NUMBER_REGEX = Regexp.new('^-{0,1}\d*\.{0,1}\d+$')
6
+ CAP_INTEGER_REGEX = Regexp.new('\-{0,1}A[+-]?\d+\Z')
6
7
 
7
8
  # @example
8
9
  # validates_inclusion_of( :status, :in => VALID_STATUSES )
9
- def validates_inclusion_of( *attributes )
10
+ def validates_inclusion_of(*attributes)
10
11
  options = {
11
- :message => 'is not in the required range'
12
- }.merge!( attributes.extract_options! )
12
+ message: 'is not in the required range'
13
+ }.merge!(attributes.extract_options!)
13
14
 
14
- validates_each( *attributes ) do |object, attribute, value|
15
- next if ( value.nil? && options[ :allow_nil ])
16
- unless options[ :in ].include?( value )
17
- object.errors[ attribute ] << options[ :message ]
15
+ validates_each(*attributes) do |object, attribute, value|
16
+ next if value.nil? && options[:allow_nil]
17
+ unless options[:in].include?(value)
18
+ object.errors[attribute] << options[:message]
18
19
  end
19
20
  end
20
21
  end
@@ -22,134 +23,130 @@ module Validation
22
23
  # Will validate all members of a collection are found in a given collection.
23
24
  # @example
24
25
  # validates_inclusion_of_members_of( :categories, :in => VALID_CATEGORIES )
25
- def validates_inclusion_of_members_of( *attributes )
26
+ def validates_inclusion_of_members_of(*attributes)
26
27
  options = {
27
- :message => 'contains members that are not valid'
28
- }.merge!( attributes.extract_options! )
28
+ message: 'contains members that are not valid'
29
+ }.merge!(attributes.extract_options!)
29
30
 
30
- validates_each( *attributes ) do |object, attribute, collection|
31
- next if ( collection.nil? && options[ :allow_nil ]) || ( collection.empty? && options[ :allow_empty ])
32
- unless collection.all?{ |member| options[ :in ].include?( member )}
33
- object.errors[ attribute ] << options[ :message ]
31
+ validates_each(*attributes) do |object, attribute, collection|
32
+ next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
33
+ unless collection.all? { |member| options[:in].include?(member) }
34
+ object.errors[attribute] << options[:message]
34
35
  end
35
36
  end
36
37
  end
37
38
 
38
- def validates_length_of_members_of( *attributes )
39
+ def validates_length_of_members_of(*attributes)
39
40
  options = {
40
- :message => 'contains members with incorrect length'
41
- }.merge!( attributes.extract_options! )
41
+ message: 'contains members with incorrect length'
42
+ }.merge!(attributes.extract_options!)
42
43
 
43
- validates_each( *attributes ) do |object, attribute, collection|
44
- next if ( collection.nil? && options[ :allow_nil ]) || ( collection.empty? && options[ :allow_empty ])
45
- unless options[ :minimum ] && collection.length >= options[ :minimum ]
46
- object.errors[ attribute ] << options[ :message ]
44
+ validates_each(*attributes) do |object, attribute, collection|
45
+ next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
46
+ unless options[:minimum] && collection.length >= options[:minimum]
47
+ object.errors[attribute] << options[:message]
47
48
  end
48
49
  end
49
50
  end
50
51
 
51
- def validates_validity_of( *attributes )
52
+ def validates_validity_of(*attributes)
52
53
  options = {
53
- :message => 'is not valid'
54
- }.merge!( attributes.extract_options! )
54
+ message: 'is not valid'
55
+ }.merge!(attributes.extract_options!)
55
56
 
56
- validates_each( *attributes ) do |object, attribute, value|
57
- next if ( value.nil? && options[ :allow_nil ])
58
- unless value && value.valid?
59
- object.errors[ attribute ] << options[ :message ]
60
- end
57
+ validates_each(*attributes) do |object, attribute, value|
58
+ next if value.nil? && options[:allow_nil]
59
+ object.errors[attribute] << options[:message] unless value&.valid?
61
60
  end
62
61
  end
63
62
 
64
- def validates_collection_of( *attributes )
63
+ def validates_collection_of(*attributes)
65
64
  options = {
66
- :message => 'contains an invalid element'
67
- }.merge!( attributes.extract_options! )
65
+ message: 'contains an invalid element'
66
+ }.merge!(attributes.extract_options!)
68
67
 
69
- validates_each( *attributes ) do |object, attribute, collection|
70
- next if ( collection.nil? && options[ :allow_nil ]) || ( collection.empty? && options[ :allow_empty ])
71
- unless collection.all?{ |element| element.valid? }
72
- object.errors[ attribute ] << options[ :message ]
68
+ validates_each(*attributes) do |object, attribute, collection|
69
+ next if (collection.nil? && options[:allow_nil]) || (collection.empty? && options[:allow_empty])
70
+ unless collection.all?(&:valid?)
71
+ object.errors[attribute] << options[:message]
73
72
  end
74
73
  end
75
74
  end
76
75
 
77
- def validates_dependency_of( *attributes )
76
+ def validates_dependency_of(*attributes)
78
77
  options = {
79
- :message => 'is dependent on :attribute being defined'
80
- }.merge!( attributes.extract_options! )
78
+ message: 'is dependent on :attribute being defined'
79
+ }.merge!(attributes.extract_options!)
81
80
 
82
- validates_each( *attributes ) do |object, attribute, value|
81
+ validates_each(*attributes) do |object, attribute, value|
83
82
  next if value.blank?
84
- contingent_on_attribute = object.send( options[ :on ])
85
- contingent_on_attribute_value = options[ :with_value ]
83
+ contingent_on_attribute = object.send(options[:on])
84
+ contingent_on_attribute_value = options[:with_value]
86
85
 
87
86
  if contingent_on_attribute.nil? || !contingent_on_attribute_value.nil? && contingent_on_attribute_value != contingent_on_attribute
88
- object.errors[ attribute ] << options[ :message ].gsub( /:attribute/, options[ :on ].to_s )
87
+ object.errors[attribute] << options[:message].gsub(/:attribute/, options[:on].to_s)
89
88
  end
90
89
  end
91
90
  end
92
91
 
93
- def validates_conditional_presence_of( *attributes )
92
+ def validates_conditional_presence_of(*attributes)
94
93
  options = {
95
- :message => 'is not defined but is required by :contingent_attribute'
96
- }.merge!( attributes.extract_options! )
94
+ message: 'is not defined but is required by :contingent_attribute'
95
+ }.merge!(attributes.extract_options!)
97
96
 
98
- validates_each( *attributes ) do |object, attribute, value|
99
- contingent_attribute_value = object.send( options[ :when ] )
100
- required_contingent_attribute_value = options[ :is ]
97
+ validates_each(*attributes) do |object, attribute, value|
98
+ contingent_attribute_value = object.send(options[:when])
99
+ required_contingent_attribute_value = options[:is]
101
100
 
102
- next if contingent_attribute_value.nil? || contingent_attribute_value != required_contingent_attribute_value && !options[ :is ].blank?
101
+ next if contingent_attribute_value.nil? || contingent_attribute_value != required_contingent_attribute_value && !options[:is].blank?
103
102
  if value.blank?
104
- object.errors[ attribute ] << options[ :message ].gsub( /:contingent_attribute/, options[ :whenn ].to_s )
103
+ object.errors[attribute] << options[:message].gsub(/:contingent_attribute/, options[:whenn].to_s)
105
104
  end
106
105
  end
107
106
  end
108
107
 
109
-
110
- def validates_numericality_of( *attributes )
108
+ def validates_numericality_of(*attributes)
111
109
  options = {
112
- :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'
113
111
  }.merge!(attributes.extract_options!)
114
112
 
115
113
  re = options[:only_integer] ? CAP_INTEGER_REGEX : CAP_NUMBER_REGEX
116
114
 
117
- validates_each( *attributes ) do |object, attribute, value|
118
- next if (value.nil? && options[ :allow_nil ])
119
- unless ( value.to_s =~ re ) &&
120
- ( options[ :greater_than ].nil? || value && value > options[ :greater_than ]) &&
121
- ( options[ :greater_than_or_equal ].nil? || value && value >= options[ :greater_than_or_equal])
122
- object.errors[ attribute ] << options[ :message ]
115
+ validates_each(*attributes) do |object, attribute, value|
116
+ next if value.nil? && options[:allow_nil]
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
+ object.errors[attribute] << options[:message]
123
121
  end
124
122
  end
125
123
  end
126
124
 
127
-
128
- def validates_responsiveness_of( *attributes )
125
+ def validates_responsiveness_of(*attributes)
129
126
  options = {
130
- :message => 'does not respond to the given method'
131
- }.merge!( attributes.extract_options! )
127
+ message: 'does not respond to the given method'
128
+ }.merge!(attributes.extract_options!)
132
129
 
133
- validates_each( *attributes ) do |object, attribute, value|
134
- next if ( collection.nil? && options[ :allow_nil ])
135
- unless options[ :to ].all?{ |method_name| object.respond_to?( method_name )}
136
- object.errors[ attribute ] << options [ :message ]
130
+ validates_each(*attributes) do |object, attribute, _value|
131
+ next if collection.nil? && options[:allow_nil]
132
+ unless options[:to].all? { |method_name| object.respond_to?(method_name) }
133
+ object.errors[attribute] << options [:message]
137
134
  end
138
135
  end
139
136
  end
140
137
 
141
- def validates_equality_of_first_and_last( *attributes )
138
+ def validates_equality_of_first_and_last(*attributes)
142
139
  options = {
143
- :message => 'does not have equal first and last elements'
144
- }.merge!( attributes.extract_options! )
140
+ message: 'does not have equal first and last elements'
141
+ }.merge!(attributes.extract_options!)
145
142
 
146
- validates_each( *attributes ) do |object, attribute, collection|
147
- next if ( collection.nil? && options[ :allow_nil ])
143
+ validates_each(*attributes) do |object, attribute, collection|
144
+ next if collection.nil? && options[:allow_nil]
145
+ next if collection.empty? && options[:allow_empty]
148
146
  unless collection.first == collection.last
149
- object.errors[ attribute ] << options[ :message ]
147
+ object.errors[attribute] << options[:message]
150
148
  end
151
149
  end
152
150
  end
153
151
  end
154
152
  end
155
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Array
2
4
  # Formats an array into a string suitable for a CAP message.
3
5
  #
@@ -6,7 +8,7 @@ class Array
6
8
  # [ "one", "two words", "three" ].to_s_for_cap # => "one \"two words\" three"
7
9
  # @see String#unpack_cap_list
8
10
  def to_s_for_cap
9
- self.map{ |element| element.to_s.for_cap_list }.join( ' ' )
11
+ map { |element| element.to_s.for_cap_list }.join(' ')
10
12
  end
11
13
 
12
14
  def blank?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Date
2
4
  alias inspect to_s
3
5
 
@@ -6,6 +8,6 @@ class Date
6
8
  # @example
7
9
  # Date.today.to_s_for_cap # => "2011-10-26T00:00:00+00:00"
8
10
  def to_s_for_cap
9
- self.to_datetime.to_s_for_cap
11
+ to_datetime.to_s_for_cap
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DateTime
2
4
  alias inspect to_s
3
5
 
@@ -6,7 +8,7 @@ class DateTime
6
8
  # @example
7
9
  # DateTime.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
8
10
  def to_s_for_cap
9
- t = self.strftime( RCAP::RCAP_TIME_FORMAT ) + format( RCAP::RCAP_ZONE_FORMAT , utc_hours_offset )
11
+ t = strftime(RCAP::RCAP_TIME_FORMAT) + format(RCAP::RCAP_ZONE_FORMAT, utc_hours_offset)
10
12
  t.sub(/\+(00:\d\d)$/, '-\1')
11
13
  end
12
14
 
@@ -15,7 +17,8 @@ class DateTime
15
17
  end
16
18
 
17
19
  private
20
+
18
21
  def utc_hours_offset
19
- self.offset * 24
22
+ offset * 24
20
23
  end
21
24
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Float
2
4
  def blank?
3
5
  false
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Integer
4
+ def blank?
5
+ false
6
+ end
7
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class NilClass
2
4
  def blank?
3
5
  true