Class: RedGrape::Edge
- Includes:
- Pipe::InV, Pipe::OutV
- Defined in:
- lib/red_grape/edge.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #connected?(v) ⇒ Boolean
-
#initialize(graph, id, source, target, label, opts = {}) ⇒ Edge
constructor
A new instance of Edge.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #vertex(direction) ⇒ Object
Methods included from Pipe::InV
Methods included from Pipe::OutV
Methods inherited from Element
#<=>, #==, #[], #[]=, #directed_value, #method_missing, #pass_through, #property, #property_keys, #remove_property, #set_property
Constructor Details
#initialize(graph, id, source, target, label, opts = {}) ⇒ Edge
Returns a new instance of Edge.
10 11 12 13 14 15 16 17 18 |
# File 'lib/red_grape/edge.rb', line 10 def initialize(graph, id, source, target, label, opts={}) super graph, opts @id = id @source = source.is_a?(Vertex) ? source : graph.vertex(source) @target = target.is_a?(Vertex) ? target : graph.vertex(target) @source.add_out_edge self @target.add_in_edge self @label = label 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.
8 9 10 |
# File 'lib/red_grape/edge.rb', line 8 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/red_grape/edge.rb', line 8 def label @label end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/red_grape/edge.rb', line 8 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
8 9 10 |
# File 'lib/red_grape/edge.rb', line 8 def target @target end |
Instance Method Details
#connected?(v) ⇒ Boolean
24 25 26 27 |
# File 'lib/red_grape/edge.rb', line 24 def connected?(v) id = v.is_a?(Vertex) ? v.id : v @source.id == id.to_s || @target.id == id.to_s end |
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/red_grape/edge.rb', line 33 def to_h { version: RedGrape::VERSION, results: { _type: '_edge', _id: @id, _label: @label, _source: @source.id, _target: @target.id }.merge(@property) } end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/red_grape/edge.rb', line 29 def to_s "e[#{@id}][#{@source.id}-#{@label}->#{@target.id}]" end |
#vertex(direction) ⇒ Object
20 21 22 |
# File 'lib/red_grape/edge.rb', line 20 def vertex(direction) directed_value direction, @target, @source end |