rgeo-geojson 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a486ffc62008cbb9d03e13f7ea93aa229c588de
4
- data.tar.gz: c3826e787a98ba17b33f81e59c859898a6807ea3
3
+ metadata.gz: fc3be76c9c38e00c18464bd4fa71abbcc369a9dc
4
+ data.tar.gz: 508c6d9bf6a22fa8dba63d8aea3a569f6f287331
5
5
  SHA512:
6
- metadata.gz: 4ef133754c920d853e2e2a9191e194afdf895bb361692e22d56d2dc160c5dda5b9b8470aad511458d84a35e7ef44f5541346e44ab6750ff1ac7124129f7ccc7f
7
- data.tar.gz: e6fd873662287d0b7999190469aad4f805259906e2589f043199128bd56848c84c7f14cb082dacabe7eb5b0073288fc40eccfae2818d098aabaafe74d7d9f476
6
+ metadata.gz: 21f7f32967c8c92f15ac42375852063c3528fa887f2d1dd728436e7ea26ce157518c5f2dd194c97a3d0c3b7819027aa181cf4a365dd72096085e4637d3b06d3b
7
+ data.tar.gz: 084e1f589f1a679d10fc15fd1584e94e9a6df76f498a587b9042f93d4a4f35befeacceab8498151e3efe02fadcaf9bd2cc21fa42dd1cee0c28849e2be42c761b
data/History.md CHANGED
@@ -1,8 +1,16 @@
1
+ ### 0.4.0 / 2015-12-28
2
+
3
+ * Removed error handling for missing parser gems
4
+ * Removed class variables in Coder
5
+ * Removed rgeo/geo_json.rb
6
+
7
+
1
8
  ### 0.3.3 / 2015-12-23
2
9
 
3
10
  * Rubocop style updates #20
4
11
  * Do not distribute test files with gem
5
12
 
13
+
6
14
  ### 0.3.2 / 2015-12-10
7
15
 
8
16
  * Faster coordinates methods (tneems) #18
data/lib/rgeo-geojson.rb CHANGED
@@ -1 +1,5 @@
1
- require "rgeo/geo_json"
1
+ require "rgeo"
2
+ require "rgeo/geo_json/version"
3
+ require "rgeo/geo_json/entities"
4
+ require "rgeo/geo_json/coder"
5
+ require "rgeo/geo_json/interface"
@@ -6,10 +6,6 @@ module RGeo
6
6
  # settings every time.
7
7
 
8
8
  class Coder
9
- @@json_available = nil
10
- @@yajl_available = nil
11
- @@activesupport_available = nil
12
-
13
9
  # Create a new coder settings object. The geo factory is passed as
14
10
  # a required argument.
15
11
  #
@@ -32,58 +28,25 @@ module RGeo
32
28
  # <tt>:active_support</tt>. Setting one of those special values
33
29
  # will require the corresponding library to be available. Note
34
30
  # that the <tt>:json</tt> library is present in the standard
35
- # library in Ruby 1.9, but requires the "json" gem in Ruby 1.8.
31
+ # library in Ruby 1.9.
36
32
  # If a parser is not specified, then the decode method will not
37
33
  # accept a String or IO object; it will require a Hash.
38
34
 
39
- def initialize(opts_ = {})
40
- @geo_factory = opts_[:geo_factory] || ::RGeo::Cartesian.preferred_factory
41
- @entity_factory = opts_[:entity_factory] || EntityFactory.instance
42
- @json_parser = opts_[:json_parser]
35
+ def initialize(opts = {})
36
+ @geo_factory = opts[:geo_factory] || RGeo::Cartesian.preferred_factory
37
+ @entity_factory = opts[:entity_factory] || EntityFactory.instance
38
+ @json_parser = opts[:json_parser]
43
39
  case @json_parser
44
40
  when :json
