Class: Hexagonly::GeoJson
- Inherits:
-
Object
- Object
- Hexagonly::GeoJson
- Defined in:
- lib/hexagonly/geo_json.rb
Instance Attribute Summary collapse
-
#features ⇒ Object
readonly
Returns the value of attribute features.
Instance Method Summary collapse
-
#add_features(features) ⇒ Object
Adds features (Points, Spaces, Hexagons) that support the #to_geojson method.
-
#initialize(features = nil) ⇒ GeoJson
constructor
A new instance of GeoJson.
-
#to_json ⇒ String
Outputs the GeoJson string.
Constructor Details
#initialize(features = nil) ⇒ GeoJson
Returns a new instance of GeoJson.
9 10 11 |
# File 'lib/hexagonly/geo_json.rb', line 9 def initialize(features = nil) add_features(features) unless features.nil? end |
Instance Attribute Details
#features ⇒ Object (readonly)
Returns the value of attribute features.
6 7 8 |
# File 'lib/hexagonly/geo_json.rb', line 6 def features @features end |
Instance Method Details
#add_features(features) ⇒ Object
Adds features (Points, Spaces, Hexagons) that support the #to_geojson method.
16 17 18 19 20 21 |
# File 'lib/hexagonly/geo_json.rb', line 16 def add_features(features) @features ||= [] features.each do |feat| @features << feat.to_geojson end end |
#to_json ⇒ String
Outputs the GeoJson string.
26 27 28 29 30 31 |
# File 'lib/hexagonly/geo_json.rb', line 26 def to_json { :type => "FeatureCollection", :features => @features }.to_json end |