Class: Graph::Attribute

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

Overview

An attribute for a graph, node, or edge. Really just a composable string (via #+) with a convenience method #<< that allows you to “paint” nodes and edges with this attribute.

Direct Known Subclasses

CompoundAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrObject Also known as: to_s

Returns the value of attribute attr

Returns:

  • (Object)

    the current value of attr



426
427
428
# File 'lib/graph.rb', line 426

def attr
  @attr
end

Instance Method Details

#+(style) ⇒ Object

Compose a new attribute from two existing attributes:

bad_nodes = red + filled + diamond


453
454
455
456
457
458
# File 'lib/graph.rb', line 453

def + style
  c = CompoundAttribute.new
  c.push self
  c.push style
  c
end

#<<(thing) ⇒ Object

“Paint” graphs, nodes, and edges with this attribute.

red << node1 << node2 << node3

is the same as:

node1.attributes << red
node2.attributes << red
node3.attributes << red


438
439
440
441
# File 'lib/graph.rb', line 438

def << thing
  thing.attributes << self
  self
end