Class: GeoRuby::GeojsonFeature
- Inherits:
-
Object
- Object
- GeoRuby::GeojsonFeature
- Defined in:
- lib/geo_ruby/geojson.rb
Overview
Class added to support geojson ‘Feature’ objects
Instance Attribute Summary collapse
-
#geometry ⇒ Object
Returns the value of attribute geometry.
-
#id ⇒ Object
Returns the value of attribute id.
-
#properties ⇒ Object
Returns the value of attribute properties.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json(options = {}) ⇒ Object
-
#initialize(geometry, properties = {}, id = nil) ⇒ GeojsonFeature
constructor
A new instance of GeojsonFeature.
- #to_json(options = {}) ⇒ Object (also: #as_geojson)
Constructor Details
#initialize(geometry, properties = {}, id = nil) ⇒ GeojsonFeature
Returns a new instance of GeojsonFeature.
20 21 22 23 24 |
# File 'lib/geo_ruby/geojson.rb', line 20 def initialize(geometry, properties = {}, id = nil) @geometry = geometry @properties = properties @id = id end |
Instance Attribute Details
#geometry ⇒ Object
Returns the value of attribute geometry.
18 19 20 |
# File 'lib/geo_ruby/geojson.rb', line 18 def geometry @geometry end |
#id ⇒ Object
Returns the value of attribute id.
18 19 20 |
# File 'lib/geo_ruby/geojson.rb', line 18 def id @id end |
#properties ⇒ Object
Returns the value of attribute properties.
18 19 20 |
# File 'lib/geo_ruby/geojson.rb', line 18 def properties @properties end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/geo_ruby/geojson.rb', line 26 def ==(other) if (self.class != other.class) false else (self.id == other.id) && (self.geometry == other.geometry) && (self.properties == other.properties) end end |
#as_json(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/geo_ruby/geojson.rb', line 34 def as_json(={}) output = {} output[:type] = 'Feature' output[:geometry] = geometry output[:properties] = properties output[:id] = id unless id.nil? output.as_json() end |
#to_json(options = {}) ⇒ Object Also known as: as_geojson
43 44 45 |
# File 'lib/geo_ruby/geojson.rb', line 43 def to_json( = {}) as_json().to_json end |