Class: Neo4j::Spatial::Geometry
- Inherits:
-
Object
- Object
- Neo4j::Spatial::Geometry
- Defined in:
- lib/neo4j/spatial/geometry.rb
Instance Attribute Summary collapse
-
#geometry ⇒ Object
readonly
Returns the value of attribute geometry.
-
#gtype ⇒ Object
readonly
Returns the value of attribute gtype.
Class Method Summary collapse
-
.id_map ⇒ Object
Reverse map from integer id to string name.
- .id_to_string(gtype) ⇒ Object
-
.name_map ⇒ Object
Forward map from string name to integer id.
- .string_to_id(name) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Geometry
constructor
A new instance of Geometry.
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Geometry
Returns a new instance of Geometry.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/neo4j/spatial/geometry.rb', line 7 def initialize(={}) @gtype = (.delete(:gtype) || .delete('gtype') || Constants.GTYPE_GEOMETRY).to_i @geometry = (.delete(:geometry) || .delete('geometry') || .delete(:default) || 'geometry').to_s.downcase if @gtype != Geometry.string_to_id(@geometry) if @gtype == 0 @gtype = Geometry.string_to_id(geometry) #puts "Corrected gtype to #{gtype} for geometry #{geometry}" elsif @geometry == 'geometry' @geometry = Geometry.id_to_string(@gtype) #puts "Corrected geometry to #{geometry} for gtype #{gtype}" end end puts "Initialized Geometry with gtype=#{gtype}, geometry=#{geometry}" end |
Instance Attribute Details
#geometry ⇒ Object (readonly)
Returns the value of attribute geometry.
6 7 8 |
# File 'lib/neo4j/spatial/geometry.rb', line 6 def geometry @geometry end |
#gtype ⇒ Object (readonly)
Returns the value of attribute gtype.
6 7 8 |
# File 'lib/neo4j/spatial/geometry.rb', line 6 def gtype @gtype end |
Class Method Details
.id_map ⇒ Object
Reverse map from integer id to string name
29 30 31 |
# File 'lib/neo4j/spatial/geometry.rb', line 29 def self.id_map @id_map ||= name_map.to_a.inject({}){|a,v| a[v[1]]=v[0];a} end |
.id_to_string(gtype) ⇒ Object
35 36 37 |
# File 'lib/neo4j/spatial/geometry.rb', line 35 def self.id_to_string(gtype) id_map[gtype] || 'geometry' end |
.name_map ⇒ Object
Forward map from string name to integer id
25 26 27 |
# File 'lib/neo4j/spatial/geometry.rb', line 25 def self.name_map @name_map ||= Hash[Constants.constants.grep(/GTYPE_/).map{|v| [v.downcase.gsub(/gtype_/,''),Constants.const_get(v)]}] end |
.string_to_id(name) ⇒ Object
32 33 34 |
# File 'lib/neo4j/spatial/geometry.rb', line 32 def self.string_to_id(name) name_map[name].to_i end |
Instance Method Details
#to_s ⇒ Object
21 22 23 |
# File 'lib/neo4j/spatial/geometry.rb', line 21 def to_s geometry end |