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
@@ -4,21 +4,21 @@ module RCAP
4
4
  include Validation
5
5
 
6
6
  # @return [String] Textual description of area.
7
- attr_accessor( :area_desc )
7
+ attr_accessor(:area_desc)
8
8
  # @return [Numeric] Expressed in feet above sea level
9
- attr_accessor( :altitude )
9
+ attr_accessor(:altitude)
10
10
  # @return [Numeric] Expressed in feet above sea level.
11
- attr_accessor( :ceiling )
11
+ attr_accessor(:ceiling)
12
12
  # @return [Array<Circle>]
13
- attr_reader( :circles )
13
+ attr_reader(:circles)
14
14
  # @return [Array<Geocode>]
15
- attr_reader( :geocodes )
15
+ attr_reader(:geocodes)
16
16
  # @return [Array<Polygon>]
17
- attr_reader( :polygons )
17
+ attr_reader(:polygons)
18
18
 
19
- validates_presence_of( :area_desc )
20
- validates_collection_of( :circles, :geocodes, :polygons, allow_empty: true )
21
- validates_dependency_of( :ceiling, on: :altitude )
19
+ validates_presence_of(:area_desc)
20
+ validates_collection_of(:circles, :geocodes, :polygons, allow_empty: true)
21
+ validates_dependency_of(:ceiling, on: :altitude)
22
22
 
23
23
  XML_ELEMENT_NAME = 'area'
24
24
  AREA_DESC_ELEMENT_NAME = 'areaDesc'
@@ -42,15 +42,15 @@ module RCAP
42
42
  @circles = []
43
43
  @geocodes = []
44
44
  @polygons = []
45
- yield( self ) if block_given?
45
+ yield(self) if block_given?
46
46
  end
47
47
 
48
48
  # Creates a new {Polygon} object and adds it to the {#polygons} array.
49
49
  #
50
50
  # @return [Polygon]
51
51
  def add_polygon
52
- self.polygon_class.new.tap do |polygon|
53
- yield( polygon ) if block_given?
52
+ polygon_class.new.tap do |polygon|
53
+ yield(polygon) if block_given?
54
54
  @polygons << polygon
55
55
  end
56
56
  end
@@ -59,8 +59,8 @@ module RCAP
59
59
  #
60
60
  # @return [Circle]
61
61
  def add_circle
62
- self.circle_class.new.tap do |circle|
63
- yield( circle ) if block_given?
62
+ circle_class.new.tap do |circle|
63
+ yield(circle) if block_given?
64
64
  @circles << circle
65
65
  end
66
66
  end
@@ -69,70 +69,69 @@ module RCAP
69
69
  #
70
70
  # @return [Geocode]
71
71
  def add_geocode
72
- self.geocode_class.new do |geocode|
73
- yield( geocode ) if block_given?
72
+ geocode_class.new do |geocode|
73
+ yield(geocode) if block_given?
74
74
  @geocodes << geocode
75
75
  end
76
76
  end
77
77
 
78
- def self.from_xml_element( area_xml_element )
79
- self.new do |area|
80
- area.area_desc = RCAP.xpath_text( area_xml_element, AREA_DESC_XPATH, area.xmlns )
81
- area.altitude = RCAP.to_f_if_given( RCAP.xpath_text( area_xml_element, ALTITUDE_XPATH, area.xmlns ))
82
- area.ceiling = RCAP.to_f_if_given( RCAP.xpath_text( area_xml_element, CEILING_XPATH, area.xmlns ))
78
+ def self.from_xml_element(area_xml_element)
79
+ new do |area|
80
+ area.area_desc = RCAP.xpath_text(area_xml_element, AREA_DESC_XPATH, area.xmlns)
81
+ area.altitude = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, ALTITUDE_XPATH, area.xmlns))
82
+ area.ceiling = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, CEILING_XPATH, area.xmlns))
83
83
 
84
- RCAP.xpath_match( area_xml_element, area.circle_class::XPATH, area.xmlns ).each do |circle_element|
85
- area.circles << area.circle_class.from_xml_element( circle_element )
84
+ RCAP.xpath_match(area_xml_element, area.circle_class::XPATH, area.xmlns).each do |circle_element|
85
+ area.circles << area.circle_class.from_xml_element(circle_element)
86
86
  end
87
87
 
88
- RCAP.xpath_match( area_xml_element, area.geocode_class::XPATH, area.xmlns ).each do |geocode_element|
89
- area.geocodes << area.geocode_class.from_xml_element( geocode_element )
88
+ RCAP.xpath_match(area_xml_element, area.geocode_class::XPATH, area.xmlns).each do |geocode_element|
89
+ area.geocodes << area.geocode_class.from_xml_element(geocode_element)
90
90
  end
91
91
 
92
- RCAP.xpath_match( area_xml_element, area.polygon_class::XPATH, area.xmlns ).each do |polygon_element|
93
- area.polygons << area.polygon_class.from_xml_element( polygon_element )
92
+ RCAP.xpath_match(area_xml_element, area.polygon_class::XPATH, area.xmlns).each do |polygon_element|
93
+ area.polygons << area.polygon_class.from_xml_element(polygon_element)
94
94
  end
95
95
  end
96
96
  end
97
97
 
98
98
  # @return [REXML::Element]
99
99
  def to_xml_element
100
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
101
- xml_element.add_element( AREA_DESC_ELEMENT_NAME ).add_text( @area_desc.to_s )
102
- add_to_xml_element = lambda do |element, object|
103
- element.add_element( object.to_xml_element )
104
- element
100
+ REXML::Element.new(XML_ELEMENT_NAME).tap do |xml_element|
101
+ xml_element.add_element(AREA_DESC_ELEMENT_NAME).add_text(@area_desc.to_s)
102
+ add_to_xml_element = lambda do |element, object|
103
+ element.add_element(object.to_xml_element)
104
+ element
105
+ end
106
+ @polygons.inject(xml_element, &add_to_xml_element)
107
+ @circles.inject(xml_element, &add_to_xml_element)
108
+ @geocodes.inject(xml_element, &add_to_xml_element)
109
+ xml_element.add_element(ALTITUDE_ELEMENT_NAME).add_text(@altitude.to_s) unless @altitude.blank?
110
+ xml_element.add_element(CEILING_ELEMENT_NAME).add_text(@ceiling.to_s) unless @altitude.blank?
105
111
  end
106
- @polygons.inject( xml_element, &add_to_xml_element )
107
- @circles.inject( xml_element, &add_to_xml_element )
108
- @geocodes.inject( xml_element, &add_to_xml_element )
109
- xml_element.add_element( ALTITUDE_ELEMENT_NAME ).add_text( @altitude.to_s ) unless @altitude.blank?
110
- xml_element.add_element( CEILING_ELEMENT_NAME ).add_text( @ceiling.to_s ) unless @altitude.blank?
111
- xml_element
112
112
  end
113
113
 
114
114
  # @return [String] XML representation of the Area
115
115
  def to_xml
116
- self.to_xml_element.to_s
116
+ to_xml_element.to_s
117
117
  end
118
118
 
119
119
  # Implements an equality operator for the Area object. Two Area objects are equal if all their attributes are equal.
120
120
  #
121
121
  # @param [Area] other Area object to compare
122
122
  # @return [true,false]
123
- def ==( other )
124
- comparison_attributes = lambda{ |area| [ area.area_desc, area.altitude, area.ceiling, area.circles, area.geocodes, area.polygons ]}
125
- comparison_attributes.call( self ) == comparison_attributes.call( other )
123
+ def ==(other)
124
+ comparison_attributes = lambda { |area| [area.area_desc, area.altitude, area.ceiling, area.circles, area.geocodes, area.polygons] }
125
+ comparison_attributes.call(self) == comparison_attributes.call(other)
126
126
  end
127
127
 
128
128
  # @return [String]
129
129
  def inspect
