Class: Neography::NodeTraverser
- Inherits:
-
Object
- Object
- Neography::NodeTraverser
- Includes:
- Enumerable
- Defined in:
- lib/neography/node_traverser.rb
Instance Attribute Summary collapse
-
#depth(d) ⇒ Object
Returns the value of attribute depth.
-
#filter(body) ⇒ Object
Returns the value of attribute filter.
-
#order(o) ⇒ Object
Returns the value of attribute order.
-
#prune(body) ⇒ Object
Returns the value of attribute prune.
-
#relationships ⇒ Object
Returns the value of attribute relationships.
-
#uniqueness(u) ⇒ Object
Returns the value of attribute uniqueness.
Instance Method Summary collapse
- #<<(other_node) ⇒ Object
- #[](index) ⇒ Object
- #both(type) ⇒ Object
- #create(other_node) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #include_start_node ⇒ Object
- #incoming(type) ⇒ Object
-
#initialize(from, types = nil, dir = "all") ⇒ NodeTraverser
constructor
A new instance of NodeTraverser.
- #iterator ⇒ Object
- #outgoing(type) ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
#initialize(from, types = nil, dir = "all") ⇒ NodeTraverser
Returns a new instance of NodeTraverser.
7 8 9 10 11 12 13 14 15 |
# File 'lib/neography/node_traverser.rb', line 7 def initialize(from, types = nil, dir = "all" ) @from = from @order = "depth first" @uniqueness = "none" @relationships = Array.new types.each do |type| @relationships << {"type" => type.to_s, "direction" => dir.to_s } end unless types.nil? end |
Instance Attribute Details
#depth(d) ⇒ Object
Returns the value of attribute depth.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def depth @depth end |
#filter(body) ⇒ Object
Returns the value of attribute filter.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def filter @filter end |
#order(o) ⇒ Object
Returns the value of attribute order.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def order @order end |
#prune(body) ⇒ Object
Returns the value of attribute prune.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def prune @prune end |
#relationships ⇒ Object
Returns the value of attribute relationships.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def relationships @relationships end |
#uniqueness(u) ⇒ Object
Returns the value of attribute uniqueness.
5 6 7 |
# File 'lib/neography/node_traverser.rb', line 5 def uniqueness @uniqueness end |
Instance Method Details
#<<(other_node) ⇒ Object
17 18 19 20 |
# File 'lib/neography/node_traverser.rb', line 17 def <<(other_node) create(other_node) self end |
#[](index) ⇒ Object
94 95 96 |
# File 'lib/neography/node_traverser.rb', line 94 def [](index) each_with_index {|node,i| break node if index == i} end |
#both(type) ⇒ Object
36 37 38 39 |
# File 'lib/neography/node_traverser.rb', line 36 def both(type) @relationships << {"type" => type.to_s, "direction" => "all"} self end |
#create(other_node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/neography/node_traverser.rb', line 22 def create(other_node) case @relationships.first["direction"] when "outgoing", "out" rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node)) when "incoming", "in" rel = Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from)) else rel = Array.new rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], @from, other_node)) rel << Neography::Relationship.new(@from.neo_server.create_relationship(@relationships.first["type"], other_node, @from)) end rel end |
#each ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/neography/node_traverser.rb', line 102 def each iterator.each do |i| node = @from.class.new(i) node.neo_server = @from.neo_server yield node end end |
#empty? ⇒ Boolean
98 99 100 |
# File 'lib/neography/node_traverser.rb', line 98 def empty? first == nil end |
#include_start_node ⇒ Object
81 82 83 84 85 86 |
# File 'lib/neography/node_traverser.rb', line 81 def include_start_node @filter = Hash.new @filter["language"] = "builtin" @filter["name"] = "all" self end |
#incoming(type) ⇒ Object
46 47 48 49 |
# File 'lib/neography/node_traverser.rb', line 46 def incoming(type) @relationships << {"type" => type.to_s, "direction" => "in"} self end |
#iterator ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/neography/node_traverser.rb', line 110 def iterator = Hash.new ["order"] = @order ["uniqueness"] = @uniqueness ["relationships"] = @relationships ["prune evaluator"] = @prune unless @prune.nil? ["return filter"] = @filter unless @filter.nil? ["depth"] = @depth unless @depth.nil? if @relationships[0]["type"].empty? rels = @from.neo_server.get_node_relationships(@from, @relationships[0]["direction"]) case @relationships[0]["direction"] when "in" rels.collect { |r| @from.neo_server.get_node(r["start"]) } #.uniq when "out" rels.collect { |r| @from.neo_server.get_node(r["end"]) } #.uniq else rels.collect { |r| if @from.neo_id == r["start"].split('/').last @from.neo_server.get_node(r["end"]) else @from.neo_server.get_node(r["start"]) end } #.uniq end else @from.neo_server.traverse(@from, "nodes", ) end end |
#outgoing(type) ⇒ Object
41 42 43 44 |
# File 'lib/neography/node_traverser.rb', line 41 def outgoing(type) @relationships << {"type" => type.to_s, "direction" => "out"} self end |
#size ⇒ Object Also known as: length
88 89 90 |
# File 'lib/neography/node_traverser.rb', line 88 def size [*self].size end |