DSL to build directed graphs
Add this line to your application's Gemfile:
gem 'graph_builder'
And then execute:
$ bundle
Or install it yourself as:
$ gem install graph_builder
GraphBuilder provides a DSL to build a graph of arbritary objects.
The objects must implement
link_to( other )
which must implement a link between self and other.
GraphBuilder::Builder.build do |builder|
builder.add a
builder.add b
builder.add c
end
GraphBuilder::Builder.build do |builder|
builder.add a
builder.branch do
builder.add b
builder.add c
end
end
GraphBuilder::Builder.build do |builder|
builder.add a
builder.branch do
builder.add l
builder.add r
end
builder.add b
end
GraphBuilder::Builder.build do |builder|
builder.add a
builder.branch do
builder.chain do
builder.add l1
builder.add l2
end
builder.chain do
builder.add r1
builder.add r2
builder.add r3
end
end
builder.add b
end
graph_builder comes with the module GraphBuilder::Linkable which implements
# links self to other
link_to( other )
# returns an array of objects self is linked to
linked_to
# returns an array of pairs [ [ self, other1 ], [ self, other2 ], ... ]
# for linked objects other1, other2, ...
links
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request