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



462
463
464
# File 'lib/graph.rb', line 462

def attr
  @attr
end

Instance Method Details

#+(style) ⇒ Object

Compose a new attribute from two existing attributes:

bad_nodes = red + filled + diamond


489
490
491
492
493
494
# File 'lib/graph.rb', line 489

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


474
475
476
477
# File 'lib/graph.rb', line 474

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