130
- area_inspect = "Area Description: #{ @area_desc }\n"+
131
- "Polygons:\n"+
132
- @polygons.map{ |polygon| " " + polygon.inspect }.join("\n" )+"\n"+
133
- "Circles: #{ @circles.inspect }\n"+
130
+ area_inspect = "Area Description: #{ @area_desc }\n"\
131
+ "Polygons:\n" + @polygons.map { |polygon| ' ' + polygon.inspect }.join("\n") + "\n"\
132
+ "Circles: #{ @circles.inspect }\n"\
134
133
  "Geocodes: #{ @geocodes.inspect }\n"
135
- RCAP.format_lines_for_inspect( 'AREA', area_inspect )
134
+ RCAP.format_lines_for_inspect('AREA', area_inspect)
136
135
  end
137
136
 
138
137
  # Returns the area description
@@ -142,7 +141,6 @@ module RCAP
142
141
  @area_desc
143
142
  end
144
143
 
145
-
146
144
  AREA_DESC_YAML = 'Area Description'
147
145
  ALTITUDE_YAML = 'Altitude'
148
146
  CEILING_YAML = 'Ceiling'
@@ -150,42 +148,42 @@ module RCAP
150
148
  GEOCODES_YAML = 'Geocodes'
151
149
  POLYGONS_YAML = 'Polygons'
152
150
 
153
- # @return [Hash]
151
+ # @return [Hash]
154
152
  def to_yaml_data
155
- RCAP.attribute_values_to_hash( [ AREA_DESC_YAML, @area_desc ],
156
- [ ALTITUDE_YAML, @altitude ],
157
- [ CEILING_YAML, @ceiling ],
158
- [ CIRCLES_YAML, @circles.map{ |circle| circle.to_a }],
159
- [ GEOCODES_YAML, @geocodes.inject({}){|h,geocode| h.merge( geocode.name => geocode.value )}],
160
- [ POLYGONS_YAML, @polygons.map( &:to_yaml_data )])
153
+ RCAP.attribute_values_to_hash([AREA_DESC_YAML, @area_desc],
154
+ [ALTITUDE_YAML, @altitude],
155
+ [CEILING_YAML, @ceiling],
156
+ [CIRCLES_YAML, @circles.map { |circle| circle.to_a }],
157
+ [GEOCODES_YAML, @geocodes.reduce({}) { |h, geocode| h.merge(geocode.name => geocode.value) }],
158
+ [POLYGONS_YAML, @polygons.map(&:to_yaml_data)])
161
159
  end
162
160
 
163
161
  # @return [String] YAML representation of object
164
- def to_yaml( options = {} )
165
- self.to_yaml_data.to_yaml( options )
162
+ def to_yaml(options = {})
163
+ to_yaml_data.to_yaml(options)
166
164
  end
167
165
 
168
166
  # @param [Hash] area_yaml_data
169
167
  # @return [Area]
170
- def self.from_yaml_data( area_yaml_data )
171
- self.new do |area|
172
- area.area_desc = area_yaml_data[ AREA_DESC_YAML ]
173
- area.altitude = area_yaml_data[ ALTITUDE_YAML ]
174
- area.ceiling = area_yaml_data[ CEILING_YAML ]
175
-
176
- Array( area_yaml_data[ CIRCLES_YAML ]).each do |circle_yaml_data|
177
- area.circles << area.circle_class.from_yaml_data( circle_yaml_data )
168
+ def self.from_yaml_data(area_yaml_data)
169
+ new do |area|
170
+ area.area_desc = area_yaml_data[AREA_DESC_YAML]
171
+ area.altitude = area_yaml_data[ALTITUDE_YAML]
172
+ area.ceiling = area_yaml_data[CEILING_YAML]
173
+
174
+ Array(area_yaml_data[CIRCLES_YAML]).each do |circle_yaml_data|
175
+ area.circles << area.circle_class.from_yaml_data(circle_yaml_data)
178
176
  end
179
177
 
180
- Array( area_yaml_data[ GEOCODES_YAML ]).each do |name, value|
178
+ Array(area_yaml_data[GEOCODES_YAML]).each do |name, value|
181
179
  area.add_geocode do |geocode|
182
180
  geocode.name = name
183
181
  geocode.value = value
184
182
  end
185
183
  end
186
184
 
187
- Array( area_yaml_data[ POLYGONS_YAML ]).each do |polyon_yaml_data|
188
- area.polygons << area.polygon_class.from_yaml_data( polyon_yaml_data )
185
+ Array(area_yaml_data[POLYGONS_YAML]).each do |polyon_yaml_data|
186
+ area.polygons << area.polygon_class.from_yaml_data(polyon_yaml_data)
189
187
  end
190
188
  end
191
189
  end
@@ -199,34 +197,34 @@ module RCAP
199
197
 
200
198
  # @param [Hash] area_hash
201
199
  # @return [Area]
202
- def self.from_h( area_hash )
203
- self.new do |area|
204
- area.area_desc = area_hash[ AREA_DESC_KEY ]
205
- area.altitude = area_hash[ ALTITUDE_KEY ]
206
- area.ceiling = area_hash[ CEILING_KEY ]
207
-
208
- Array( area_hash[ CIRCLES_KEY ]).each do |circle_array|
209
- area.circles << area.circle_class.from_a( circle_array )
200
+ def self.from_h(area_hash)
201
+ new do |area|
202
+ area.area_desc = area_hash[AREA_DESC_KEY]
203
+ area.altitude = area_hash[ALTITUDE_KEY]
204
+ area.ceiling = area_hash[CEILING_KEY]
205
+
206
+ Array(area_hash[CIRCLES_KEY]).each do |circle_array|
207
+ area.circles << area.circle_class.from_a(circle_array)
210
208
  end
211
209
 
212
- Array( area_hash[ GEOCODES_KEY ]).each do |geocode_hash|
213
- area.geocodes << area.geocode_class.from_h( geocode_hash )
210
+ Array(area_hash[GEOCODES_KEY]).each do |geocode_hash|
211
+ area.geocodes << area.geocode_class.from_h(geocode_hash)
214
212
  end
215
213
 
216
- Array( area_hash[ POLYGONS_KEY ]).each do |polygon_hash|
217
- area.polygons << area.polygon_class.from_h( polygon_hash )
214
+ Array(area_hash[POLYGONS_KEY]).each do |polygon_hash|
215
+ area.polygons << area.polygon_class.from_h(polygon_hash)
218
216
  end
219
217
  end
220
218
  end
221
219
 
222
220
  # @return [Hash]
223
221
  def to_h
224
- RCAP.attribute_values_to_hash( [ AREA_DESC_KEY, @area_desc ],
225
- [ ALTITUDE_KEY, @altitude ],
226
- [ CEILING_KEY, @ceiling ],
227
- [ CIRCLES_KEY, @circles.map{ |circle| circle.to_a }],
228
- [ GEOCODES_KEY, @geocodes.map{ |geocode| geocode.to_h }],
229
- [ POLYGONS_KEY, @polygons.map{ |polygon| polygon.to_h }])
222
+ RCAP.attribute_values_to_hash([AREA_DESC_KEY, @area_desc],
223
+ [ALTITUDE_KEY, @altitude],
224
+ [CEILING_KEY, @ceiling],
225
+ [CIRCLES_KEY, @circles.map { |circle| circle.to_a }],
226
+ [GEOCODES_KEY, @geocodes.map { |geocode| geocode.to_h }],
227
+ [POLYGONS_KEY, @polygons.map { |polygon| polygon.to_h }])
230
228
  end
231
229
  end
232
230
  end
@@ -4,10 +4,10 @@ module RCAP
4
4
  include Validation
5
5
 
6
6
  # @return [Numeric] Expresed in kilometers
7
- attr_accessor( :radius )
7
+ attr_accessor(:radius)
8
8
 
9
- validates_presence_of( :radius )
10
- validates_numericality_of( :radius , greater_than_or_equal: 0 )
9
+ validates_presence_of(:radius)
10
+ validates_numericality_of(:radius, greater_than_or_equal: 0)
11
11
 