45
- if @@json_available.nil?
46
- begin
47
- require "json"
48
- @@json_available = true
49
- rescue ::LoadError
50
- @@json_available = false
51
- end
52
- end
53
- if @@json_available
54
- @json_parser = ::Proc.new { |str_| ::JSON.parse(str_) }
55
- else
56
- raise Error::RGeoError, "JSON library is not available. You may need to install the 'json' gem."
57
- end
41
+ require "json" unless defined?(JSON)
42
+ @json_parser = proc { |str| JSON.parse(str) }
58
43
  when :yajl
59
- if @@yajl_available.nil?
60
- begin
61
- require "yajl"
62
- @@yajl_available = true
63
- rescue ::LoadError
64
- @@yajl_available = false
65
- end
66
- end
67
- if @@yajl_available
68
- @json_parser = ::Proc.new { |str_| ::Yajl::Parser.new.parse(str_) }
69
- else
70
- raise Error::RGeoError, "Yajl library is not available. You may need to install the 'yajl' gem."
71
- end
44
+ require "yajl" unless defined?(Yajl)
45
+ @json_parser = proc { |str| Yajl::Parser.new.parse(str) }
72
46
  when :active_support
73
- if @@activesupport_available.nil?
74
- begin
75
- require "active_support/json"
76
- @@activesupport_available = true
77
- rescue ::LoadError
78
- @@activesupport_available = false
79
- end
80
- end
81
- if @@activesupport_available
82
- @json_parser = ::Proc.new { |str_| ::ActiveSupport::JSON.decode(str_) }
83
- else
84
- raise Error::RGeoError, "ActiveSupport::JSON library is not available. You may need to install the 'activesupport' gem."
85
- end
86
- when ::Proc, nil
47
+ require "active_support/json" unless defined?(ActiveSupport::JSON)
48
+ @json_parser = proc { |str| ActiveSupport::JSON.decode(str) }
49
+ when Proc, nil
87
50
  # Leave as is
88
51
  else
89
52
  raise ::ArgumentError, "Unrecognzied json_parser: #{@json_parser.inspect}"
@@ -105,18 +68,18 @@ module RGeo
105
68
  #
106
69
  # Returns nil if nil is passed in as the object.
107
70
 
108
- def encode(object_)
109
- if @entity_factory.is_feature_collection?(object_)
71
+ def encode(object)
72
+ if @entity_factory.is_feature_collection?(object)
110
73
  {
111
74
  "type" => "FeatureCollection",
112
- "features" => @entity_factory.map_feature_collection(object_) { |f_| _encode_feature(f_) },
75
+ "features" => @entity_factory.map_feature_collection(object) { |f| _encode_feature(f) },
113
76
  }
114
- elsif @entity_factory.is_feature?(object_)
115
- _encode_feature(object_)
116
- elsif object_.nil?
77
+ elsif @entity_factory.is_feature?(object)
78
+ _encode_feature(object)
79
+ elsif object.nil?
117
80
  nil
118
81
  else
119
- _encode_geometry(object_)
82
+ _encode_geometry(object)
120
83
  end
121
84
  end
122
85
 
@@ -124,31 +87,31 @@ module RGeo
124
87
  # String, or an IO object from which to read the JSON string.
125
88
  # If an error occurs, nil is returned.
126
89
 
127
- def decode(input_)
128
- if input_.kind_of?(::IO)
129
- input_ = input_.read rescue nil
90
+ def decode(input)
91
+ if input.is_a?(IO)
92
+ input = input.read rescue nil
130
93
  end
131
- if input_.kind_of?(::String)
132
- input_ = @json_parser.call(input_) rescue nil
94
+ if input.is_a?(String)
95
+ input = @json_parser.call(input) rescue nil
133
96
  end
134
- unless input_.kind_of?(::Hash)
97
+ unless input.is_a?(Hash)
135
98
  return nil
136
99
  end
137
- case input_["type"]
100
+ case input["type"]
138
101
  when "FeatureCollection"
