Class: RedGrape::Vertex
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#in_edges ⇒ Object
readonly
Returns the value of attribute in_edges.
-
#out_edges ⇒ Object
readonly
Returns the value of attribute out_edges.
Instance Method Summary collapse
- #add_in_edge(edge) ⇒ Object
- #add_out_edge(edge) ⇒ Object
-
#edges(direction, *labels) ⇒ Object
- Returns edges direction
- :out or :in labels
-
labels.
-
#initialize(graph, id, opts = {}) ⇒ Vertex
constructor
A new instance of Vertex.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #vertices(direction, *labels) ⇒ Object
Methods included from Pipe::Fill
Methods included from Pipe::As
Methods included from Pipe::SideEffect
Methods included from Pipe::InE
Methods included from Pipe::In
Methods included from Pipe::OutE
Methods included from Pipe::Out
Methods included from Pipe::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
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/red_grape/vertex.rb', line 14 def id @id end |
#in_edges ⇒ Object (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_edges ⇒ Object (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_h ⇒ Object
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_s ⇒ Object
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 |