12
12
  XML_ELEMENT_NAME = 'circle'
13
13
 
@@ -18,7 +18,7 @@ module RCAP
18
18
  # @option attributes [Numeric] :longitude
19
19
  # @option attributes [Numeric] :radius
20
20
  def initialize
21
- yield( self ) if block_given?
21
+ yield(self) if block_given?
22
22
  end
23
23
 
24
24
  # Returns a string representation of the circle of the form
@@ -31,19 +31,19 @@ module RCAP
31
31
 
32
32
  # @return [String]
33
33
  def inspect
34
- "(#{ self.to_s })"
34
+ "(#{ self })"
35
35
  end
36
36
 
37
37
  # @return [REXML::Element]
38
38
  def to_xml_element
39
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
40
- xml_element.add_text( self.to_s )
39
+ xml_element = REXML::Element.new(XML_ELEMENT_NAME)
40
+ xml_element.add_text(to_s)
41
41
  xml_element
42
42
  end
43
43
 
44
44
  # @return [String]
45
45
  def to_xml
46
- self.to_xml_element.to_s
46
+ to_xml_element.to_s
47
47
  end
48
48
 
49
49
  # Parses a circle string of the form
@@ -51,31 +51,31 @@ module RCAP
51
51
  #
52
52
  # @param [String] circle_string
53
53
  # @return [Array(Float,Float,Float)]
54
- def self.parse_circle_string( circle_string )
55
- coordinates, radius = circle_string.split( ' ' )
56
- lattitude, longitude = coordinates.split( ',' )
57
- [ lattitude, longitude, radius ].map{ |e| e.to_f }
54
+ def self.parse_circle_string(circle_string)
55
+ coordinates, radius = circle_string.split(' ')
56
+ lattitude, longitude = coordinates.split(',')
57
+ [lattitude, longitude, radius].map { |e| e.to_f }
58
58
  end
59
59
 
60
60
  # @param [REXML::Element] circle_xml_element
61
61
  # @return [Circle]
62
- def self.from_xml_element( circle_xml_element )
63
- self.from_a( self.parse_circle_string( circle_xml_element.text ))
62
+ def self.from_xml_element(circle_xml_element)
63
+ from_a(parse_circle_string(circle_xml_element.text))
64
64
  end
65
65
 
66
66
  # Two circles are equivalent if their lattitude, longitude and radius are equal.
67
67
  #
68
68
  # @param [Circle] other
69
69
  # @return [true,false]
70
- def ==( other )
71
- self.to_a == other.to_a
70
+ def ==(other)
71
+ to_a == other.to_a
72
72
  end
73
73
 
74
74
  # @param [Array(Numeric, Numeric, Numeric)] circle_yaml_data lattitude, longitude, radius
75
75
  # @return [Circle]
76
- def self.from_yaml_data( circle_yaml_data )
76
+ def self.from_yaml_data(circle_yaml_data)
77
77
  lattitude, longitude, radius = circle_yaml_data
78
- self.new do |circle|
78
+ new do |circle|
79
79
  circle.lattitude = lattitude.to_f
80
80
  circle.longitude = longitude.to_f
81
81
  circle.radius = radius.to_f
@@ -85,35 +85,35 @@ module RCAP
85
85
  RADIUS_KEY = 'radius'
86
86
  # @return [Hash]
87
87
  def to_h
88
- RCAP.attribute_values_to_hash( [ RADIUS_KEY, @radius ],
89
- [ LATTITUDE_KEY, @lattitude ],
90
- [ LONGITUDE_KEY, @longitude ])
88
+ RCAP.attribute_values_to_hash([RADIUS_KEY, @radius],
89
+ [LATTITUDE_KEY, @lattitude],
90
+ [LONGITUDE_KEY, @longitude])
91
91
  end
92
92
 
93
93
  # @param [Hash] circle_hash
94
94
  # @return [Circle]
95
- def self.from_h( circle_hash )
96
- self.new do |circle|
97
- circle.radius = circle_hash[ RADIUS_KEY ].to_f
98
- circle.lattitude = circle_hash[ LATTITUDE_KEY ].to_f
99
- circle.longitude = circle_hash[ LONGITUDE_KEY ].to_f
95
+ def self.from_h(circle_hash)
96
+ new do |circle|
97
+ circle.radius = circle_hash[RADIUS_KEY].to_f
98
+ circle.lattitude = circle_hash[LATTITUDE_KEY].to_f
99
+ circle.longitude = circle_hash[LONGITUDE_KEY].to_f
100
100
  end
101
101
  end
102
102
 
103
103
  # @return [Array(Numeric,Numeric,Numeric)]
104
104
  def to_a
105
- [ @lattitude, @longitude, @radius ]
105
+ [@lattitude, @longitude, @radius]
106
106
  end
107
107
 
108
108
  RADIUS_INDEX = 2
109
109
 
110
110
  # @param [Array] circle_array
111
111
  # @return [Circle]
112
- def self.from_a( circle_array )
113
- self.new do |circle|
114
- circle.longitude = circle_array[ LONGITUDE_INDEX ].to_f
115
- circle.lattitude = circle_array[ LATTITUDE_INDEX ].to_f
116
- circle.radius = circle_array[ RADIUS_INDEX ].to_f
112
+ def self.from_a(circle_array)
113
+ new do |circle|
114
+ circle.longitude = circle_array[LONGITUDE_INDEX].to_f
115
+ circle.lattitude = circle_array[LATTITUDE_INDEX].to_f
116
+ circle.radius = circle_array[RADIUS_INDEX].to_f
117
117
  end
118
118
  end
119
119
  end
@@ -3,50 +3,50 @@ module RCAP
3
3
  class Info
4
4
  include Validation
5
5
 
6
- CATEGORY_GEO = "Geo"
7
- CATEGORY_MET = "Met"
8
- CATEGORY_SAFETY = "Safety"
9
- CATEGORY_SECURITY = "Security"
10
- CATEGORY_RESCUE = "Rescue"
11
- CATEGORY_FIRE = "Fire"
12
- CATEGORY_HEALTH = "Health"
13
- CATEGORY_ENV = "Env"
14
- CATEGORY_TRANSPORT = "Transport"
15
- CATEGORY_INFRA = "Infra"
16
- CATEGORY_CBRNE = "CBRNE"
17
- CATEGORY_OTHER = "Other"
6
+ CATEGORY_GEO = 'Geo'
7
+ CATEGORY_MET = 'Met'
8
+ CATEGORY_SAFETY = 'Safety'
9
+ CATEGORY_SECURITY = 'Security'
10
+ CATEGORY_RESCUE = 'Rescue'
11
+ CATEGORY_FIRE = 'Fire'
12
+ CATEGORY_HEALTH = 'Health'
13
+ CATEGORY_ENV = 'Env'
14
+ CATEGORY_TRANSPORT = 'Transport'
15
+ CATEGORY_INFRA = 'Infra'
16
+ CATEGORY_CBRNE = 'CBRNE'
17
+ CATEGORY_OTHER = 'Other'
18
18
  # Valid values for categories
19
- VALID_CATEGORIES = [ CATEGORY_GEO, CATEGORY_MET, CATEGORY_SAFETY,
20
- CATEGORY_SECURITY, CATEGORY_RESCUE, CATEGORY_FIRE, CATEGORY_HEALTH,
21
- CATEGORY_ENV, CATEGORY_TRANSPORT, CATEGORY_INFRA, CATEGORY_CBRNE,
22
- CATEGORY_OTHER ]
23
-
24
- URGENCY_IMMEDIATE = "Immediate"
25
- URGENCY_EXPECTED = "Expected"
26
- URGENCY_FUTURE = "Future"
27
- URGENCY_PAST = "Past"
28
- URGENCY_UNKNOWN = "Unknown"
19
+ VALID_CATEGORIES = [CATEGORY_GEO, CATEGORY_MET, CATEGORY_SAFETY,
20
+ CATEGORY_SECURITY, CATEGORY_RESCUE, CATEGORY_FIRE, CATEGORY_HEALTH,
21
+ CATEGORY_ENV, CATEGORY_TRANSPORT, CATEGORY_INFRA, CATEGORY_CBRNE,
22
+ CATEGORY_OTHER]
23
+
24
+ URGENCY_IMMEDIATE = 'Immediate'
25
+ URGENCY_EXPECTED = 'Expected'
26
+ URGENCY_FUTURE = 'Future'
27
+ URGENCY_PAST = 'Past'
28
+ URGENCY_UNKNOWN = 'Unknown'
29
29
  # Valid values for urgency