139
- features_ = input_["features"]
140
- features_ = [] unless features_.kind_of?(::Array)
141
- decoded_features_ = []
142
- features_.each do |f_|
143
- if f_["type"] == "Feature"
144
- decoded_features_ << _decode_feature(f_)
102
+ features = input["features"]
103
+ features = [] unless features.is_a?(Array)
104
+ decoded_features = []
105
+ features.each do |f|
106
+ if f["type"] == "Feature"
107
+ decoded_features << _decode_feature(f)
145
108
  end
146
109
  end
147
- @entity_factory.feature_collection(decoded_features_)
110
+ @entity_factory.feature_collection(decoded_features)
148
111
  when "Feature"
149
- _decode_feature(input_)
112
+ _decode_feature(input)
150
113
  else
151
- _decode_geometry(input_)
114
+ _decode_geometry(input)
152
115
  end
153
116
  end
154
117
 
@@ -161,107 +124,107 @@ module RGeo
161
124
 
162
125
  attr_reader :entity_factory
163
126
 
164
- def _encode_feature(object_) # :nodoc:
165
- json_ = {
127
+ def _encode_feature(object) # :nodoc:
128
+ json = {
166
129
  "type" => "Feature",
167
- "geometry" => _encode_geometry(@entity_factory.get_feature_geometry(object_)),
168
- "properties" => @entity_factory.get_feature_properties(object_).dup,
130
+ "geometry" => _encode_geometry(@entity_factory.get_feature_geometry(object)),
131
+ "properties" => @entity_factory.get_feature_properties(object).dup,
169
132
  }
170
- id_ = @entity_factory.get_feature_id(object_)
171
- json_["id"] = id_ if id_
172
- json_
133
+ id = @entity_factory.get_feature_id(object)
134
+ json["id"] = id if id
135
+ json
173
136
  end
174
137
 
175
- def _encode_geometry(object_, point_encoder_ = nil) # :nodoc:
176
- unless point_encoder_
177
- if object_.factory.property(:has_z_coordinate)
178
- if object_.factory.property(:has_m_coordinate)
179
- point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.z, p_.m] }
138
+ def _encode_geometry(object, point_encoder = nil) # :nodoc:
139
+ unless point_encoder
140
+ if object.factory.property(:has_z_coordinate)
141
+ if object.factory.property(:has_m_coordinate)
142
+ point_encoder = proc { |p| [p.x, p.y, p.z, p.m] }
180
143
  else
181
- point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.z] }
144
+ point_encoder = proc { |p| [p.x, p.y, p.z] }
182
145
  end
183
146
  else
184
- if object_.factory.property(:has_m_coordinate)
185
- point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y, p_.m] }
147
+ if object.factory.property(:has_m_coordinate)
148
+ point_encoder = proc { |p| [p.x, p.y, p.m] }
186
149
  else
187
- point_encoder_ = ::Proc.new { |p_| [p_.x, p_.y] }
150
+ point_encoder = proc { |p| [p.x, p.y] }
188
151
  end
189
152
  end
190
153
  end
191
- case object_
192
- when ::RGeo::Feature::Point
154
+ case object
155
+ when RGeo::Feature::Point
193
156
  {
194
157
  "type" => "Point",
195
- "coordinates" => object_.coordinates
158
+ "coordinates" => object.coordinates
196
159
  }
197
- when ::RGeo::Feature::LineString
160
+ when RGeo::Feature::LineString
198
161
  {
199
162
  "type" => "LineString",
200
- "coordinates" => object_.coordinates
163
+ "coordinates" => object.coordinates
201
164
  }
202
- when ::RGeo::Feature::Polygon
165
+ when RGeo::Feature::Polygon
203
166
  {
204
167
  "type" => "Polygon",
205
- "coordinates" => object_.coordinates
168
+ "coordinates" => object.coordinates
206
169
  }
