An individual result of running a graph query. It wraps the JSON result and provides access to it as a hash. It also supports casting the result into a known domain object type: Vertex, Edge, and Path currently.

See Also:
Specifications:
Result should handle vertex blobs
r = Result.new(vertex_hash('demigod', 'hercules', properties: { age: 29 }))
v = r.cast
expect(v.class).to be(Vertex)
expect(v.label).to eq('demigod')
expect(v.id['community_id']).to eq(12345)
expect(v.properties['name'][0].value).to eq('hercules')
expect(v.properties['age'][0].value).to eq(29)
expect(v.properties['age'][0].properties).to be_empty
expect(v['name'][0].value).to eq('hercules')
expect(v['age'][0].value).to eq(29)
Result should handle vertex blobs with multi-valued properties
r = Result.new(vertex_hash('demigod', 'hercules', properties: { friends: %w(aeolus xena) }))
v = r.cast
expect(v.class).to be(Vertex)
expect(v.label).to eq('demigod')
expect(v.id['community_id']).to eq(12345)
expect(v.properties['name'][0].value).to eq('hercules')
expect(v.properties['friends'][0].value).to eq('aeolus')
expect(v.properties['friends'][1].value).to eq('xena')
expect(v.properties['friends'][1].properties).to be_empty
expect(v.properties['friends'].values).to eq(%w(aeolus xena))
Result should handle vertex blobs with meta-properties
r = Result.new(vertex_hash('demigod', 'hercules', properties: { age: 29 }, include_meta: true))
v = r.cast
expect(v.class).to be(Vertex)
expect(v.label).to eq('demigod')
expect(v.id['community_id']).to eq(12345)
expect(v.properties['name'][0].value).to eq('hercules')
expect(v.properties['age'][0].properties['k0']).to eq('v0')
expect(v['age'][0]['k0']).to eq('v0')
Result should handle edge blobs properly
r = Result.new(edge_hash('father', 'god', 'titan', properties: { prop1: 'val1' }))
e = r.cast
expect(e.class).to be(Edge)
expect(e.label).to eq('father')
expect(e.in_v_label).to eq('god')
expect(e.out_v_label).to eq('titan')
expect(e.id['out_vertex']['community_id']).to eq(12345)
expect(e.properties['prop1']).to eq('val1')
expect(e['prop1']).to eq('val1')
Result should handle simple results properly
r = Result.new(7)
expect(r.cast).to be(r)
expect(r.value).to eq(7)
Result should handle path results properly
vertex1 = vertex_hash('demigod', 'hercules', properties: { age: 29 })
vertex2 = vertex_hash('god', 'jupiter', properties: { age: 5000 })
r = Result.new('labels' => [[], []], 'objects' => [vertex1, vertex2])
expect(r.cast).to be(r)
path = r.as_path
expect(path.labels).to eq([[], []])
expect(path.objects.size).to eq(2)
expect(path.objects[0].class).to be(Vertex)
expect(path.objects[0].label).to eq('demigod')
expect(path.objects[1].class).to be(Vertex)
expect(path.objects[1].label).to eq('god')

Inherits

Object

Methods

value

Returns hash representation of the JSON result of a graph query if it’s a complex result. A simple value otherwise

Returns:
Type Details
hash representation of the JSON result of a graph query if it’s a complex result. A simple value otherwise

cast

Coerce this result into a domain object if possible.

Returns:
Type Details
(Vertex, Edge or Result) a new wrapped object, or self if we can’t cast it

as_vertex

Coerce this result into a Vertex object.

Returns:
Type Details
Vertex a vertex domain object
Raises:
Type Details
ArgumentError if the result data does not represent a vertex

as_edge

Coerce this result into an Edge object.

Returns:
Type Details
Edge an edge domain object.
Raises:
Type Details
ArgumentError if the result data does not represent an edge.

as_path

Coerce this result into a Path object.

Returns:
Type Details
Path a path domain object.