rcap 1.0.0.rc.1 → 1.0.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -8
- data/lib/rcap/cap_1_1/circle.rb +1 -1
- data/lib/rcap/cap_1_1/point.rb +2 -2
- data/lib/rcap/cap_1_2/circle.rb +1 -1
- data/lib/rcap/cap_1_2/point.rb +2 -2
- data/lib/rcap/validations.rb +3 -2
- data/lib/rcap/version.rb +1 -1
- data/spec/validations_spec.rb +32 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -8,7 +8,7 @@ RCAP currently supports CAP 1.1 and 1.2.
|
|
8
8
|
|
9
9
|
== Version
|
10
10
|
|
11
|
-
1.0
|
11
|
+
1.0.0 RC 1
|
12
12
|
|
13
13
|
== Dependencies
|
14
14
|
|
@@ -47,10 +47,12 @@ All RCAP classes reside in the RCAP namespace but including the RCAP module make
|
|
47
47
|
|
48
48
|
=== Creating an Alert
|
49
49
|
|
50
|
-
alert = Alert.new(
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
alert = Alert.new( identifier: RCAP.generate_identifier,
|
51
|
+
sent: DateTime.now,
|
52
|
+
sender: 'cape_town_disaster_relief@capetown.municipal.za',
|
53
|
+
status: Alert::STATUS_ACTUAL,
|
54
|
+
msg_type: Alert::MSG_TYPE_ALERT,
|
55
|
+
scope: Alert::SCOPE_PUBLIC )
|
54
56
|
|
55
57
|
alert.add_info( event: 'Liquid Petroleoum Tanker Fire',
|
56
58
|
language: 'en-ZA',
|
@@ -70,7 +72,7 @@ All RCAP classes reside in the RCAP namespace but including the RCAP module make
|
|
70
72
|
alert.status # "Actual"
|
71
73
|
alert.infos[0].language # "en-ZA"
|
72
74
|
alert.infos[0].categories.join( ', ' ) # "Transport, Fire"
|
73
|
-
alert.infos[0].areas[0]
|
75
|
+
alert.infos[0].areas[0] # "N2 Highway/R300 Interchange"
|
74
76
|
|
75
77
|
=== Parsing an Alert From An External Source
|
76
78
|
|
@@ -86,7 +88,7 @@ RCAP allows for the parsing of a CAP XML string
|
|
86
88
|
|
87
89
|
==== From YAML
|
88
90
|
|
89
|
-
Alert messgaes can be read in from text files containing data formatted in YAML[http://yaml.org] as generated by Alert#to_yaml.
|
91
|
+
Alert messgaes can be read in from text files containing data formatted in YAML[http://yaml.org] as generated by RCAP::CAP_1_2::Alert#to_yaml.
|
90
92
|
|
91
93
|
alert = RCAP::Alert.from_yaml( yaml_string )
|
92
94
|
|
@@ -110,7 +112,7 @@ The RCAP API aims to codify as many of the rules of the CAP XML format into vali
|
|
110
112
|
puts "Is info valid: #{ info.valid? }"
|
111
113
|
info.errors.full_messages.each{ |message| puts "Error: #{ message }" }
|
112
114
|
|
113
|
-
Will produce the
|
115
|
+
Will produce the following output:
|
114
116
|
|
115
117
|
Is info valid: false
|
116
118
|
Error: severity is not present
|
data/lib/rcap/cap_1_1/circle.rb
CHANGED
data/lib/rcap/cap_1_1/point.rb
CHANGED
@@ -38,8 +38,8 @@ module RCAP
|
|
38
38
|
[ self.lattitude, self.longitude ] == [ other.lattitude, other.longitude ]
|
39
39
|
end
|
40
40
|
|
41
|
-
LATTITUDE_KEY = '
|
42
|
-
LONGITUDE_KEY = '
|
41
|
+
LATTITUDE_KEY = 'lattitude' # :nodoc:
|
42
|
+
LONGITUDE_KEY = 'longitude' # :nodoc:
|
43
43
|
|
44
44
|
def to_h # :nodoc:
|
45
45
|
RCAP.attribute_values_to_hash(
|
data/lib/rcap/cap_1_2/circle.rb
CHANGED
data/lib/rcap/cap_1_2/point.rb
CHANGED
@@ -38,8 +38,8 @@ module RCAP
|
|
38
38
|
[ self.lattitude, self.longitude ] == [ other.lattitude, other.longitude ]
|
39
39
|
end
|
40
40
|
|
41
|
-
LATTITUDE_KEY = '
|
42
|
-
LONGITUDE_KEY = '
|
41
|
+
LATTITUDE_KEY = 'lattitude' # :nodoc:
|
42
|
+
LONGITUDE_KEY = 'longitude' # :nodoc:
|
43
43
|
|
44
44
|
def to_h # :nodoc:
|
45
45
|
RCAP.attribute_values_to_hash(
|
data/lib/rcap/validations.rb
CHANGED
@@ -104,7 +104,7 @@ module Validation # :nodoc:
|
|
104
104
|
|
105
105
|
def validates_numericality_of( *attributes )
|
106
106
|
options = {
|
107
|
-
:message => 'is not a number',
|
107
|
+
:message => 'is not a number or does not meet a conditional requirement',
|
108
108
|
}.merge!(attributes.extract_options!)
|
109
109
|
|
110
110
|
re = options[:only_integer] ? CAP_INTEGER_REGEX : CAP_NUMBER_REGEX
|
@@ -112,7 +112,8 @@ module Validation # :nodoc:
|
|
112
112
|
validates_each( *attributes ) do |object, attribute, value|
|
113
113
|
next if (value.nil? && options[ :allow_nil ]) || (value.blank? && options[ :allow_blank ])
|
114
114
|
unless ( value.to_s =~ re ) &&
|
115
|
-
( options[ :greater_than ].nil? || value && value > options[ :greater_than ])
|
115
|
+
( options[ :greater_than ].nil? || value && value > options[ :greater_than ]) &&
|
116
|
+
( options[ :greater_than_or_equal ].nil? || value && value >= options[ :greater_than_or_equal])
|
116
117
|
object.errors[ attribute ] << options[ :message ]
|
117
118
|
end
|
118
119
|
end
|
data/lib/rcap/version.rb
CHANGED
data/spec/validations_spec.rb
CHANGED
@@ -33,6 +33,14 @@ class ConditionalPresenceIsObject
|
|
33
33
|
validates_conditional_presence_of( :dependent_value, when: :contingent_value, is: 1 )
|
34
34
|
end
|
35
35
|
|
36
|
+
class NumericalityObject
|
37
|
+
include Validation
|
38
|
+
attr_accessor( :gt, :gte )
|
39
|
+
|
40
|
+
validates_numericality_of( :gt, greater_than: 0 )
|
41
|
+
validates_numericality_of( :gte, greater_than_or_equal: 0 )
|
42
|
+
end
|
43
|
+
|
36
44
|
describe( Validation::ClassMethods ) do
|
37
45
|
describe( 'validates_collection_of' ) do
|
38
46
|
before( :each ) do
|
@@ -165,4 +173,28 @@ describe( Validation::ClassMethods ) do
|
|
165
173
|
end
|
166
174
|
end
|
167
175
|
end
|
176
|
+
|
177
|
+
describe( 'validates_numericality_of' ) do
|
178
|
+
before( :each ) do
|
179
|
+
@object = NumericalityObject.new
|
180
|
+
@object.gt = 1
|
181
|
+
@object.gte = 0
|
182
|
+
@object.should( be_valid )
|
183
|
+
end
|
184
|
+
|
185
|
+
it( 'should not be valid with a non-numerical value' ) do
|
186
|
+
@object.gt = 'one'
|
187
|
+
@object.should_not( be_valid )
|
188
|
+
end
|
189
|
+
|
190
|
+
it( 'should not be valid if set :greater_than is false' ) do
|
191
|
+
@object.gt = 0
|
192
|
+
@object.should_not( be_valid )
|
193
|
+
end
|
194
|
+
|
195
|
+
it( 'should not be valid if set :greater_than_or_equal is false' ) do
|
196
|
+
@object.gte = -1
|
197
|
+
@object.should_not( be_valid )
|
198
|
+
end
|
199
|
+
end
|
168
200
|
end
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- rc
|
10
|
-
-
|
11
|
-
version: 1.0.0.rc.
|
10
|
+
- 2
|
11
|
+
version: 1.0.0.rc.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Farrel Lifson
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-04-
|
19
|
+
date: 2011-04-04 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|