Class: Agama::Traverser
- Inherits:
-
Object
- Object
- Agama::Traverser
- Defined in:
- lib/agama/traverser.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #along(edge_type) ⇒ Object
- #each ⇒ Object
- #incoming ⇒ Object
-
#initialize(db, graph) ⇒ Traverser
constructor
A new instance of Traverser.
- #of_type(node_type) ⇒ Object
- #outgoing ⇒ Object
- #set(params) ⇒ Object
- #undirected ⇒ Object
Constructor Details
#initialize(db, graph) ⇒ Traverser
Returns a new instance of Traverser.
6 7 8 9 10 11 12 13 |
# File 'lib/agama/traverser.rb', line 6 def initialize(db, graph) @cursor = db.e_cursor @search_key = "" @unset = true @graph = graph @from = nil @params = {} end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/agama/traverser.rb', line 4 def params @params end |
Instance Method Details
#along(edge_type) ⇒ Object
20 21 22 |
# File 'lib/agama/traverser.rb', line 20 def along(edge_type) self.set(:edge_type => edge_type) end |
#each ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/agama/traverser.rb', line 45 def each search_key = "" from = nil if @unset search_key = Keyify.range(@params) from = @graph.get_node(@params[:from]) @cursor.jump(search_key) @unset = false end while @cursor.key and Keyify.subkey?(search_key, @cursor.key) to, type, direction, directed = Keyify.parse(@cursor.key) if @cursor.value new_edge = Marshal.load(@cursor.value) new_edge[:type] = type new_edge[:directed] = directed if direction == "I" new_edge[:to] = from new_edge[:from] = @graph.get_node(to) else new_edge[:from] = from new_edge[:to] = @graph.get_node(to) end yield new_edge end @cursor.next end end |
#incoming ⇒ Object
29 30 31 32 |
# File 'lib/agama/traverser.rb', line 29 def incoming self.set(:edge_type => Config::DEFAULT_TYPE) unless @params[:edge_type] self.set(:direction => "I") end |
#of_type(node_type) ⇒ Object
39 40 41 42 43 |
# File 'lib/agama/traverser.rb', line 39 def of_type(node_type) self.set(:edge_type => Config::DEFAULT_TYPE) unless @params[:edge_type] self.set(:direction => "N") unless @params[:direction] self.set(:to_type => node_type) end |
#outgoing ⇒ Object
24 25 26 27 |
# File 'lib/agama/traverser.rb', line 24 def outgoing self.set(:edge_type => Config::DEFAULT_TYPE) unless @params[:edge_type] self.set(:direction => "O") end |
#set(params) ⇒ Object
15 16 17 18 |
# File 'lib/agama/traverser.rb', line 15 def set(params) @params.merge!(params) self end |
#undirected ⇒ Object
34 35 36 37 |
# File 'lib/agama/traverser.rb', line 34 def undirected self.set(:edge_type => Config::DEFAULT_TYPE) unless @params[:edge_type] self.set(:direction => "N") end |