Class: Macrocosm
- Inherits:
-
Object
- Object
- Macrocosm
- Defined in:
- lib/macrocosm.rb,
lib/macrocosm/version.rb,
lib/macrocosm/template.rb
Defined Under Namespace
Constant Summary collapse
- NoCategory =
'no-category'
- VERSION =
"0.1.7"
Instance Attribute Summary collapse
-
#curveness ⇒ Object
readonly
Returns the value of attribute curveness.
Instance Method Summary collapse
- #add_link(source, target, relation_in_list: nil, relation_in_graph: nil, line_style: {}) ⇒ Object
- #add_node(name, category = nil) ⇒ Object
- #graph ⇒ Object
-
#initialize(curveness: 0) ⇒ Macrocosm
constructor
A new instance of Macrocosm.
- #to_s ⇒ Object
Constructor Details
#initialize(curveness: 0) ⇒ Macrocosm
Returns a new instance of Macrocosm.
54 55 56 57 58 59 60 61 |
# File 'lib/macrocosm.rb', line 54 def initialize(curveness: 0) category_index = -1 @categories = Hash.new{ |h, cate| h[cate] = (category_index += 1) } @nodes = [] @links = Links.new @curveness = curveness end |
Instance Attribute Details
#curveness ⇒ Object (readonly)
Returns the value of attribute curveness.
52 53 54 |
# File 'lib/macrocosm.rb', line 52 def curveness @curveness end |
Instance Method Details
#add_link(source, target, relation_in_list: nil, relation_in_graph: nil, line_style: {}) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/macrocosm.rb', line 72 def add_link(source, target, relation_in_list: nil, relation_in_graph: nil, line_style: {}) @links.add_link( source, target, relation_in_list: relation_in_list, relation_in_graph: relation_in_graph, line_style: line_style ) end |
#add_node(name, category = nil) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/macrocosm.rb', line 63 def add_node(name, category = nil) category = (category || NoCategory).to_s idx = @categories[category] @nodes << { name: name, category: idx } end |
#graph ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/macrocosm.rb', line 89 def graph JSON.pretty_generate({ nodes: @nodes, links: @links.links, categories: @categories.keys.sort!.map{ |name| {name: name} } }) end |