207
- when ::RGeo::Feature::MultiPoint
170
+ when RGeo::Feature::MultiPoint
208
171
  {
209
172
  "type" => "MultiPoint",
210
- "coordinates" => object_.coordinates
173
+ "coordinates" => object.coordinates
211
174
  }
212
- when ::RGeo::Feature::MultiLineString
175
+ when RGeo::Feature::MultiLineString
213
176
  {
214
177
  "type" => "MultiLineString",
215
- "coordinates" => object_.coordinates
178
+ "coordinates" => object.coordinates
216
179
  }
217
- when ::RGeo::Feature::MultiPolygon
180
+ when RGeo::Feature::MultiPolygon
218
181
  {
219
182
  "type" => "MultiPolygon",
220
- "coordinates" => object_.coordinates
183
+ "coordinates" => object.coordinates
221
184
  }
222
- when ::RGeo::Feature::GeometryCollection
185
+ when RGeo::Feature::GeometryCollection
223
186
  {
224
187
  "type" => "GeometryCollection",
225
- "geometries" => object_.map { |geom_| _encode_geometry(geom_, point_encoder_) },
188
+ "geometries" => object.map { |geom| _encode_geometry(geom, point_encoder) },
226
189
  }
227
190
  else
228
191
  nil
229
192
  end
230
193
  end
231
194
 
232
- def _decode_feature(input_) # :nodoc:
233
- geometry_ = input_["geometry"]
234
- if geometry_
235
- geometry_ = _decode_geometry(geometry_)
236
- return nil unless geometry_
195
+ def _decode_feature(input) # :nodoc:
196
+ geometry = input["geometry"]
197
+ if geometry
198
+ geometry = _decode_geometry(geometry)
199
+ return nil unless geometry
237
200
  end
238
- @entity_factory.feature(geometry_, input_["id"], input_["properties"])
201
+ @entity_factory.feature(geometry, input["id"], input["properties"])
239
202
  end
240
203
 
241
- def _decode_geometry(input_) # :nodoc:
242
- case input_["type"]
204
+ def _decode_geometry(input) # :nodoc:
205
+ case input["type"]
243
206
  when "GeometryCollection"
244
- _decode_geometry_collection(input_)
207
+ _decode_geometry_collection(input)
245
208
  when "Point"
246
- _decode_point_coords(input_["coordinates"])
209
+ _decode_point_coords(input["coordinates"])
247
210
  when "LineString"
248
- _decode_line_string_coords(input_["coordinates"])
211
+ _decode_line_string_coords(input["coordinates"])
249
212
  when "Polygon"
250
- _decode_polygon_coords(input_["coordinates"])
213
+ _decode_polygon_coords(input["coordinates"])
251
214
  when "MultiPoint"
252
- _decode_multi_point_coords(input_["coordinates"])
215
+ _decode_multi_point_coords(input["coordinates"])
253
216
  when "MultiLineString"
254
- _decode_multi_line_string_coords(input_["coordinates"])
217
+ _decode_multi_line_string_coords(input["coordinates"])
255
218
  when "MultiPolygon"
256
- _decode_multi_polygon_coords(input_["coordinates"])
219
+ _decode_multi_polygon_coords(input["coordinates"])
257
220
  else
258
221
  nil
259
222
  end
260
223
  end
261
224
 
262
- def _decode_geometry_collection(input_) # :nodoc:
263
- geometries_ = input_["geometries"]
264
- geometries_ = [] unless geometries_.kind_of?(::Array)
225
+ def _decode_geometry_collection(input) # :nodoc:
226
+ geometries_ = input["geometries"]
227
+ geometries_ = [] unless geometries_.is_a?(Array)
265
228
  decoded_geometries_ = []
266
229
  geometries_.each do |g_|
267
230
  g_ = _decode_geometry(g_)
@@ -270,69 +233,69 @@ module RGeo
270
233
  @geo_factory.collection(decoded_geometries_)
271
234
  end
272
235
 
