Low commit activity in last 3 years
No release in over a year
Hierarchical graph representation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 5.0, < 5.11
~> 0.2
~> 12.3
~> 0.12
 Project Readme

HierarchicalGraph

Gem Version Build Status Coverage Status Code Climate

Hierarchical graph representation

Installation

Add this line to your application's Gemfile:

gem 'hierarchical_graph'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hierarchical_graph

Usage

Build graph

graph = HierarchicalGraph.new

graph.add_node 1, name: 'Node 1', other: 1000
graph.add_node 2
graph.add_node 3

graph.add_relation parent_id: 1, child_id: 2
graph.add_relation parent_id: 2, child_id: 3

Navigate graph

graph[1] # <Node 1>
graph.roots # [<Node 1>, <Node 2>]
graph.parents_of(3) # [<Node 2>]
graph.ancestors_of(3) # [<Node 1>, <Node 2>]
graph.children_of(1) # [<Node 2>]
graph.descendants_of(1) # [<Node 2>, <Node 3>]

Node

node = graph[node_id]

node.id # node_id
node.root? # true/false

node.data # {key_1: val_1, key_2: val_2}
node.data[:key_1] # val_1
node.data[:key_3] = val_3
node[:key_1] # val_1
node[:key_3] = val_3

node.parents # [<Node>, ...]
node.ancestors # [<Node>, ...]
node.children # [<Node>, ...]
node.descendants # [<Node>, ...]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/hierarchical_graph.

License

The gem is available as open source under the terms of the MIT License.