Class: Dse::Graph::Result
- Inherits:
-
Object
- Object
- Dse::Graph::Result
- Defined in:
- lib/dse/graph/result.rb
Overview
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Hash representation of the JSON result of a graph query if it's a complex result.
Instance Method Summary collapse
-
#as_edge ⇒ Edge
Coerce this result into an Edge object.
-
#as_path ⇒ Path
Coerce this result into a Path object.
-
#as_vertex ⇒ Vertex
Coerce this result into a Vertex object.
-
#cast ⇒ Vertex, ...
Coerce this result into a domain object if possible.
Instance Attribute Details
#value ⇒ Object (readonly)
Returns hash representation of the JSON result of a graph query if it's a complex result. A simple value otherwise.
20 21 22 |
# File 'lib/dse/graph/result.rb', line 20 def value @value end |
Instance Method Details
#as_edge ⇒ Edge
Coerce this result into an Edge object.
52 53 54 55 56 57 |
# File 'lib/dse/graph/result.rb', line 52 def as_edge Cassandra::Util.assert_instance_of(::Hash, @value) Dse::Graph::Edge.new(@value['id'], @value['label'], @value.fetch('properties', {}), @value['inV'], @value['inVLabel'], @value['outV'], @value['outVLabel']) end |
#as_path ⇒ Path
Coerce this result into a Path object.
61 62 63 64 |
# File 'lib/dse/graph/result.rb', line 61 def as_path Cassandra::Util.assert_instance_of(::Hash, @value) Dse::Graph::Path.new(@value['labels'], @value['objects']) end |
#as_vertex ⇒ Vertex
Coerce this result into a Vertex object.
44 45 46 47 |
# File 'lib/dse/graph/result.rb', line 44 def as_vertex Cassandra::Util.assert_instance_of(::Hash, @value) Dse::Graph::Vertex.new(@value['id'], @value['label'], @value.fetch('properties', {})) end |
#cast ⇒ Vertex, ...
Coerce this result into a domain object if possible.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dse/graph/result.rb', line 29 def cast type = @value['type'] if @value.is_a?(Hash) case type when 'vertex' as_vertex when 'edge' as_edge else self end end |