273
- def _decode_point_coords(point_coords_) # :nodoc:
274
- return nil unless point_coords_.kind_of?(::Array)
275
- @geo_factory.point(*(point_coords_[0...@num_coordinates].map(&:to_f))) rescue nil
236
+ def _decode_point_coords(point_coords) # :nodoc:
237
+ return nil unless point_coords.is_a?(Array)
238
+ @geo_factory.point(*(point_coords[0...@num_coordinates].map(&:to_f))) rescue nil
276
239
  end
277
240
 
278
- def _decode_line_string_coords(line_coords_) # :nodoc:
279
- return nil unless line_coords_.kind_of?(::Array)
280
- points_ = []
281
- line_coords_.each do |point_coords_|
282
- point_ = _decode_point_coords(point_coords_)
283
- points_ << point_ if point_
241
+ def _decode_line_string_coords(line_coords) # :nodoc:
242
+ return nil unless line_coords.is_a?(Array)
243
+ points = []
244
+ line_coords.each do |point_coords|
245
+ point = _decode_point_coords(point_coords)
246
+ points << point if point
284
247
  end
285
- @geo_factory.line_string(points_)
248
+ @geo_factory.line_string(points)
286
249
  end
287
250
 
288
- def _decode_polygon_coords(poly_coords_) # :nodoc:
289
- return nil unless poly_coords_.kind_of?(::Array)
290
- rings_ = []
291
- poly_coords_.each do |ring_coords_|
292
- return nil unless ring_coords_.kind_of?(::Array)
293
- points_ = []
294
- ring_coords_.each do |point_coords_|
295
- point_ = _decode_point_coords(point_coords_)
296
- points_ << point_ if point_
251
+ def _decode_polygon_coords(poly_coords) # :nodoc:
252
+ return nil unless poly_coords.is_a?(Array)
253
+ rings = []
254
+ poly_coords.each do |ring_coords|
255
+ return nil unless ring_coords.is_a?(Array)
256
+ points = []
257
+ ring_coords.each do |point_coords|
258
+ point = _decode_point_coords(point_coords)
259
+ points << point if point
297
260
  end
298
- ring_ = @geo_factory.linear_ring(points_)
299
- rings_ << ring_ if ring_
261
+ ring = @geo_factory.linear_ring(points)
262
+ rings << ring if ring
300
263
  end
301
- if rings_.size == 0
264
+ if rings.size == 0
302
265
  nil
303
266
  else
304
- @geo_factory.polygon(rings_[0], rings_[1..-1])
267
+ @geo_factory.polygon(rings[0], rings[1..-1])
305
268
  end
306
269
  end
307
270
 
308
- def _decode_multi_point_coords(multi_point_coords_) # :nodoc:
309
- return nil unless multi_point_coords_.kind_of?(::Array)
310
- points_ = []
311
- multi_point_coords_.each do |point_coords_|
312
- point_ = _decode_point_coords(point_coords_)
313
- points_ << point_ if point_
271
+ def _decode_multi_point_coords(multi_point_coords) # :nodoc:
272
+ return nil unless multi_point_coords.is_a?(Array)
273
+ points = []
274
+ multi_point_coords.each do |point_coords|
275
+ point = _decode_point_coords(point_coords)
276
+ points << point if point
314
277
  end
315
- @geo_factory.multi_point(points_)
278
+ @geo_factory.multi_point(points)
316
279
  end
317
280
 
318
- def _decode_multi_line_string_coords(multi_line_coords_) # :nodoc:
319
- return nil unless multi_line_coords_.kind_of?(::Array)
320
- lines_ = []
321
- multi_line_coords_.each do |line_coords_|
322
- line_ = _decode_line_string_coords(line_coords_)
323
- lines_ << line_ if line_
281
+ def _decode_multi_line_string_coords(multi_line_coords) # :nodoc:
282
+ return nil unless multi_line_coords.is_a?(Array)
283
+ lines = []
284
+ multi_line_coords.each do |line_coords|
285
+ line = _decode_line_string_coords(line_coords)
286
+ lines << line if line
324
287
  end
