Class: KVDAG::Edge

Inherits:
Object
  • Object
show all
Includes:
AttributeNode
Defined in:
lib/kvdag/edge.rb

Overview

An edge to a vertex in a KVDAG

Instance Attribute Summary collapse

Attributes included from AttributeNode

#attrs

Instance Method Summary collapse

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_vertexObject (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

#inspectObject 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?

Returns:

  • (Boolean)


42
43
44
# File 'lib/kvdag/edge.rb', line 42

def reachable?(target)
  @to_vertex.equal?(target) || @to_vertex.reachable?(target)
end

#to_hash_proxyObject

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