30
- VALID_URGENCIES = [ URGENCY_IMMEDIATE, URGENCY_EXPECTED, URGENCY_FUTURE,
31
- URGENCY_PAST, URGENCY_UNKNOWN ]
32
-
33
- SEVERITY_EXTREME = "Extreme"
34
- SEVERITY_SEVERE = "Severe"
35
- SEVERITY_MODERATE = "Moderate"
36
- SEVERITY_MINOR = "Minor"
37
- SEVERITY_UNKNOWN = "Unknown"
30
+ VALID_URGENCIES = [URGENCY_IMMEDIATE, URGENCY_EXPECTED, URGENCY_FUTURE,
31
+ URGENCY_PAST, URGENCY_UNKNOWN]
32
+
33
+ SEVERITY_EXTREME = 'Extreme'
34
+ SEVERITY_SEVERE = 'Severe'
35
+ SEVERITY_MODERATE = 'Moderate'
36
+ SEVERITY_MINOR = 'Minor'
37
+ SEVERITY_UNKNOWN = 'Unknown'
38
38
  # Valid values for severity
39
- VALID_SEVERITIES = [ SEVERITY_EXTREME, SEVERITY_SEVERE, SEVERITY_MODERATE,
40
- SEVERITY_MINOR, SEVERITY_UNKNOWN ]
41
-
42
- CERTAINTY_VERY_LIKELY = "Very Likely"
43
- CERTAINTY_LIKELY = "Likely"
44
- CERTAINTY_POSSIBLE = "Possible"
45
- CERTAINTY_UNLIKELY = "Unlikely"
46
- CERTAINTY_UNKNOWN = "Unknown"
39
+ VALID_SEVERITIES = [SEVERITY_EXTREME, SEVERITY_SEVERE, SEVERITY_MODERATE,
40
+ SEVERITY_MINOR, SEVERITY_UNKNOWN]
41
+
42
+ CERTAINTY_VERY_LIKELY = 'Very Likely'
43
+ CERTAINTY_LIKELY = 'Likely'
44
+ CERTAINTY_POSSIBLE = 'Possible'
45
+ CERTAINTY_UNLIKELY = 'Unlikely'
46
+ CERTAINTY_UNKNOWN = 'Unknown'
47
47
  # Valid valies for certainty
48
- VALID_CERTAINTIES = [ CERTAINTY_VERY_LIKELY, CERTAINTY_LIKELY,
49
- CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN ]
48
+ VALID_CERTAINTIES = [CERTAINTY_VERY_LIKELY, CERTAINTY_LIKELY,
49
+ CERTAINTY_POSSIBLE, CERTAINTY_UNLIKELY, CERTAINTY_UNKNOWN]
50
50
 
51
51
  XML_ELEMENT_NAME = 'info'
52
52
  LANGUAGE_ELEMENT_NAME = 'language'
@@ -88,57 +88,56 @@ module RCAP
88
88
 
89
89
  DEFAULT_LANGUAGE = 'en-US'
90
90
 
91
- validates_presence_of( :event )
92
- validates_presence_of( :urgency )
93
- validates_presence_of( :severity )
94
- validates_presence_of( :certainty )
95
- validates_inclusion_of( :severity, :allow_nil => true, :in => VALID_SEVERITIES, :message => "can only be assigned the following values: #{ VALID_SEVERITIES.join(', ') }" )
96
- validates_inclusion_of( :urgency, :allow_nil => true, :in => VALID_URGENCIES, :message => "can only be assigned the following values: #{ VALID_URGENCIES.join(', ') }" )
97
- validates_inclusion_of_members_of( :categories, :in => VALID_CATEGORIES, :allow_blank => true )
98
- validates_collection_of( :resources, :areas, :event_codes, :parameters )
91
+ validates_presence_of(:event)
92
+ validates_presence_of(:urgency)
93
+ validates_presence_of(:severity)
94
+ validates_presence_of(:certainty)
95
+ validates_inclusion_of(:severity, allow_nil: true, in: VALID_SEVERITIES, message: "can only be assigned the following values: #{ VALID_SEVERITIES.join(', ') }")
96
+ validates_inclusion_of(:urgency, allow_nil: true, in: VALID_URGENCIES, message: "can only be assigned the following values: #{ VALID_URGENCIES.join(', ') }")
97
+ validates_inclusion_of_members_of(:categories, in: VALID_CATEGORIES, allow_blank: true)
98
+ validates_collection_of(:resources, :areas, :event_codes, :parameters)
99
99
 
100
100
  # @return [String]
101
- attr_accessor( :event )
101
+ attr_accessor(:event)
102
102
  # @return [String] Value can only be one of {VALID_URGENCIES}
103
- attr_accessor( :urgency )
103
+ attr_accessor(:urgency)
104
104
  # @return [String] Value can only be one of {VALID_SEVERITIES}
105
- attr_accessor( :severity )
105
+ attr_accessor(:severity)
106
106
  # @return [String] Value can only be one of {VALID_CERTAINTIES}
107
- attr_accessor( :certainty )
107
+ attr_accessor(:certainty)
108
108
  # @return [String]
109
- attr_accessor( :language )
109
+ attr_accessor(:language)
110
110
  # @return [String]
111
- attr_accessor( :audience )
111
+ attr_accessor(:audience)
112
112
  # @return [DateTime] Effective start time of information
113
- attr_accessor( :effective )
113
+ attr_accessor(:effective)
114
114
  # @return [DateTime] Expected start of event
115
- attr_accessor( :onset )
115
+ attr_accessor(:onset)
116
116
  # @return [DateTime] Effective expiry time of information
117
- attr_accessor( :expires )
117
+ attr_accessor(:expires)
118
118
  # @return [String]
119
- attr_accessor( :sender_name )
119
+ attr_accessor(:sender_name)
120
120
  # @return [String]
121
- attr_accessor( :headline )
121
+ attr_accessor(:headline)
122
122
  # @return [String]
123
- attr_accessor( :description )
123
+ attr_accessor(:description)
124
124
  # @return [String]
125
- attr_accessor( :instruction )
125
+ attr_accessor(:instruction)
126
126
  # @return [String]
127
- attr_accessor( :web )
127
+ attr_accessor(:web)
128
128
  # @return [String]
129
- attr_accessor( :contact )
129
+ attr_accessor(:contact)
130
130
 
131
131
  # @return [Array<String>] Collection of textual categories; elements can be one of {VALID_CATEGORIES}
132
- attr_reader( :categories )
132
+ attr_reader(:categories)
133
133
  # @return [Array<EventCode>] Collection of {EventCode} objects
134
- attr_reader( :event_codes )
134
+ attr_reader(:event_codes)
135
135
  # @return [Array<Parameter>] Collection of {Parameter} objects
136
- attr_reader( :parameters )
136
+ attr_reader(:parameters)
137
137
  # @return [Array<Resource> Collection of {Resource} objects
138
- attr_reader( :resources )
138
+ attr_reader(:resources)
139
139
  # @return [Array<Area>] Collection of {Area} objects
140
- attr_reader( :areas )
141
-
140
+ attr_reader(:areas)
142
141
 
143
142
  # Initialises a new Info object which will be yielded to an attached block if given