325
- @geo_factory.multi_line_string(lines_)
288
+ @geo_factory.multi_line_string(lines)
326
289
  end
327
290
 
328
- def _decode_multi_polygon_coords(multi_polygon_coords_) # :nodoc:
329
- return nil unless multi_polygon_coords_.kind_of?(::Array)
330
- polygons_ = []
331
- multi_polygon_coords_.each do |poly_coords_|
332
- poly_ = _decode_polygon_coords(poly_coords_)
333
- polygons_ << poly_ if poly_
291
+ def _decode_multi_polygon_coords(multi_polygon_coords) # :nodoc:
292
+ return nil unless multi_polygon_coords.is_a?(Array)
293
+ polygons = []
294
+ multi_polygon_coords.each do |poly_coords|
295
+ poly = _decode_polygon_coords(poly_coords)
296
+ polygons << poly if poly
334
297
  end
335
- @geo_factory.multi_polygon(polygons_)
298
+ @geo_factory.multi_polygon(polygons)
336
299
  end
337
300
  end
338
301
  end
@@ -14,17 +14,17 @@ module RGeo
14
14
  # Create a feature wrapping the given geometry, with the given ID
15
15
  # and properties.
16
16
 
17
- def initialize(geometry_, id_ = nil, properties_ = {})
18
- @geometry = geometry_
19
- @id = id_
17
+ def initialize(geometry, id = nil, properties = {})
18
+ @geometry = geometry
19
+ @id = id
20
20
  @properties = {}
21
- properties_.each do |k_, v_|
22
- @properties[k_.to_s] = v_
21
+ properties.each do |k, v|
22
+ @properties[k.to_s] = v
23
23
  end
24
24
  end
25
25
 
26
26
  def inspect # :nodoc:
27
- "#<#{self.class}:0x#{object_id.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
27
+ "#<#{self.class}:0x#{objectid.to_s(16)} id=#{@id.inspect} geom=#{@geometry ? @geometry.as_text.inspect : 'nil'}>"
28
28
  end
29
29
 
30
30
  def to_s # :nodoc:
@@ -40,8 +40,8 @@ module RGeo
40
40
  # This method uses the eql? method to test geometry equality, which
41
41
  # may behave differently than the == operator.
42
42
 
43
- def eql?(rhs_)
44
- rhs_.kind_of?(Feature) && @geometry.eql?(rhs_.geometry) && @id.eql?(rhs_.feature_id) && @properties.eql?(rhs_.instance_variable_get(:@properties))
43
+ def eql?(other)
44
+ other.is_a?(Feature) && @geometry.eql?(other.geometry) && @id.eql?(other.feature_id) && @properties.eql?(other.instance_variable_get(:@properties))
45
45
  end
46
46
 
47
47
  # Two features are equal if their geometries, IDs, and properties
@@ -49,8 +49,8 @@ module RGeo
49
49
  # This method uses the == operator to test geometry equality, which
50
50
  # may behave differently than the eql? method.
51
51
 
52
- def ==(rhs_)
53
- rhs_.kind_of?(Feature) && @geometry == rhs_.geometry && @id == rhs_.feature_id && @properties == rhs_.instance_variable_get(:@properties)
52
+ def ==(other)
53
+ other.is_a?(Feature) && @geometry == other.geometry && @id == other.feature_id && @properties == other.instance_variable_get(:@properties)
54
54
  end
55
55
 
56
56
  # Returns the geometry contained in this feature, which may be nil.
@@ -72,8 +72,8 @@ module RGeo
72
72
  # Gets the value of the given named property.
73
73
  # Returns nil if the given property is not found.
74
74
 
75
- def property(key_)
76
- @properties[key_.to_s]
75
+ def property(key)
76
+ @properties[key.to_s]
77
77
  end
