Class: Neo4j::Spatial::Geometry

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/spatial/geometry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options={})
  @gtype = (options.delete(:gtype) || options.delete('gtype') || Constants.GTYPE_GEOMETRY).to_i
  @geometry = (options.delete(:geometry) || options.delete('geometry') || options.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

#geometryObject (readonly)

Returns the value of attribute geometry.



6
7
8
# File 'lib/neo4j/spatial/geometry.rb', line 6

def geometry
  @geometry
end

#gtypeObject (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_mapObject

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_mapObject

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_sObject



21
22
23
# File 'lib/neo4j/spatial/geometry.rb', line 21

def to_s
  geometry
end