144
143
  #
@@ -150,15 +149,15 @@ module RCAP
150
149
  @parameters = []
151
150
  @resources = []
152
151
  @areas = []
153
- yield( self ) if block_given?
152
+ yield(self) if block_given?
154
153
  end
155
154
 
156
155
  # Creates a new EventCode object and adds it to the event_codes array.
157
156
  #
158
157
  # @return [EventCode]
159
158
  def add_event_code
160
- event_code = self.event_code_class.new
161
- yield( event_code ) if block_given?
159
+ event_code = event_code_class.new
160
+ yield(event_code) if block_given?
162
161
  @event_codes << event_code
163
162
  event_code
164
163
  end
@@ -167,8 +166,8 @@ module RCAP
167
166
  #
168
167
  # @return [Parameter]
169
168
  def add_parameter
170
- parameter = self.parameter_class.new
171
- yield( parameter ) if block_given?
169
+ parameter = parameter_class.new
170
+ yield(parameter) if block_given?
172
171
  @parameters << parameter
173
172
  parameter
174
173
  end
@@ -177,8 +176,8 @@ module RCAP
177
176
  #
178
177
  # @return [Resource]
179
178
  def add_resource
180
- resource = self.resource_class.new
181
- yield( resource ) if block_given?
179
+ resource = resource_class.new
180
+ yield(resource) if block_given?
182
181
  @resources << resource
183
182
  resource
184
183
  end
@@ -187,123 +186,119 @@ module RCAP
187
186
  #
188
187
  # @return [Area]
189
188
  def add_area
190
- area = self.area_class.new
191
- yield( area ) if block_given?
189
+ area = area_class.new
190
+ yield(area) if block_given?
192
191
  @areas << area
193
192
  area
194
193
  end
195
194
 
196
195
  # @return [REXML::Element]
197
196
  def to_xml_element
198
- xml_element = REXML::Element.new( XML_ELEMENT_NAME )
199
- xml_element.add_element( LANGUAGE_ELEMENT_NAME ).add_text( @language ) if @language
197
+ xml_element = REXML::Element.new(XML_ELEMENT_NAME)
198
+ xml_element.add_element(LANGUAGE_ELEMENT_NAME).add_text(@language) if @language
200
199
  @categories.each do |category|
201
- xml_element.add_element( CATEGORY_ELEMENT_NAME ).add_text( category )
200
+ xml_element.add_element(CATEGORY_ELEMENT_NAME).add_text(category)
202
201
  end
203
- xml_element.add_element( EVENT_ELEMENT_NAME ).add_text( @event )
204
- xml_element.add_element( URGENCY_ELEMENT_NAME ).add_text( @urgency )
205
- xml_element.add_element( SEVERITY_ELEMENT_NAME ).add_text( @severity )
206
- xml_element.add_element( CERTAINTY_ELEMENT_NAME ).add_text( @certainty )
207
- xml_element.add_element( AUDIENCE_ELEMENT_NAME ).add_text( @audience ) if @audience
202
+ xml_element.add_element(EVENT_ELEMENT_NAME).add_text(@event)
203
+ xml_element.add_element(URGENCY_ELEMENT_NAME).add_text(@urgency)
204
+ xml_element.add_element(SEVERITY_ELEMENT_NAME).add_text(@severity)
205
+ xml_element.add_element(CERTAINTY_ELEMENT_NAME).add_text(@certainty)
206
+ xml_element.add_element(AUDIENCE_ELEMENT_NAME).add_text(@audience) if @audience
208
207
  @event_codes.each do |event_code|
209
- xml_element.add_element( event_code.to_xml_element )
208
+ xml_element.add_element(event_code.to_xml_element)
210
209
  end
211
- xml_element.add_element( EFFECTIVE_ELEMENT_NAME ).add_text( @effective.to_s_for_cap ) if @effective
212
- xml_element.add_element( ONSET_ELEMENT_NAME ).add_text( @onset.to_s_for_cap ) if @onset
213
- xml_element.add_element( EXPIRES_ELEMENT_NAME ).add_text( @expires.to_s_for_cap ) if @expires
214
- xml_element.add_element( SENDER_NAME_ELEMENT_NAME ).add_text( @sender_name ) if @sender_name
215
- xml_element.add_element( HEADLINE_ELEMENT_NAME ).add_text( @headline ) if @headline
216
- xml_element.add_element( DESCRIPTION_ELEMENT_NAME ).add_text( @description ) if @description
217
- xml_element.add_element( INSTRUCTION_ELEMENT_NAME ).add_text( @instruction ) if @instruction
218
- xml_element.add_element( WEB_ELEMENT_NAME ).add_text( @web ) if @web
219
- xml_element.add_element( CONTACT_ELEMENT_NAME ).add_text( @contact ) if @contact
210
+ xml_element.add_element(EFFECTIVE_ELEMENT_NAME).add_text(@effective.to_s_for_cap) if @effective
211
+ xml_element.add_element(ONSET_ELEMENT_NAME).add_text(@onset.to_s_for_cap) if @onset
212
+ xml_element.add_element(EXPIRES_ELEMENT_NAME).add_text(@expires.to_s_for_cap) if @expires
213
+ xml_element.add_element(SENDER_NAME_ELEMENT_NAME).add_text(@sender_name) if @sender_name
214
+ xml_element.add_element(HEADLINE_ELEMENT_NAME).add_text(@headline) if @headline
215
+ xml_element.add_element(DESCRIPTION_ELEMENT_NAME).add_text(@description) if @description
216
+ xml_element.add_element(INSTRUCTION_ELEMENT_NAME).add_text(@instruction) if @instruction
217
+ xml_element.add_element(WEB_ELEMENT_NAME).add_text(@web) if @web
218
+ xml_element.add_element(CONTACT_ELEMENT_NAME).add_text(@contact) if @contact
220
219
  @parameters.each do |parameter|
221
- xml_element.add_element( parameter.to_xml_element )
220
+ xml_element.add_element(parameter.to_xml_element)
222
221
  end
223
222
  @resources.each do |resource|
224
- xml_element.add_element( resource.to_xml_element )
223
+ xml_element.add_element(resource.to_xml_element)
225
224
  end
226
225
  @areas.each do |area|
227
- xml_element.add_element( area.to_xml_element )
226
+ xml_element.add_element(area.to_xml_element)
228
227
  end
229
228
  xml_element
230
229
  end
231
230
 
232
231
  # @return [String]
233
232
  def to_xml
234
- self.to_xml_element.to_s
233
+ to_xml_element.to_s
235
234
  end
236
235
 
237
236
  # @param [REXML::Element] info_xml_element
238
237
  # @return [Info]
239
- def self.from_xml_element( info_xml_element )
240
- self.new do |info|
241
- info.language = RCAP.xpath_text( info_xml_element, LANGUAGE_XPATH, info.xmlns ) || DEFAULT_LANGUAGE
238
+ def self.from_xml_element(info_xml_element)
239
+ new do |info|
240
+ info.language = RCAP.xpath_text(info_xml_element, LANGUAGE_XPATH, info.xmlns) || DEFAULT_LANGUAGE
242
241
 
243
- RCAP.xpath_match( info_xml_element, CATEGORY_XPATH, info.xmlns ).each do |element|
242
+ RCAP.xpath_match(info_xml_element, CATEGORY_XPATH, info.xmlns).each do |element|
244
243
  info.categories << element.text
245
244
  end
246
245
 
