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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/rcap/alert.rb +28 -29
  4. data/lib/rcap/base/alert.rb +192 -192
  5. data/lib/rcap/base/area.rb +84 -86
  6. data/lib/rcap/base/circle.rb +32 -32
  7. data/lib/rcap/base/info.rb +248 -253
  8. data/lib/rcap/base/parameter.rb +23 -24
  9. data/lib/rcap/base/point.rb +23 -23
  10. data/lib/rcap/base/polygon.rb +32 -32
  11. data/lib/rcap/base/resource.rb +57 -57
  12. data/lib/rcap/cap_1_0/alert.rb +79 -83
  13. data/lib/rcap/cap_1_0/area.rb +0 -2
  14. data/lib/rcap/cap_1_0/circle.rb +0 -1
  15. data/lib/rcap/cap_1_0/info.rb +1 -3
  16. data/lib/rcap/cap_1_0/parameter.rb +11 -12
  17. data/lib/rcap/cap_1_0/point.rb +0 -1
  18. data/lib/rcap/cap_1_0/polygon.rb +0 -2
  19. data/lib/rcap/cap_1_0/resource.rb +0 -3
  20. data/lib/rcap/cap_1_1/alert.rb +4 -6
  21. data/lib/rcap/cap_1_1/area.rb +0 -2
  22. data/lib/rcap/cap_1_1/circle.rb +0 -1
  23. data/lib/rcap/cap_1_1/info.rb +120 -129
  24. data/lib/rcap/cap_1_1/parameter.rb +0 -2
  25. data/lib/rcap/cap_1_1/point.rb +0 -1
  26. data/lib/rcap/cap_1_1/polygon.rb +0 -2
  27. data/lib/rcap/cap_1_1/resource.rb +32 -34
  28. data/lib/rcap/cap_1_2/alert.rb +4 -6
  29. data/lib/rcap/cap_1_2/area.rb +0 -2
  30. data/lib/rcap/cap_1_2/circle.rb +0 -1
  31. data/lib/rcap/cap_1_2/info.rb +114 -121
  32. data/lib/rcap/cap_1_2/parameter.rb +0 -2
  33. data/lib/rcap/cap_1_2/point.rb +0 -1
  34. data/lib/rcap/cap_1_2/polygon.rb +1 -3
  35. data/lib/rcap/cap_1_2/resource.rb +32 -34
  36. data/lib/rcap/config.rb +3 -3
  37. data/lib/rcap/custom_validators.rb +72 -76
  38. data/lib/rcap/extensions/array.rb +1 -1
  39. data/lib/rcap/extensions/date.rb +2 -2
  40. data/lib/rcap/extensions/date_time.rb +3 -3
  41. data/lib/rcap/extensions/string.rb +3 -3
  42. data/lib/rcap/extensions/time.rb +2 -3
  43. data/lib/rcap/info.rb +4 -5
  44. data/lib/rcap/utilities.rb +24 -25
  45. data/lib/rcap/validation.rb +19 -20
  46. data/lib/rcap/version.rb +1 -1
  47. data/spec/alert_spec.rb +141 -141
  48. data/spec/cap_1_0/alert_spec.rb +92 -94
  49. data/spec/cap_1_0/area_spec.rb +86 -86
  50. data/spec/cap_1_0/circle_spec.rb +39 -39
  51. data/spec/cap_1_0/event_code_spec.rb +15 -15
  52. data/spec/cap_1_0/geocode_spec.rb +16 -16
  53. data/spec/cap_1_0/info_spec.rb +175 -177
  54. data/spec/cap_1_0/parameter_spec.rb +27 -27
  55. data/spec/cap_1_0/point_spec.rb +18 -18
  56. data/spec/cap_1_0/polygon_spec.rb +38 -38
  57. data/spec/cap_1_0/resource_spec.rb +63 -64
  58. data/spec/cap_1_1/alert_spec.rb +107 -109
  59. data/spec/cap_1_1/area_spec.rb +90 -90
  60. data/spec/cap_1_1/circle_spec.rb +34 -34
  61. data/spec/cap_1_1/event_code_spec.rb +15 -16
  62. data/spec/cap_1_1/geocode_spec.rb +16 -16
  63. data/spec/cap_1_1/info_spec.rb +194 -196
  64. data/spec/cap_1_1/parameter_spec.rb +17 -17
  65. data/spec/cap_1_1/point_spec.rb +18 -18
  66. data/spec/cap_1_1/polygon_spec.rb +36 -36
  67. data/spec/cap_1_1/resource_spec.rb +106 -107
  68. data/spec/cap_1_2/alert_spec.rb +98 -99
  69. data/spec/cap_1_2/area_spec.rb +90 -90
  70. data/spec/cap_1_2/circle_spec.rb +43 -43
  71. data/spec/cap_1_2/event_code_spec.rb +19 -20
  72. data/spec/cap_1_2/geocode_spec.rb +20 -20
  73. data/spec/cap_1_2/info_spec.rb +196 -198
  74. data/spec/cap_1_2/parameter_spec.rb +19 -19
  75. data/spec/cap_1_2/point_spec.rb +21 -21
  76. data/spec/cap_1_2/polygon_spec.rb +47 -47
  77. data/spec/cap_1_2/resource_spec.rb +96 -97
  78. data/spec/extensions_spec.rb +29 -29
  79. data/spec/info_spec.rb +15 -15
  80. data/spec/spec_helper.rb +3 -3
  81. data/spec/validations_spec.rb +73 -73
  82. metadata +2 -2
