Class: RedGrape::Vertex

Inherits:
Element show all
Includes:
Pipe::As, Pipe::Both, Pipe::Fill, Pipe::In, Pipe::InE, Pipe::Out, Pipe::OutE, Pipe::SideEffect
Defined in:
lib/red_grape/vertex.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pipe::Fill

#fill

Methods included from Pipe::As

#as

Methods included from Pipe::SideEffect

#side_effect

Methods included from Pipe::InE

#in_e

Methods included from Pipe::In

#in

Methods included from Pipe::OutE

#out_e

Methods included from Pipe::Out

#out

Methods included from Pipe::Both

#both

Methods inherited from Element

#<=>, #==, #[], #[]=, #directed_value, #method_missing, #pass_through, #property, #property_keys, #remove_property, #set_property

Constructor Details

#initialize(graph, id, opts = {}) ⇒ Vertex

Returns a new instance of Vertex.



16
17
18
19
20
21
# File 'lib/red_grape/vertex.rb', line 16

def initialize(graph, id, opts={})
  super graph, opts
  @id = id.to_s
  @out_edges = []
  @in_edges = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RedGrape::Element

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/red_grape/vertex.rb', line 14

def id
  @id
end

#in_edgesObject (readonly)

Returns the value of attribute in_edges.



14
15
16
# File 'lib/red_grape/vertex.rb', line 14

def in_edges
  @in_edges
end

#out_edgesObject (readonly)

Returns the value of attribute out_edges.



14
15
16
# File 'lib/red_grape/vertex.rb', line 14

def out_edges
  @out_edges
end

Instance Method Details

#add_in_edge(edge) ⇒ Object



44
45
46
# File 'lib/red_grape/vertex.rb', line 44

def add_in_edge(edge)
  @in_edges << edge
end

#add_out_edge(edge) ⇒ Object



40
41
42
# File 'lib/red_grape/vertex.rb', line 40

def add_out_edge(edge)
  @out_edges << edge
end

#edges(direction, *labels) ⇒ Object

Returns edges

direction

:out or :in

labels

labels



26
27
28
29
30
31
32
33
# File 'lib/red_grape/vertex.rb', line 26

def edges(direction, *labels)
  edges = directed_value direction, @out_edges, @in_edges
  if labels.empty?
    edges
  else
    edges.select {|e| labels.include? e.label}
  end
end

#to_hObject



52
53
54
55
56
57
58
59
60
# File 'lib/red_grape/vertex.rb', line 52

def to_h
  {
    version: RedGrape::VERSION,
    results: {
      _type: '_vertex',
      _id: @id
    }.merge(@property)
  }
end

#to_sObject



48
49
50
# File 'lib/red_grape/vertex.rb', line 48

def to_s
  "v[#{@id}]"
end

#vertices(direction, *labels) ⇒ Object



35
36
37
38
# File 'lib/red_grape/vertex.rb', line 35

def vertices(direction, *labels)
  edges = edges direction, *labels
  directed_value direction, proc{edges.map &:target}, proc{edges.map &:source}
end