Class: RCAP::Base::Area
Constant Summary
collapse
- XML_ELEMENT_NAME =
'area'
- AREA_DESC_ELEMENT_NAME =
'areaDesc'
- ALTITUDE_ELEMENT_NAME =
'altitude'
- CEILING_ELEMENT_NAME =
'ceiling'
- XPATH =
"cap:#{ XML_ELEMENT_NAME }"
- AREA_DESC_XPATH =
"cap:#{ AREA_DESC_ELEMENT_NAME }"
- ALTITUDE_XPATH =
"cap:#{ ALTITUDE_ELEMENT_NAME }"
- CEILING_XPATH =
"cap:#{ CEILING_ELEMENT_NAME }"
- AREA_DESC_YAML =
'Area Description'
- ALTITUDE_YAML =
'Altitude'
- CEILING_YAML =
'Ceiling'
- CIRCLES_YAML =
'Circles'
- GEOCODES_YAML =
'Geocodes'
- POLYGONS_YAML =
'Polygons'
- AREA_DESC_KEY =
'area_desc'
- ALTITUDE_KEY =
'altitude'
- CEILING_KEY =
'ceiling'
- CIRCLES_KEY =
'circles'
- GEOCODES_KEY =
'geocodes'
- POLYGONS_KEY =
'polygons'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Validation
#errors, included, #valid?, #validate
Constructor Details
#initialize {|_self| ... } ⇒ Area
Returns a new instance of Area.
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rcap/base/area.rb', line 37
def initialize
@area_desc = nil
@altitude = nil
@ceiling = nil
@circles = []
@geocodes = []
@polygons = []
yield(self) if block_given?
end
|
Instance Attribute Details
#altitude ⇒ Numeric
Returns Expressed in feet above sea level.
9
10
11
|
# File 'lib/rcap/base/area.rb', line 9
def altitude
@altitude
end
|
#area_desc ⇒ String
Returns Textual description of area.
7
8
9
|
# File 'lib/rcap/base/area.rb', line 7
def area_desc
@area_desc
end
|
#ceiling ⇒ Numeric
Returns Expressed in feet above sea level.
11
12
13
|
# File 'lib/rcap/base/area.rb', line 11
def ceiling
@ceiling
end
|
13
14
15
|
# File 'lib/rcap/base/area.rb', line 13
def circles
@circles
end
|
15
16
17
|
# File 'lib/rcap/base/area.rb', line 15
def geocodes
@geocodes
end
|
17
18
19
|
# File 'lib/rcap/base/area.rb', line 17
def polygons
@polygons
end
|
Class Method Details
.from_h(area_hash) ⇒ Area
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/rcap/base/area.rb', line 200
def self.from_h(area_hash)
new do |area|
area.area_desc = area_hash[AREA_DESC_KEY]
area.altitude = area_hash[ALTITUDE_KEY]
area.ceiling = area_hash[CEILING_KEY]
Array(area_hash[CIRCLES_KEY]).each do |circle_array|
area.circles << area.circle_class.from_a(circle_array)
end
Array(area_hash[GEOCODES_KEY]).each do |geocode_hash|
area.geocodes << area.geocode_class.from_h(geocode_hash)
end
Array(area_hash[POLYGONS_KEY]).each do |polygon_hash|
area.polygons << area.polygon_class.from_h(polygon_hash)
end
end
end
|
.from_xml_element(area_xml_element) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/rcap/base/area.rb', line 78
def self.from_xml_element(area_xml_element)
new do |area|
area.area_desc = RCAP.xpath_text(area_xml_element, AREA_DESC_XPATH, area.xmlns)
area.altitude = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, ALTITUDE_XPATH, area.xmlns))
area.ceiling = RCAP.to_f_if_given(RCAP.xpath_text(area_xml_element, CEILING_XPATH, area.xmlns))
RCAP.xpath_match(area_xml_element, area.circle_class::XPATH, area.xmlns).each do |circle_element|
area.circles << area.circle_class.from_xml_element(circle_element)
end
RCAP.xpath_match(area_xml_element, area.geocode_class::XPATH, area.xmlns).each do |geocode_element|
area.geocodes << area.geocode_class.from_xml_element(geocode_element)
end
RCAP.xpath_match(area_xml_element, area.polygon_class::XPATH, area.xmlns).each do |polygon_element|
area.polygons << area.polygon_class.from_xml_element(polygon_element)
end
end
end
|
.from_yaml_data(area_yaml_data) ⇒ Area
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/rcap/base/area.rb', line 168
def self.from_yaml_data(area_yaml_data)
new do |area|
area.area_desc = area_yaml_data[AREA_DESC_YAML]
area.altitude = area_yaml_data[ALTITUDE_YAML]
area.ceiling = area_yaml_data[CEILING_YAML]
Array(area_yaml_data[CIRCLES_YAML]).each do |circle_yaml_data|
area.circles << area.circle_class.from_yaml_data(circle_yaml_data)
end
Array(area_yaml_data[GEOCODES_YAML]).each do |name, value|
area.add_geocode do |geocode|
geocode.name = name
geocode.value = value
end
end
Array(area_yaml_data[POLYGONS_YAML]).each do |polyon_yaml_data|
area.polygons << area.polygon_class.from_yaml_data(polyon_yaml_data)
end
end
end
|
Instance Method Details
#==(other) ⇒ true, false
Implements an equality operator for the Area object. Two Area objects are equal if all their attributes are equal.
123
124
125
126
|
# File 'lib/rcap/base/area.rb', line 123
def ==(other)
comparison_attributes = lambda { |area| [area.area_desc, area.altitude, area.ceiling, area.circles, area.geocodes, area.polygons] }
comparison_attributes.call(self) == comparison_attributes.call(other)
end
|
#add_circle ⇒ Circle
61
62
63
64
65
66
|
# File 'lib/rcap/base/area.rb', line 61
def add_circle
circle_class.new.tap do |circle|
yield(circle) if block_given?
@circles << circle
end
end
|
#add_geocode ⇒ Geocode
71
72
73
74
75
76
|
# File 'lib/rcap/base/area.rb', line 71
def add_geocode
geocode_class.new do |geocode|
yield(geocode) if block_given?
@geocodes << geocode
end
end
|
#add_polygon ⇒ Polygon
51
52
53
54
55
56
|
# File 'lib/rcap/base/area.rb', line 51
def add_polygon
polygon_class.new.tap do |polygon|
yield(polygon) if block_given?
@polygons << polygon
end
end
|
129
130
131
132
133
134
135
|
# File 'lib/rcap/base/area.rb', line 129
def inspect
area_inspect = "Area Description: #{ @area_desc }\n"\
"Polygons:\n" + @polygons.map { |polygon| ' ' + polygon.inspect }.join("\n") + "\n"\
"Circles: #{ @circles.inspect }\n"\
"Geocodes: #{ @geocodes.inspect }\n"
RCAP.format_lines_for_inspect('AREA', area_inspect)
end
|
#to_h ⇒ Hash
221
222
223
224
225
226
227
228
|
# File 'lib/rcap/base/area.rb', line 221
def to_h
RCAP.attribute_values_to_hash([AREA_DESC_KEY, @area_desc],
[ALTITUDE_KEY, @altitude],
[CEILING_KEY, @ceiling],
[CIRCLES_KEY, @circles.map { |circle| circle.to_a }],
[GEOCODES_KEY, @geocodes.map { |geocode| geocode.to_h }],
[POLYGONS_KEY, @polygons.map { |polygon| polygon.to_h }])
end
|
Returns the area description
140
141
142
|
# File 'lib/rcap/base/area.rb', line 140
def to_s
@area_desc
end
|
Returns XML representation of the Area.
115
116
117
|
# File 'lib/rcap/base/area.rb', line 115
def to_xml
to_xml_element.to_s
end
|
#to_xml_element ⇒ REXML::Element
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/rcap/base/area.rb', line 99
def to_xml_element
REXML::Element.new(XML_ELEMENT_NAME).tap do |xml_element|
xml_element.add_element(AREA_DESC_ELEMENT_NAME).add_text(@area_desc.to_s)
add_to_xml_element = lambda do |element, object|
element.add_element(object.to_xml_element)
element
end
@polygons.inject(xml_element, &add_to_xml_element)
@circles.inject(xml_element, &add_to_xml_element)
@geocodes.inject(xml_element, &add_to_xml_element)
xml_element.add_element(ALTITUDE_ELEMENT_NAME).add_text(@altitude.to_s) unless @altitude.blank?
xml_element.add_element(CEILING_ELEMENT_NAME).add_text(@ceiling.to_s) unless @altitude.blank?
end
end
|
#to_yaml(options = {}) ⇒ String
Returns YAML representation of object.
162
163
164
|
# File 'lib/rcap/base/area.rb', line 162
def to_yaml(options = {})
to_yaml_data.to_yaml(options)
end
|
#to_yaml_data ⇒ Hash
152
153
154
155
156
157
158
159
|
# File 'lib/rcap/base/area.rb', line 152
def to_yaml_data
RCAP.attribute_values_to_hash([AREA_DESC_YAML, @area_desc],
[ALTITUDE_YAML, @altitude],
[CEILING_YAML, @ceiling],
[CIRCLES_YAML, @circles.map { |circle| circle.to_a }],
[GEOCODES_YAML, @geocodes.reduce({}) { |h, geocode| h.merge(geocode.name => geocode.value) }],
[POLYGONS_YAML, @polygons.map(&:to_yaml_data)])
end
|