@@ -1,11 +1,9 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
-
4
3
  # A Parameter object is valid if
5
4
  # * it has a name
6
5
  # * it has a value
7
6
  class Parameter < RCAP::Base::Parameter
8
-
9
7
  # @return [String]
10
8
  def xmlns
11
9
  Alert::XMLNS
@@ -1,6 +1,5 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
-
4
3
  # A Point object is valid if
5
4
  # * it has a lattitude within the minimum and maximum lattitude values
6
5
  # * it has a longitude within the minimum and maximum longitude values
@@ -1,12 +1,10 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
-
4
3
  # A Polygon object is valid if
5
4
  # * it has a minimum of three points
6
5
  # * each Point object in the points collection is valid
7
6
  class Polygon < RCAP::Base::Polygon
8
-
9
- validates_length_of( :points, :minimum => 4 )
7
+ validates_length_of(:points, minimum: 4)
10
8
 
11
9
  # @return [Class]
12
10
  def point_class
@@ -1,15 +1,13 @@
1
1
  module RCAP
2
2
  module CAP_1_2
3
-
4
3
  # A Resource object is valid if
5
4
  # * it has a resource description
6
5
  # * it has a mime_type
7
6
  class Resource < RCAP::Base::Resource
8
-
9
7
  # @return [String] Dereferenced URI - contents of URI Base64 encoded
10
- attr_accessor( :deref_uri )
8
+ attr_accessor(:deref_uri)
11
9
 
12
- validates_presence_of( :mime_type )
10
+ validates_presence_of(:mime_type)
13
11
 
14
12
  DEREF_URI_ELEMENT_NAME = 'derefUri'
15
13
 
@@ -18,13 +16,13 @@ module RCAP
18
16
  # @return [REXML::Element]
19
17
  def to_xml_element
20
18
  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
19
+ xml_element = REXML::Element.new(XML_ELEMENT_NAME)
20
+ xml_element.add_element(RESOURCE_DESC_ELEMENT_NAME).add_text(@resource_desc)
21
+ xml_element.add_element(MIME_TYPE_ELEMENT_NAME).add_text(@mime_type) if @mime_type
22
+ xml_element.add_element(SIZE_ELEMENT_NAME).add_text(@size.to_s) if @size
23
+ xml_element.add_element(URI_ELEMENT_NAME).add_text(@uri) if @uri
24
+ xml_element.add_element(DEREF_URI_ELEMENT_NAME).add_text(@deref_uri) if @deref_uri
25
+ xml_element.add_element(DIGEST_ELEMENT_NAME).add_text(@digest) if @digest
28
26
  xml_element
29
27
  end
30
28
 
@@ -39,9 +37,9 @@ module RCAP
39
37
  #
40
38
  # @return [Array(Integer,String)]
41
39
  def dereference_uri!
42
- content = URI.parse( self.uri ).read
43
- @deref_uri = Base64.encode64( content )
44
- self.calculate_hash_and_size
40
+ content = URI.parse(uri).read
41
+ @deref_uri = Base64.encode64(content)
42
+ calculate_hash_and_size
45
43
  end
46
44
 
47
45
  # @return [String]
@@ -51,31 +49,31 @@ module RCAP
51
49
 
52
50
  # @param [REXML::Element] resource_xml_element
53
51
  # @return [Resource]
54
- def self.from_xml_element( resource_xml_element )
52
+ def self.from_xml_element(resource_xml_element)
55
53
  super.tap do |resource|
56
- resource.deref_uri = RCAP.xpath_text( resource_xml_element, DEREF_URI_XPATH, resource.xmlns )
54
+ resource.deref_uri = RCAP.xpath_text(resource_xml_element, DEREF_URI_XPATH, resource.xmlns)
57
55
  end
58
56
  end
59
57
 
60
- DEREF_URI_YAML = "Derefrenced URI Data"
58
+ DEREF_URI_YAML = 'Derefrenced URI Data'
61
59
 
62
60
  # @param [Hash] options
63
61
  # @return [String]
64
- def to_yaml( options = {} )
62
+ def to_yaml(options = {})
65
63
  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 )