78
78
  alias_method :[], :property
79
79
 
@@ -95,14 +95,14 @@ module RGeo
95
95
  # between the GeoJSON engine and feature collections.
96
96
 
97
97
  class FeatureCollection
98
- include ::Enumerable
98
+ include Enumerable
99
99
 
100
100
  # Create a new FeatureCollection with the given features, which must
101
101
  # be provided as an Enumerable.
102
102
 
103
- def initialize(features_ = [])
103
+ def initialize(features = [])
104
104
  @features = []
105
- features_.each { |f_| @features << f_ if f_.kind_of?(Feature) }
105
+ features.each { |f| @features << f if f.is_a?(Feature) }
106
106
  end
107
107
 
108
108
  def inspect # :nodoc:
@@ -122,8 +122,8 @@ module RGeo
122
122
  # This methods uses the eql? method to test geometry equality, which
123
123
  # may behave differently than the == operator.
124
124
 
125
- def eql?(rhs_)
126
- rhs_.kind_of?(FeatureCollection) && @features.eql?(rhs_.instance_variable_get(:@features))
125
+ def eql?(other)
126
+ other.is_a?(FeatureCollection) && @features.eql?(other.instance_variable_get(:@features))
127
127
  end
128
128
 
129
129
  # Two feature collections are equal if they contain the same
@@ -131,14 +131,14 @@ module RGeo
131
131
  # This methods uses the == operator to test geometry equality, which
132
132
  # may behave differently than the eql? method.
133
133
 
134
- def ==(rhs_)
135
- rhs_.kind_of?(FeatureCollection) && @features == rhs_.instance_variable_get(:@features)
134
+ def ==(other)
135
+ other.is_a?(FeatureCollection) && @features == other.instance_variable_get(:@features)
136
136
  end
137
137
 
138
138
  # Iterates or returns an iterator for the features.
139
139
 
140
- def each(&block_)
141
- @features.each(&block_)
140
+ def each(&block)
141
+ @features.each(&block)
142
142
  end
143
143
 
144
144
  # Returns the number of features contained in this collection.
@@ -149,8 +149,8 @@ module RGeo
149
149
 
150
150
  # Access a feature by index.
151
151
 
152
- def [](index_)
153
- @features[index_]
152
+ def [](index)
153
+ @features[index]
154
154
  end
155
155
  end
156
156
 
@@ -163,55 +163,55 @@ module RGeo
163
163
  # properties hash. Note that, per the GeoJSON spec, geometry and/or
164
164
  # properties may be nil.
165
165
 
166
- def feature(geometry_, id_ = nil, properties_ = nil)
167
- Feature.new(geometry_, id_, properties_ || {})
166
+ def feature(geometry, id = nil, properties = nil)
167
+ Feature.new(geometry, id, properties || {})
168
168
  end
169
169
 
170
170
  # Create and return a new feature collection, given an enumerable
171
171
  # of feature objects.
172
172
 
173
- def feature_collection(features_ = [])
174
- FeatureCollection.new(features_)
173
+ def feature_collection(features = [])
174
+ FeatureCollection.new(features)
175
175
  end
176
176
 
177
177
  # Returns true if the given object is a feature created by this
178
178
  # entity factory.
179
179
 
180
- def is_feature?(object_)
181
- object_.kind_of?(Feature)
180
+ def is_feature?(object)
181
+ object.is_a?(Feature)
182
182
  end
183
183
 
184
184
  # Returns true if the given object is a feature collection created
185
185
  # by this entity factory.
186
186
 
187
- def is_feature_collection?(object_)
188
- object_.kind_of?(FeatureCollection)
187
+ def is_feature_collection?(object)
188
+ object.is_a?(FeatureCollection)
189
189
  end
190
190
 
191
191
  # Run Enumerable#map on the features contained in the given feature
192
192
  # collection.
193
193
 