247
- info.event = RCAP.xpath_text( info_xml_element, EVENT_XPATH, info.xmlns )
248
- info.urgency = RCAP.xpath_text( info_xml_element, URGENCY_XPATH, info.xmlns )
249
- info.severity = RCAP.xpath_text( info_xml_element, SEVERITY_XPATH, info.xmlns )
250
- info.certainty = RCAP.xpath_text( info_xml_element, CERTAINTY_XPATH, info.xmlns )
251
- info.audience = RCAP.xpath_text( info_xml_element, AUDIENCE_XPATH, info.xmlns )
252
- info.effective = RCAP.parse_datetime( RCAP.xpath_text( info_xml_element, EFFECTIVE_XPATH, info.xmlns ))
253
- info.onset = RCAP.parse_datetime( RCAP.xpath_text( info_xml_element, ONSET_XPATH, info.xmlns ))
254
- info.expires = RCAP.parse_datetime( RCAP.xpath_text( info_xml_element, EXPIRES_XPATH, info.xmlns ))
255
- info.sender_name = RCAP.xpath_text( info_xml_element, SENDER_NAME_XPATH, info.xmlns )
256
- info.headline = RCAP.xpath_text( info_xml_element, HEADLINE_XPATH, info.xmlns )
257
- info.description = RCAP.xpath_text( info_xml_element, DESCRIPTION_XPATH, info.xmlns )
258
- info.instruction = RCAP.xpath_text( info_xml_element, INSTRUCTION_XPATH, info.xmlns )
259
- info.web = RCAP.xpath_text( info_xml_element, WEB_XPATH, info.xmlns )
260
- info.contact = RCAP.xpath_text( info_xml_element, CONTACT_XPATH, info.xmlns )
261
-
262
- RCAP.xpath_match( info_xml_element, info.event_code_class::XPATH, info.xmlns ).each do |element|
263
- info.event_codes << info.event_code_class.from_xml_element( element )
246
+ info.event = RCAP.xpath_text(info_xml_element, EVENT_XPATH, info.xmlns)
247
+ info.urgency = RCAP.xpath_text(info_xml_element, URGENCY_XPATH, info.xmlns)
248
+ info.severity = RCAP.xpath_text(info_xml_element, SEVERITY_XPATH, info.xmlns)
249
+ info.certainty = RCAP.xpath_text(info_xml_element, CERTAINTY_XPATH, info.xmlns)
250
+ info.audience = RCAP.xpath_text(info_xml_element, AUDIENCE_XPATH, info.xmlns)
251
+ info.effective = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, EFFECTIVE_XPATH, info.xmlns))
252
+ info.onset = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, ONSET_XPATH, info.xmlns))
253
+ info.expires = RCAP.parse_datetime(RCAP.xpath_text(info_xml_element, EXPIRES_XPATH, info.xmlns))
254
+ info.sender_name = RCAP.xpath_text(info_xml_element, SENDER_NAME_XPATH, info.xmlns)
255
+ info.headline = RCAP.xpath_text(info_xml_element, HEADLINE_XPATH, info.xmlns)
256
+ info.description = RCAP.xpath_text(info_xml_element, DESCRIPTION_XPATH, info.xmlns)
257
+ info.instruction = RCAP.xpath_text(info_xml_element, INSTRUCTION_XPATH, info.xmlns)
258
+ info.web = RCAP.xpath_text(info_xml_element, WEB_XPATH, info.xmlns)
259
+ info.contact = RCAP.xpath_text(info_xml_element, CONTACT_XPATH, info.xmlns)
260
+
261
+ RCAP.xpath_match(info_xml_element, info.event_code_class::XPATH, info.xmlns).each do |element|
262
+ info.event_codes << info.event_code_class.from_xml_element(element)
264
263
  end
265
264
 
266
- RCAP.xpath_match( info_xml_element, info.parameter_class::XPATH, info.xmlns ).each do |element|
267
- info.parameters << info.parameter_class.from_xml_element( element )
265
+ RCAP.xpath_match(info_xml_element, info.parameter_class::XPATH, info.xmlns).each do |element|
266
+ info.parameters << info.parameter_class.from_xml_element(element)
268
267
  end
269
268
 
270
- RCAP.xpath_match( info_xml_element, info.resource_class::XPATH, info.xmlns ).each do |element|
271
- info.resources << info.resource_class.from_xml_element( element )
269
+ RCAP.xpath_match(info_xml_element, info.resource_class::XPATH, info.xmlns).each do |element|
270
+ info.resources << info.resource_class.from_xml_element(element)
272
271
  end
273
272
 
274
- RCAP.xpath_match( info_xml_element, info.area_class::XPATH, info.xmlns ).each do |element|
275
- info.areas << info.area_class.from_xml_element( element )
273
+ RCAP.xpath_match(info_xml_element, info.area_class::XPATH, info.xmlns).each do |element|
274
+ info.areas << info.area_class.from_xml_element(element)
276
275
  end
277
276
  end
278
277
  end
279
278
 
280
279
  # @return [String]
281
280
  def inspect
282
- info_inspect = "Language: #{ @language }\n"+
283
- "Categories: #{ @categories.to_s_for_cap }\n"+
284
- "Event: #{ @event }\n"+
285
- "Urgency: #{ @urgency }\n"+
286
- "Severity: #{ @severity }\n"+
287
- "Certainty: #{ @certainty }\n"+
288
- "Audience: #{ @audience }\n"+
289
- "Event Codes: #{ @event_codes.inspect }\n"+
290
- "Effective: #{ @effective }\n"+
291
- "Onset: #{ @onset }\n"+
292
- "Expires: #{ @expires }\n"+
293
- "Sender Name: #{ @sender_name }\n"+
294
- "Headline: #{ @headline }\n"+
295
- "Description:\n"+
296
- @description.to_s.lines.map{ |line| " " + line }.join( "\n")+"\n"+
297
- "Instruction: #{ @instruction }\n"+
298
- "Web: #{ @web }\n"+
299
- "Contact: #{ @contact }\n"+
300
- "Parameters:\n"+
301
- @parameters.map{ |parameter| " " + parameter.inspect }.join( "\n" )+"\n"+
302
- "Resources:\n"+
303
- @resources.map{ |resource| " " + resource.inspect }.join( "\n" )+"\n"+
304
- "Area:\n"+
305
- @areas.map{ |area| " #{ area }" }.join( "\n" )+"\n"
306
- RCAP.format_lines_for_inspect( 'INFO', info_inspect )
281
+ info_inspect = "Language: #{ @language }\n"\
282
+ "Categories: #{ @categories.to_s_for_cap }\n"\
283
+ "Event: #{ @event }\n"\
284
+ "Urgency: #{ @urgency }\n"\
285
+ "Severity: #{ @severity }\n"\
286
+ "Certainty: #{ @certainty }\n"\
287
+ "Audience: #{ @audience }\n"\
288
+ "Event Codes: #{ @event_codes.inspect }\n"\
289
+ "Effective: #{ @effective }\n"\
290
+ "Onset: #{ @onset }\n"\
291
+ "Expires: #{ @expires }\n"\
292
+ "Sender Name: #{ @sender_name }\n"\
293
+ "Headline: #{ @headline }\n"\
294
+ "Description:\n" + @description.to_s.lines.map { |line| ' ' + line }.join("\n") + "\n"\
295
+ "Instruction: #{ @instruction }\n"\
296
+ "Web: #{ @web }\n"\
297
+ "Contact: #{ @contact }\n"\
298
+ "Parameters:\n" + @parameters.map { |parameter| ' ' + parameter.inspect }.join("\n") + "\n"\
299
+ "Resources:\n" + @resources.map { |resource| ' ' + resource.inspect }.join("\n") + "\n"\
300
+ "Area:\n" + @areas.map { |area| " #{ area }" }.join("\n") + "\n"
301
+ RCAP.format_lines_for_inspect('INFO', info_inspect)
307
302
  end
308
303
 
309
304
  # Returns a string representation of the event of the form
@@ -337,78 +332,78 @@ module RCAP
337
332
 
338
333
  # @return [Hash]
339
334
  def to_yaml_data
