Class: KVDAG::Edge
Overview
An edge to a vertex in a KVDAG
Instance Attribute Summary collapse
-
#to_vertex ⇒ Object
readonly
Return the target vertex of this edge.
Attributes included from AttributeNode
Instance Method Summary collapse
-
#initialize(dag, target, attrs = {}) ⇒ Edge
constructor
A new instance of Edge.
- #inspect ⇒ Object (also: #to_s)
-
#reachable?(target) ⇒ Boolean
Is the
target
vertex reachable via this edge?. -
#to_hash_proxy ⇒ Object
Return the proxied key-value hash tree visible from this edge via its target vertex and all its ancestors.
Methods included from AttributeNode
#[], #[]=, #fetch, #filter, #match?, #merge!, #to_hash
Constructor Details
#initialize(dag, target, attrs = {}) ⇒ Edge
Returns a new instance of Edge.
19 20 21 22 |
# File 'lib/kvdag/edge.rb', line 19 def initialize(dag, target, attrs = {}) @to_vertex = target @attrs = dag.hash_proxy_class.new(attrs) end |
Instance Attribute Details
#to_vertex ⇒ Object (readonly)
Return the target vertex of this edge
10 11 12 |
# File 'lib/kvdag/edge.rb', line 10 def to_vertex @to_vertex end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
24 25 26 |
# File 'lib/kvdag/edge.rb', line 24 def inspect "#<%s @attr=%s @to_vertex=%s>" % [self.class, @attrs.to_hash, @to_vertex] end |
#reachable?(target) ⇒ Boolean
Is the target
vertex reachable via this edge?
43 44 45 |
# File 'lib/kvdag/edge.rb', line 43 def reachable?(target) @to_vertex.equal?(target) || @to_vertex.reachable?(target) end |
#to_hash_proxy ⇒ Object
Return the proxied key-value hash tree visible from this edge via its target vertex and all its ancestors
Calling to_hash instead will return a regular hash tree, without any special properties, e.g. for serializing as YAML or JSON.
36 37 38 39 |
# File 'lib/kvdag/edge.rb', line 36 def to_hash_proxy result = @to_vertex.to_hash_proxy result.merge!(@attrs) end |