Class: AllegroGraph::Proxy::Geometric

Inherits:
Object
  • Object
show all
Defined in:
lib/allegro_graph/proxy/geometric.rb

Overview

The Geometric class acts as proxy to the geo-functions of the AllegroGraph server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Geometric

Returns a new instance of Geometric.



12
13
14
# File 'lib/allegro_graph/proxy/geometric.rb', line 12

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/allegro_graph/proxy/geometric.rb', line 10

def resource
  @resource
end

Instance Method Details

#cartesian_type(parameters = { }) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/allegro_graph/proxy/geometric.rb', line 20

def cartesian_type(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :cartesian_type
  type = @resource.request :post, self.path + "/types/cartesian", :parameters => parameters, :expected_status_code => 200
  type.sub! /^.*</, "<"
  type.sub! />.*$/, ">"
  type
end

#create_polygon(points, parameters = { }) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
# File 'lib/allegro_graph/proxy/geometric.rb', line 36

def create_polygon(points, parameters = { })
  type = parameters.delete :type
  parameters = Utility::ParameterMapper.map parameters, :create_polygon

  raise ArgumentError, "at least three points has to defined" unless points.is_a?(Array) && points.size >= 3
  parameters[:point] = points.map{ |point| "\"%+g%+g\"^^%s" % [ point[0], point[1], type ] }

  @resource.request :put, self.path + "/polygon", :parameters => parameters, :expected_status_code => 204
  true
end

#pathObject



16
17
18
# File 'lib/allegro_graph/proxy/geometric.rb', line 16

def path
  "#{@resource.path}/geo"
end

#spherical_type(parameters = { }) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/allegro_graph/proxy/geometric.rb', line 28

def spherical_type(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :spherical_type
  type = @resource.request :post, self.path + "/types/spherical", :parameters => parameters, :expected_status_code => 200
  type.sub! /^.*</, "<"
  type.sub! />.*$/, ">"
  type
end