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_http :post, self.path + "/types/cartesian", :parameters => parameters, :expected_status_code => 200
  type.sub! /^.*</, "<"
  type.sub! />.*$/, ">"
  type
end

#create_cartesian_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_cartesian_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_json :put, self.path + "/polygon", :parameters => parameters, :expected_status_code => 204
  true
end

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

Raises:

  • (ArgumentError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/allegro_graph/proxy/geometric.rb', line 47

def create_spherical_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 do |point|
    "\"" +
      Utility::ParameterMapper.latitude_to_iso(point[0]) +
      Utility::ParameterMapper.longitude_to_iso(point[1]) +
      "\"^^#{type}"
  end

  @resource.request_json :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_http :post, self.path + "/types/spherical", :parameters => parameters, :expected_status_code => 200
  type.sub! /^.*</, "<"
  type.sub! />.*$/, ">"
  type
end