Class: N4j::Cypher
- Inherits:
-
Object
- Object
- N4j::Cypher
- Defined in:
- lib/n4j/cypher.rb
Constant Summary collapse
- PARAMETERS =
[:start, :match, :where, :return]
Class Method Summary collapse
Instance Method Summary collapse
- #go ⇒ Object
-
#initialize(opts = {}) ⇒ Cypher
constructor
A new instance of Cypher.
-
#next(type = nil) ⇒ Object
hops?.
- #return ⇒ Object
- #start=(entity) ⇒ Object
- #to_query ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Cypher
Returns a new instance of Cypher.
5 6 7 8 9 |
# File 'lib/n4j/cypher.rb', line 5 def initialize(opts ={}) opts.each_pair do |k,v| send "#{k}=", v if respond_to?("#{k}=") end end |
Class Method Details
.query(query) ⇒ Object
42 43 44 |
# File 'lib/n4j/cypher.rb', line 42 def self.query(query) N4j.batch([{:to => '/ext/CypherPlugin/graphdb/execute_query', :method => 'POST', :body => {'query' => query}}]).first['body'] end |
Instance Method Details
#go ⇒ Object
29 30 31 |
# File 'lib/n4j/cypher.rb', line 29 def go self.class.query(to_query) end |
#next(type = nil) ⇒ Object
hops?
11 12 13 14 15 |
# File 'lib/n4j/cypher.rb', line 11 def next(type = nil) # hops? start_var = start.sub(/start\s+/,'').sub(/\s*=.+/,'') self.match = "match (#{start_var})-->(b)" self end |
#return ⇒ Object
25 26 27 |
# File 'lib/n4j/cypher.rb', line 25 def return @return || (match && "return #{match.split(/\W+/).last}") end |
#start=(entity) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/n4j/cypher.rb', line 17 def start=(entity) @start = if entity.kind_of?(String) entity else "start a = #{entity.entity_type}(#{entity.to_key.first})" end end |
#to_query ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/n4j/cypher.rb', line 33 def to_query raise "start must contain 'start' (currently: '#{start}')" if start && !start.index('start') raise "match must contain 'match' (currently: '#{match}')" if match && !match.index('match') raise "where must contain 'where' (currently: '#{where}')" if where && !where.index('where') raise "return must contain 'return' (currently: '#{self.return}')" if self.return && !self.return.index('return') "#{start} #{match} #{where} #{self.return}" end |