Class: N4j::Traversal

Inherits:
Object
  • Object
show all
Defined in:
lib/n4j/traversal.rb

Constant Summary collapse

PARAMETERS =
[:order, :uniqueness, :return_filter, :prune_evaluator, :relationships, :max_depth]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Traversal

Returns a new instance of Traversal.



6
7
8
9
10
# File 'lib/n4j/traversal.rb', line 6

def initialize(opts ={})
  opts.each_pair do |k,v|
    send "#{k}=", v if respond_to?("#{k}=")
  end
end

Instance Attribute Details

#return_typeObject

Returns the value of attribute return_type.



4
5
6
# File 'lib/n4j/traversal.rb', line 4

def return_type
  @return_type
end

#startObject

Returns the value of attribute start.



4
5
6
# File 'lib/n4j/traversal.rb', line 4

def start
  @start
end

Instance Method Details

#goObject



59
60
61
# File 'lib/n4j/traversal.rb', line 59

def go
  N4j.batch([{:to => "#{start}/traverse/#{return_type}", :method => 'POST', :body => traversal}])
end

#inbound(type) ⇒ Object



22
23
24
25
26
# File 'lib/n4j/traversal.rb', line 22

def inbound(type)
  self.relationships ||= []
  self.relationships << {'direction' => 'in', 'type' => type}
  self
end

#outbound(type) ⇒ Object



16
17
18
19
20
# File 'lib/n4j/traversal.rb', line 16

def outbound(type)
  self.relationships ||= []
  self.relationships << {'direction' => 'out', 'type' => type}
  self
end

#traversalObject

{

"order" : "breadth_first",
"return_filter" : {
  "body" : "position.endNode().getProperty('name').toLowerCase().contains('t')",
  "language" : "javascript"
},
"prune_evaluator" : {
  "body" : "position.length() > 10",
  "language" : "javascript"
},
"uniqueness" : "node_global",
"relationships" : [ {
  "direction" : "all",
  "type" : "knows"
}, {
  "direction" : "all",
  "type" : "loves"
} ],
"max_depth" : 3

}



49
50
51
52
53
54
55
56
57
# File 'lib/n4j/traversal.rb', line 49

def traversal
  # {"relationships" => [{'direction' => 'in', 'type' => 'is_a' }]}
  self.class::PARAMETERS.inject({}) do |sum, n|
    key = :"@#{n}"
    val = instance_variable_defined?(key) && instance_variable_get(key)
    sum[n] = val if val
    sum
  end
end