194
- def map_feature_collection(object_, &block_)
195
- object_.map(&block_)
194
+ def map_feature_collection(object, &block)
195
+ object.map(&block)
196
196
  end
197
197
 
198
198
  # Returns the geometry associated with the given feature.
199
199
 
200
- def get_feature_geometry(object_)
201
- object_.geometry
200
+ def get_feature_geometry(object)
201
+ object.geometry
202
202
  end
203
203
 
204
204
  # Returns the ID of the given feature, or nil for no ID.
205
205
 
206
- def get_feature_id(object_)
207
- object_.feature_id
206
+ def get_feature_id(object)
207
+ object.feature_id
208
208
  end
209
209
 
210
210
  # Returns the properties of the given feature as a hash. Editing
211
211
  # this hash does not change the state of the feature.
212
212
 
213
- def get_feature_properties(object_)
214
- object_.properties
213
+ def get_feature_properties(object)
214
+ object.properties
215
215
  end
216
216
 
217
217
  # Return the singleton instance of EntityFactory.
@@ -12,8 +12,8 @@ module RGeo
12
12
  # encode supports objects of type RGeo::GeoJSON::Feature and
13
13
  # RGeo::GeoJSON::FeatureCollection.
14
14
 
15
- def encode(object_, opts_ = {})
16
- Coder.new(opts_).encode(object_)
15
+ def encode(object, opts = {})
16
+ Coder.new(opts).encode(object)
17
17
  end
18
18
 
19
19
  # High-level convenience routine for decoding an object from GeoJSON.
@@ -43,8 +43,8 @@ module RGeo
43
43
  # If a parser is not specified, then the decode method will not
44
44
  # accept a String or IO object; it will require a Hash.
45
45
 
46
- def decode(input_, opts_ = {})
47
- Coder.new(opts_).decode(input_)
46
+ def decode(input_, opts = {})
47
+ Coder.new(opts).decode(input_)
48
48
  end
49
49
 
50
50
  # Creates and returns a coder object of type RGeo::GeoJSON::Coder
@@ -75,8 +75,8 @@ module RGeo
75
75
  # If a parser is not specified, then the decode method will not
76
76
  # accept a String or IO object; it will require a Hash.
77
77
 
78
- def coder(opts_ = {})
79
- Coder.new(opts_)
78
+ def coder(opts = {})
79
+ Coder.new(opts)
80
80
  end
81
81
  end
82
82
  end
@@ -1,5 +1,5 @@
1
1
  module RGeo
2
2
  module GeoJSON
3
- VERSION = "0.3.3".freeze
3
+ VERSION = "0.4.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo-geojson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-23 00:00:00.000000000 Z
12
+ date: 2015-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgeo
@@ -80,7 +80,6 @@ files:
80
80
  - LICENSE.txt
81
81
  - README.md
82
82
  - lib/rgeo-geojson.rb
83
- - lib/rgeo/geo_json.rb
84
83
  - lib/rgeo/geo_json/coder.rb
85
84
  - lib/rgeo/geo_json/entities.rb
86
85
  - lib/rgeo/geo_json/interface.rb
data/lib/rgeo/geo_json.rb DELETED
@@ -1,20 +0,0 @@
1
- require "rgeo"
2
-
3
- # RGeo is a spatial data library for Ruby, provided by the "rgeo" gem.
4
- #
5
- # The optional RGeo::GeoJSON module provides a set of tools for GeoJSON
6
- # encoding and decoding.
7
-
8
- module RGeo
9
- # This is a namespace for a set of tools that provide GeoJSON encoding.
10
- # See http://geojson.org/ for more information about this specification.
11
-
12
- module GeoJSON
13
- end
14
- end
15
-
16
- # Implementation files
17
- require "rgeo/geo_json/version"
18
- require "rgeo/geo_json/entities"
19
- require "rgeo/geo_json/coder"
20
- require "rgeo/geo_json/interface"