Class: Seafoam::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/seafoam/graph.rb

Overview

A node, with properties, input edges, and output edges.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, props = nil) ⇒ Node

Returns a new instance of Node.



36
37
38
39
40
41
42
# File 'lib/seafoam/graph.rb', line 36

def initialize(id, props = nil)
  props ||= {}
  @id = id
  @inputs = []
  @outputs = []
  @props = props
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'lib/seafoam/graph.rb', line 34

def id
  @id
end

#inputsObject (readonly)

Returns the value of attribute inputs.



34
35
36
# File 'lib/seafoam/graph.rb', line 34

def inputs
  @inputs
end

#outputsObject (readonly)

Returns the value of attribute outputs.



34
35
36
# File 'lib/seafoam/graph.rb', line 34

def outputs
  @outputs
end

#propsObject (readonly)

Returns the value of attribute props.



34
35
36
# File 'lib/seafoam/graph.rb', line 34

def props
  @props
end

Instance Method Details

#adjacentObject

All adjacent nodes - from input and output edges.



50
51
52
# File 'lib/seafoam/graph.rb', line 50

def adjacent
  (inputs.map(&:from) + outputs.map(&:to)).uniq
end

#edgesObject

All edges - input and output.



45
46
47
# File 'lib/seafoam/graph.rb', line 45

def edges
  inputs + outputs
end

#id_and_labelObject

id (label)



55
56
57
58
59
60
61
# File 'lib/seafoam/graph.rb', line 55

def id_and_label
  if props[:label]
    "#{id} (#{props[:label]})"
  else
    id.to_s
  end
end

#inspectObject

Inspect.



64
65
66
# File 'lib/seafoam/graph.rb', line 64

def inspect
  "<Node #{id}>"
end