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.



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

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

Returns:

  • (Boolean)


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

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.



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