64
+ [RESOURCE_DESC_YAML, @resource_desc],
65
+ [URI_YAML, @uri],
66
+ [MIME_TYPE_YAML, @mime_type],
67
+ [DEREF_URI_YAML, @deref_uri],
68
+ [SIZE_YAML, @size],
69
+ [DIGEST_YAML, @digest]).to_yaml(options)
72
70
  end
73
71
 
74
72
  # @param [Hash] resource_yaml_data
75
73
  # @return [Resource]
76
- def self.from_yaml_data( resource_yaml_data )
74
+ def self.from_yaml_data(resource_yaml_data)
77
75
  super.tap do |resource|
78
- resource.deref_uri = resource_yaml_data[ DEREF_URI_YAML ].strip if resource_yaml_data[ DEREF_URI_YAML ]
76
+ resource.deref_uri = resource_yaml_data[DEREF_URI_YAML].strip if resource_yaml_data[DEREF_URI_YAML]
79
77
  end
80
78
  end
81
79
 
@@ -83,19 +81,19 @@ module RCAP
83
81
 
84
82
  # @return [Hash]
85
83
  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 ])
84
+ RCAP.attribute_values_to_hash([RESOURCE_DESC_KEY, @resource_desc],
85
+ [URI_KEY, @uri],
86
+ [MIME_TYPE_KEY, @mime_type],
87
+ [DEREF_URI_KEY, @deref_uri],
88
+ [SIZE_KEY, @size],
89
+ [DIGEST_KEY, @digest])
92
90
  end
93
91
 
94
92
  # @param [Hash] resource_hash
95
93
  # @return [Resource]
96
- def self.from_h( resource_hash )
94
+ def self.from_h(resource_hash)
97
95
  super.tap do |resource|
98
- resource.deref_uri = resource_hash[ DEREF_URI_KEY ].strip if resource_hash[ DEREF_URI_KEY ]
96
+ resource.deref_uri = resource_hash[DEREF_URI_KEY].strip if resource_hash[DEREF_URI_KEY]
99
97
  end
100
98
  end
101
99
  end
@@ -1,7 +1,7 @@
1
1
  module RCAP
2
- XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new( 2 )
2
+ XML_PRETTY_PRINTER = REXML::Formatters::Pretty.new(2)
3
3
  XML_PRETTY_PRINTER.compact = true
4
4
 
5
- RCAP_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
6
- RCAP_ZONE_FORMAT = "%+03i:00"
5
+ RCAP_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
6
+ RCAP_ZONE_FORMAT = '%+03i:00'
7
7
  end
@@ -1,20 +1,19 @@
1
1
  module Validation
2
2
  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' )
3
+ CAP_NUMBER_REGEX = Regexp.new('^-{0,1}\d*\.{0,1}\d+$')
4
+ CAP_INTEGER_REGEX = Regexp.new('\-{0,1}A[+-]?\d+\Z')
6
5
 
7
6
  # @example
8
7
  # validates_inclusion_of( :status, :in => VALID_STATUSES )
9
- def validates_inclusion_of( *attributes )
8
+ def validates_inclusion_of(*attributes)
10
9
  options = {
11
- :message => 'is not in the required range'
12
- }.merge!( attributes.extract_options! )
10
+ message: 'is not in the required range'
11
+ }.merge!(attributes.extract_options!)
13
12
 
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 ]
13
+ validates_each(*attributes) do |object, attribute, value|
14
+ next if value.nil? && options[:allow_nil]
15
+ unless options[:in].include?(value)
16
+ object.errors[attribute] << options[:message]
18
17
  end
19
18
  end
20
19
  end
@@ -22,134 +21,131 @@ module Validation
22
21
  # Will validate all members of a collection are found in a given collection.
23
22
  # @example
24
23
  # validates_inclusion_of_members_of( :categories, :in => VALID_CATEGORIES )
25
- def validates_inclusion_of_members_of( *attributes )
24
+ def validates_inclusion_of_members_of(*attributes)
26
25
  options = {
27
- :message => 'contains members that are not valid'
28
- }.merge!( attributes.extract_options! )
26
+ message: 'contains members that are not valid'
27
+ }.merge!(attributes.extract_options!)
29
28
 
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 ]
29
+ validates_each(*attributes) do |object, attribute, collection|
30
+ next if ( collection.nil? && options[:allow_nil]) || ( collection.empty? && options[:allow_empty])
31
+ unless collection.all? { |member| options[:in].include?(member) }
32
+ object.errors[attribute] << options[:message]
34
33
  end
35
34
  end
36
35
  end
37
36
 
