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.
18 19 20 21 |
# File 'lib/kvdag/edge.rb', line 18 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
9 10 11 |
# File 'lib/kvdag/edge.rb', line 9 def to_vertex @to_vertex end |
Instance Method Details
#inspect ⇒ Object Also known as: to_s
23 24 25 |
# File 'lib/kvdag/edge.rb', line 23 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?
42 43 44 |
# File 'lib/kvdag/edge.rb', line 42 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.
35 36 37 38 |
# File 'lib/kvdag/edge.rb', line 35 def to_hash_proxy result = @to_vertex.to_hash_proxy result.merge!(@attrs) end |