340
- parameter_to_hash = lambda{ |hash, parameter| hash.merge( parameter.name => parameter.value )}
341
-
342
- RCAP.attribute_values_to_hash( [ LANGUAGE_YAML, @language ],
343
- [ CATEGORIES_YAML, @categories ],
344
- [ EVENT_YAML, @event ],
345
- [ URGENCY_YAML, @urgency ],
346
- [ SEVERITY_YAML, @severity ],
347
- [ CERTAINTY_YAML, @certainty ],
348
- [ AUDIENCE_YAML, @audience ],
349
- [ EFFECTIVE_YAML, @effective ],
350
- [ ONSET_YAML, @onset ],
351
- [ EXPIRES_YAML, @expires ],
352
- [ SENDER_NAME_YAML, @sender_name ],
353
- [ HEADLINE_YAML, @headline ],
354
- [ DESCRIPTION_YAML, @description ],
355
- [ INSTRUCTION_YAML, @instruction ],
356
- [ WEB_YAML, @web ],
357
- [ CONTACT_YAML, @contact ],
358
- [ EVENT_CODES_YAML, @event_codes.inject({}, &parameter_to_hash )],
359
- [ PARAMETERS_YAML, @parameters.inject({}, &parameter_to_hash )],
360
- [ RESOURCES_YAML, @resources.map( &:to_yaml_data )],
361
- [ AREAS_YAML, @areas.map(&:to_yaml_data )])
335
+ parameter_to_hash = lambda { |hash, parameter| hash.merge(parameter.name => parameter.value) }
336
+
337
+ RCAP.attribute_values_to_hash([LANGUAGE_YAML, @language],
338
+ [CATEGORIES_YAML, @categories],
339
+ [EVENT_YAML, @event],
340
+ [URGENCY_YAML, @urgency],
341
+ [SEVERITY_YAML, @severity],
342
+ [CERTAINTY_YAML, @certainty],
343
+ [AUDIENCE_YAML, @audience],
344
+ [EFFECTIVE_YAML, @effective],
345
+ [ONSET_YAML, @onset],
346
+ [EXPIRES_YAML, @expires],
347
+ [SENDER_NAME_YAML, @sender_name],
348
+ [HEADLINE_YAML, @headline],
349
+ [DESCRIPTION_YAML, @description],
350
+ [INSTRUCTION_YAML, @instruction],
351
+ [WEB_YAML, @web],
352
+ [CONTACT_YAML, @contact],
353
+ [EVENT_CODES_YAML, @event_codes.inject({}, &parameter_to_hash)],
354
+ [PARAMETERS_YAML, @parameters.inject({}, &parameter_to_hash)],
355
+ [RESOURCES_YAML, @resources.map(&:to_yaml_data)],
356
+ [AREAS_YAML, @areas.map(&:to_yaml_data)])
362
357
  end
363
358
 
364
359
  # @return [String]
365
- def to_yaml( options = {} )
366
- self.to_yaml_data.to_yaml( options )
360
+ def to_yaml(options = {})
361
+ to_yaml_data.to_yaml(options)
367
362
  end
368
363
 
369
364
  # @param [Hash] info_yaml_data
370
365
  # @return [Info]
371
- def self.from_yaml_data( info_yaml_data )
372
- self.new do |info|
373
- info.language = info_yaml_data [ LANGUAGE_YAML ]
374
- Array( info_yaml_data [ CATEGORIES_YAML ]).each do |category|
366
+ def self.from_yaml_data(info_yaml_data)
367
+ new do |info|
368
+ info.language = info_yaml_data [LANGUAGE_YAML]
369
+ Array(info_yaml_data [CATEGORIES_YAML]).each do |category|
375
370
  info.categories << category
376
371
  end
377
- info.event = RCAP.strip_if_given( info_yaml_data [ EVENT_YAML ])
378
- info.urgency = RCAP.strip_if_given( info_yaml_data [ URGENCY_YAML ])
379
- info.severity = RCAP.strip_if_given( info_yaml_data [ SEVERITY_YAML ])
380
- info.certainty = RCAP.strip_if_given( info_yaml_data [ CERTAINTY_YAML ])
381
- info.audience = RCAP.strip_if_given( info_yaml_data [ AUDIENCE_YAML ])
382
- info.effective = RCAP.parse_datetime( info_yaml_data[ EFFECTIVE_YAML ])
383
- info.onset = RCAP.parse_datetime( info_yaml_data[ ONSET_YAML ])
384
- info.expires = RCAP.parse_datetime( info_yaml_data[ EXPIRES_YAML ])
385
- info.sender_name = RCAP.strip_if_given( info_yaml_data [ SENDER_NAME_YAML ])
386
- info.headline = RCAP.strip_if_given( info_yaml_data [ HEADLINE_YAML ])
387
- info.description = RCAP.strip_if_given( info_yaml_data [ DESCRIPTION_YAML ])
388
- info.instruction = RCAP.strip_if_given( info_yaml_data [ INSTRUCTION_YAML ])
389
- info.web = RCAP.strip_if_given( info_yaml_data [ WEB_YAML ])
390
- info.contact = RCAP.strip_if_given( info_yaml_data [ CONTACT_YAML ])
391
-
392
- Array( info_yaml_data [ EVENT_CODES_YAML ]).each do |name,value|
372
+ info.event = RCAP.strip_if_given(info_yaml_data [EVENT_YAML])
373
+ info.urgency = RCAP.strip_if_given(info_yaml_data [URGENCY_YAML])
374
+ info.severity = RCAP.strip_if_given(info_yaml_data [SEVERITY_YAML])
375
+ info.certainty = RCAP.strip_if_given(info_yaml_data [CERTAINTY_YAML])
376
+ info.audience = RCAP.strip_if_given(info_yaml_data [AUDIENCE_YAML])
377
+ info.effective = RCAP.parse_datetime(info_yaml_data[EFFECTIVE_YAML])
378
+ info.onset = RCAP.parse_datetime(info_yaml_data[ONSET_YAML])
379
+ info.expires = RCAP.parse_datetime(info_yaml_data[EXPIRES_YAML])
380
+ info.sender_name = RCAP.strip_if_given(info_yaml_data [SENDER_NAME_YAML])
381
+ info.headline = RCAP.strip_if_given(info_yaml_data [HEADLINE_YAML])
382
+ info.description = RCAP.strip_if_given(info_yaml_data [DESCRIPTION_YAML])
383
+ info.instruction = RCAP.strip_if_given(info_yaml_data [INSTRUCTION_YAML])
384
+ info.web = RCAP.strip_if_given(info_yaml_data [WEB_YAML])
385
+ info.contact = RCAP.strip_if_given(info_yaml_data [CONTACT_YAML])
386
+
387
+ Array(info_yaml_data [EVENT_CODES_YAML]).each do |name, value|
393
388
  info.add_event_code do |event_code|
394
- event_code.name = RCAP.strip_if_given( name )
395
- event_code.value = RCAP.strip_if_given( value )
389
+ event_code.name = RCAP.strip_if_given(name)
390
+ event_code.value = RCAP.strip_if_given(value)
396
391
  end
397
392
  end
398
393
 
399
- Array( info_yaml_data [ PARAMETERS_YAML ]).each do |name,value|
394
+ Array(info_yaml_data [PARAMETERS_YAML]).each do |name, value|
400
395
  info.add_parameter do |parameter|
401
- parameter.name = RCAP.strip_if_given( name )
402
- parameter.value = RCAP.strip_if_given( value )
396
+ parameter.name = RCAP.strip_if_given(name)
397
+ parameter.value = RCAP.strip_if_given(value)
403
398
  end
404
399
  end
405
400
 
406
- Array( info_yaml_data [ RESOURCES_YAML ]).each do |resource_yaml_data|
407
- info.resources << info.resource_class.from_yaml_data( resource_yaml_data )
401
+ Array(info_yaml_data [RESOURCES_YAML]).each do |resource_yaml_data|
402
+ info.resources << info.resource_class.from_yaml_data(resource_yaml_data)
408
403
  end
409
404
 