38
- def validates_length_of_members_of( *attributes )
37
+ def validates_length_of_members_of(*attributes)
39
38
  options = {
40
- :message => 'contains members with incorrect length'
41
- }.merge!( attributes.extract_options! )
39
+ message: 'contains members with incorrect length'
40
+ }.merge!(attributes.extract_options!)
42
41
 
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 ]
42
+ validates_each(*attributes) do |object, attribute, collection|
43
+ next if ( collection.nil? && options[:allow_nil]) || ( collection.empty? && options[:allow_empty])
44
+ unless options[:minimum] && collection.length >= options[:minimum]
45
+ object.errors[attribute] << options[:message]
47
46
  end
48
47
  end
49
48
  end
50
49
 
51
- def validates_validity_of( *attributes )
50
+ def validates_validity_of(*attributes)
52
51
  options = {
53
- :message => 'is not valid'
54
- }.merge!( attributes.extract_options! )
52
+ message: 'is not valid'
53
+ }.merge!(attributes.extract_options!)
55
54
 
56
- validates_each( *attributes ) do |object, attribute, value|
57
- next if ( value.nil? && options[ :allow_nil ])
55
+ validates_each(*attributes) do |object, attribute, value|
56
+ next if value.nil? && options[:allow_nil]
58
57
  unless value && value.valid?
59
- object.errors[ attribute ] << options[ :message ]
58
+ object.errors[attribute] << options[:message]
60
59
  end
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? { |element| element.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]
148
145
  unless collection.first == collection.last
149
- object.errors[ attribute ] << options[ :message ]
146
+ object.errors[attribute] << options[:message]
150
147
  end
151
148
  end
152
149
  end
153
150
  end
154
151
  end
155
-
@@ -6,7 +6,7 @@ class Array
6
6
  # [ "one", "two words", "three" ].to_s_for_cap # => "one \"two words\" three"
7
7
  # @see String#unpack_cap_list
8
8
  def to_s_for_cap
9
- self.map{ |element| element.to_s.for_cap_list }.join( ' ' )
9
+ map { |element| element.to_s.for_cap_list }.join(' ')
10
10
  end
11
11
 
12
12
  def blank?
@@ -1,11 +1,11 @@
1
1
  class Date
2
- alias inspect to_s
2
+ alias_method :inspect, :to_s
3
3
 
4
4
  # Returns a string representaion of the time suitable for CAP.
5
5
  # @return [String]
6
6
  # @example
7
7
  # Date.today.to_s_for_cap # => "2011-10-26T00:00:00+00:00"
8
8
  def to_s_for_cap
9
- self.to_datetime.to_s_for_cap
9
+ to_datetime.to_s_for_cap
10
10
  end
11
11
  end
@@ -1,12 +1,12 @@
1
1
  class DateTime
2
- alias inspect to_s
2
+ alias_method :inspect, :to_s
3
3
 
4
4
  # Returns a string representaion of the time suitable for CAP.
5
5
  # @return [String]
6
6
  # @example
7
7
  # DateTime.now.to_s_for_cap # => "2011-10-26T21:45:00+02:00"
8
8
  def to_s_for_cap
9
- t = self.strftime( RCAP::RCAP_TIME_FORMAT ) + format( RCAP::RCAP_ZONE_FORMAT , utc_hours_offset )
9
+ t = strftime(RCAP::RCAP_TIME_FORMAT) + format(RCAP::RCAP_ZONE_FORMAT, utc_hours_offset)
10
10
  t.sub(/\+(00:\d\d)$/, '-\1')
11
11
  end
12
12
 
@@ -16,6 +16,6 @@ class DateTime
16
16
 
17
17
  private
18
18
  def utc_hours_offset
19
- self.offset * 24
19
+ offset * 24
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  class String
2
- CAP_LIST_REGEX = Regexp.new( '"([\w\s]+)"|(\S+)' )
2
+ CAP_LIST_REGEX = Regexp.new('"([\w\s]+)"|(\S+)')
3
3
  WHITESPACE_REGEX = Regexp.new('^\s+$')
4
4
 
5
5
  # Reformats string for a CAP list. If the string contains whitespace it will
@@ -11,7 +11,7 @@ class String
11
11
  # "two words".for_cap_list # => "\"two words\""
12
12
  def for_cap_list
13
13
  if self =~ /\s/
14
- '"'+self+'"'
14
+ '"' + self + '"'
15
15
  else
16
16
  self
17
17
  end
@@ -24,7 +24,7 @@ class String
24
24
  # "one \"two words\" three".unpack_cap_list # => [ "one", "two words", "three" ]
25
25
  # @see Array#to_s_for_cap
26
26
  def unpack_cap_list
27
- self.split( CAP_LIST_REGEX ).reject{ |match| match == "" || match =~ WHITESPACE_REGEX }
27
+ split(CAP_LIST_REGEX).reject { |match| match == '' || match =~ WHITESPACE_REGEX }
28
28
  end
29
29
 
30
30
  def blank?