Class: Seafoam::Node
- Inherits:
-
Object
- Object
- Seafoam::Node
- Defined in:
- lib/seafoam/graph.rb
Overview
A node, with properties, input edges, and output edges.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
Instance Method Summary collapse
-
#adjacent ⇒ Object
All adjacent nodes - from input and output edges.
-
#edges ⇒ Object
All edges - input and output.
-
#id_and_label ⇒ Object
id (label).
-
#initialize(id, props = nil) ⇒ Node
constructor
A new instance of Node.
-
#inspect ⇒ Object
Inspect.
Constructor Details
#initialize(id, props = nil) ⇒ Node
Returns a new instance of Node.
53 54 55 56 57 58 59 |
# File 'lib/seafoam/graph.rb', line 53 def initialize(id, props = nil) props ||= {} @id = id @inputs = [] @outputs = [] @props = props end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
51 52 53 |
# File 'lib/seafoam/graph.rb', line 51 def id @id end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
51 52 53 |
# File 'lib/seafoam/graph.rb', line 51 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
51 52 53 |
# File 'lib/seafoam/graph.rb', line 51 def outputs @outputs end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
51 52 53 |
# File 'lib/seafoam/graph.rb', line 51 def props @props end |
Instance Method Details
#adjacent ⇒ Object
All adjacent nodes - from input and output edges.
67 68 69 |
# File 'lib/seafoam/graph.rb', line 67 def adjacent (inputs.map(&:from) + outputs.map(&:to)).uniq end |
#edges ⇒ Object
All edges - input and output.
62 63 64 |
# File 'lib/seafoam/graph.rb', line 62 def edges inputs + outputs end |
#id_and_label ⇒ Object
id (label)
72 73 74 75 76 77 78 |
# File 'lib/seafoam/graph.rb', line 72 def id_and_label if props[:label] "#{id} (#{props[:label]})" else id.to_s end end |
#inspect ⇒ Object
Inspect.
81 82 83 |
# File 'lib/seafoam/graph.rb', line 81 def inspect "<Node #{id}>" end |