410
- Array( info_yaml_data [ AREAS_YAML ]).each do |area_yaml_data|
411
- info.areas << info.area_class.from_yaml_data( area_yaml_data )
405
+ Array(info_yaml_data [AREAS_YAML]).each do |area_yaml_data|
406
+ info.areas << info.area_class.from_yaml_data(area_yaml_data)
412
407
  end
413
408
  end
414
409
  end
@@ -436,65 +431,65 @@ module RCAP
436
431
 
437
432
  # @return [Hash]
438
433
  def to_h
439
- RCAP.attribute_values_to_hash( [ LANGUAGE_KEY, @language ],
440
- [ CATEGORIES_KEY, @categories ],
441
- [ EVENT_KEY, @event ],
442
- [ URGENCY_KEY, @urgency ],
443
- [ SEVERITY_KEY, @severity ],
444
- [ CERTAINTY_KEY, @certainty ],
445
- [ AUDIENCE_KEY, @audience ],
446
- [ EFFECTIVE_KEY, RCAP.to_s_for_cap( @effective )],
447
- [ ONSET_KEY, RCAP.to_s_for_cap( @onset )],
448
- [ EXPIRES_KEY, RCAP.to_s_for_cap( @expires )],
449
- [ SENDER_NAME_KEY, @sender_name ],
450
- [ HEADLINE_KEY, @headline ],
451
- [ DESCRIPTION_KEY, @description ],
452
- [ INSTRUCTION_KEY, @instruction ],
453
- [ WEB_KEY, @web ],
454
- [ CONTACT_KEY, @contact ],
455
- [ RESOURCES_KEY, @resources.map{ |resource| resource.to_h } ],
456
- [ EVENT_CODES_KEY, @event_codes.map{ |event_code| event_code.to_h } ],
457
- [ PARAMETERS_KEY, @parameters.map{ |parameter| parameter.to_h } ],
458
- [ AREAS_KEY, @areas.map{ |area| area.to_h }])
434
+ RCAP.attribute_values_to_hash([LANGUAGE_KEY, @language],
435
+ [CATEGORIES_KEY, @categories],
436
+ [EVENT_KEY, @event],
437
+ [URGENCY_KEY, @urgency],
438
+ [SEVERITY_KEY, @severity],
439
+ [CERTAINTY_KEY, @certainty],
440
+ [AUDIENCE_KEY, @audience],
441
+ [EFFECTIVE_KEY, RCAP.to_s_for_cap(@effective)],
442
+ [ONSET_KEY, RCAP.to_s_for_cap(@onset)],
443
+ [EXPIRES_KEY, RCAP.to_s_for_cap(@expires)],
444
+ [SENDER_NAME_KEY, @sender_name],
445
+ [HEADLINE_KEY, @headline],
446
+ [DESCRIPTION_KEY, @description],
447
+ [INSTRUCTION_KEY, @instruction],
448
+ [WEB_KEY, @web],
449
+ [CONTACT_KEY, @contact],
450
+ [RESOURCES_KEY, @resources.map { |resource| resource.to_h }],
451
+ [EVENT_CODES_KEY, @event_codes.map { |event_code| event_code.to_h }],
452
+ [PARAMETERS_KEY, @parameters.map { |parameter| parameter.to_h }],
453
+ [AREAS_KEY, @areas.map { |area| area.to_h }])
459
454
  end
460
455
 
461
456
  # @param [Hash] info_hash
462
457
  # @return [Info]
463
- def self.from_h( info_hash )
464
- self.new do |info|
465
- info.language = info_hash[ LANGUAGE_KEY ]
466
- Array( info_hash[ CATEGORIES_KEY ]).each do |category|
467
- info.categories << RCAP.strip_if_given( category )
458
+ def self.from_h(info_hash)
459
+ new do |info|
460
+ info.language = info_hash[LANGUAGE_KEY]
461
+ Array(info_hash[CATEGORIES_KEY]).each do |category|
462
+ info.categories << RCAP.strip_if_given(category)
468
463
  end
469
- info.event = RCAP.strip_if_given( info_hash[ EVENT_KEY ])
470
- info.urgency = RCAP.strip_if_given( info_hash[ URGENCY_KEY ])
471
- info.severity = RCAP.strip_if_given( info_hash[ SEVERITY_KEY ])
472
- info.certainty = RCAP.strip_if_given( info_hash[ CERTAINTY_KEY ])
473
- info.audience = RCAP.strip_if_given( info_hash[ AUDIENCE_KEY ])
474
- info.effective = RCAP.parse_datetime( info_hash[ EFFECTIVE_KEY ])
475
- info.onset = RCAP.parse_datetime( info_hash[ ONSET_KEY ])
476
- info.expires = RCAP.parse_datetime( info_hash[ EXPIRES_KEY ])
477
- info.sender_name = RCAP.strip_if_given( info_hash[ SENDER_NAME_KEY ])
478
- info.headline = RCAP.strip_if_given( info_hash[ HEADLINE_KEY ])
479
- info.description = RCAP.strip_if_given( info_hash[ DESCRIPTION_KEY ])
480
- info.instruction = RCAP.strip_if_given( info_hash[ INSTRUCTION_KEY ])
481
- info.web = RCAP.strip_if_given( info_hash[ WEB_KEY ])
482
- info.contact = RCAP.strip_if_given( info_hash[ CONTACT_KEY ])
483
-
484
- Array( info_hash[ RESOURCES_KEY ]).each do |resource_hash|
485
- info.resources << info.resource_class.from_h( resource_hash )
464
+ info.event = RCAP.strip_if_given(info_hash[EVENT_KEY])
465
+ info.urgency = RCAP.strip_if_given(info_hash[URGENCY_KEY])
466
+ info.severity = RCAP.strip_if_given(info_hash[SEVERITY_KEY])
467
+ info.certainty = RCAP.strip_if_given(info_hash[CERTAINTY_KEY])
468
+ info.audience = RCAP.strip_if_given(info_hash[AUDIENCE_KEY])
469
+ info.effective = RCAP.parse_datetime(info_hash[EFFECTIVE_KEY])
470
+ info.onset = RCAP.parse_datetime(info_hash[ONSET_KEY])
471
+ info.expires = RCAP.parse_datetime(info_hash[EXPIRES_KEY])
472
+ info.sender_name = RCAP.strip_if_given(info_hash[SENDER_NAME_KEY])
473
+ info.headline = RCAP.strip_if_given(info_hash[HEADLINE_KEY])
474
+ info.description = RCAP.strip_if_given(info_hash[DESCRIPTION_KEY])
475
+ info.instruction = RCAP.strip_if_given(info_hash[INSTRUCTION_KEY])
476
+ info.web = RCAP.strip_if_given(info_hash[WEB_KEY])
477
+ info.contact = RCAP.strip_if_given(info_hash[CONTACT_KEY])
478
+
479
+ Array(info_hash[RESOURCES_KEY]).each do |resource_hash|
480
+ info.resources << info.resource_class.from_h(resource_hash)
486
481
  end
487
482
 
488
- Array( info_hash[ EVENT_CODES_KEY ]).each do |event_code_hash|
489
- info.event_codes << info.event_code_class.from_h( event_code_hash )
483
+ Array(info_hash[EVENT_CODES_KEY]).each do |event_code_hash|
484
+ info.event_codes << info.event_code_class.from_h(event_code_hash)
490
485
  end
491
486
 
492
- Array( info_hash[ PARAMETERS_KEY ]).each do |parameter_hash|
493
- info.parameters << info.parameter_class.from_h( parameter_hash )
487
+ Array(info_hash[PARAMETERS_KEY]).each do |parameter_hash|
488
+ info.parameters << info.parameter_class.from_h(parameter_hash)
494
489
  end
495
490
 
496
- Array( info_hash[ AREAS_KEY ]).each do |area_hash|
497
- info.areas << info.area_class.from_h( area_hash )
491
+ Array(info_hash[AREAS_KEY]).each do |area_hash|
492
+ info.areas << info.area_class.from_h(area_hash)
498
493
  end
499
494
  end
500
495
  end