Class: Ruxster::Vertex

Inherits:
Base
  • Object
show all
Defined in:
lib/ruxster/vertex.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect_string, #create, create_index, #destroy, find, get, #id, #id=, indices, #initialize, #parameterize, #properties_hash, #type, #type=, #update

Constructor Details

This class inherits a constructor from Ruxster::Base

Class Method Details

.allObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ruxster/vertex.rb', line 46

def self.all
  objects = []
  response = Excon.get(Vertex.connect_string + "/vertices")
  if response
    results = JSON.parse(response.body)["results"]
    if results
      results.each do |hash|
        objects << self.new(hash)
      end
    end
  end
  objects
end

.create(hash = {}) ⇒ Object



40
41
42
43
44
# File 'lib/ruxster/vertex.rb', line 40

def self.create(hash={})
  edge = Vertex.new(hash)
  edge.create
  edge
end

.index_typeObject



9
10
11
# File 'lib/ruxster/vertex.rb', line 9

def self.index_type
  "vertex"
end

.url_directoryObject



6
7
8
# File 'lib/ruxster/vertex.rb', line 6

def self.url_directory
  "vertices"
end

Instance Method Details

#[](key) ⇒ Object



13
14
15
# File 'lib/ruxster/vertex.rb', line 13

def [](key)
  properties_hash[key]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/ruxster/vertex.rb', line 16

def []=(key, value)
  properties_hash[key] = value
end

#all_edges(which_edges = "bothE") ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruxster/vertex.rb', line 26

def all_edges(which_edges="bothE")
  edges = []
  response = Excon.get(Vertex.connect_string + "/vertices/#{self.id}/#{which_edges}")
  if response
    results = JSON.parse(response.body)["results"]
    if results
      results.each do |hash|
        edges << Edge.new(hash)
      end
    end
  end
  edges
end

#in_edgesObject



23
24
25
# File 'lib/ruxster/vertex.rb', line 23

def in_edges
  all_edges("inE")
end

#out_edgesObject



20
21
22
# File 'lib/ruxster/vertex.rb', line 20

def out_edges
  all_edges("outE")
end