mikado_graph_generator 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d40123be1c0da8c638c131cbf9950308e0d5e65
4
- data.tar.gz: 2868134bffaa3ac330a39fc874276a5498236d38
3
+ metadata.gz: 50d127099e97a095948b836a9cd6d547caf4961f
4
+ data.tar.gz: 7a9dc695f1e142367483d130b0388d0dd6959337
5
5
  SHA512:
6
- metadata.gz: af89d6afa1fc13b87c5fdc2dbc105467c905d8941a8668011482f4e9b0b65a4a8c9fc0430a2cece900662ea178cc6c7097165ccf577ffb2c115b208c8896cf5a
7
- data.tar.gz: d8c6e2b6a8840bd531bab60bb806642b070082a7bc0af910e52180770cc7f6146bf358f8926c9bfd8c7e22ed3181765ff6463856cb12d3c75ed0cbd1a6445624
6
+ metadata.gz: fb466184253fd7dd6882c9939e5e18a34553604a1952ddd3195cc1956ee4abfc872258346d154dc511e2c2447e6948bfa3bfc764fc15f34ea5c90c33c0d51495
7
+ data.tar.gz: daf8ef624d17918aafaf78aa9aa498da21d0c33992396296f513dcf4360d5e41f6d33e6978f47a1aaf57135ebe1fb5d1a6cbdaa75bafe27d028c3a0b8c8f898e
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
3
  - 2.3.1
5
- before_install: gem install bundler -v 1.14.3
4
+ before_install:
5
+ - gem install bundler -v 1.14.3
6
+ - sudo apt-get -qq update
7
+ - sudo apt-get install -y graphviz
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mikado_graph_generator (0.1.0)
4
+ mikado_graph_generator (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -21,6 +21,7 @@ GEM
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
22
  rspec-support (~> 3.5.0)
23
23
  rspec-support (3.5.0)
24
+ ruby-graphviz (1.2.2)
24
25
 
25
26
  PLATFORMS
26
27
  ruby
@@ -30,6 +31,7 @@ DEPENDENCIES
30
31
  mikado_graph_generator!
31
32
  rake (~> 10.0)
32
33
  rspec (~> 3.0)
34
+ ruby-graphviz
33
35
 
34
36
  BUNDLED WITH
35
37
  1.14.3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Mikado Graph Generator
1
+ # Mikado Graph Generator [![Build Status](https://travis-ci.org/snasirca/mikado_graph_generator.svg?branch=master)](https://travis-ci.org/snasirca/mikado_graph_generator) [![Code Climate](https://codeclimate.com/github/snasirca/mikado_graph_generator/badges/gpa.svg)](https://codeclimate.com/github/snasirca/mikado_graph_generator)
2
2
 
3
3
  Welcome to a DSL for creating Mikado Graphs using *GraphViz*.
4
4
 
@@ -33,30 +33,32 @@ You can use this gem's DSL in the following way to create a Mikado Graph generat
33
33
  ```ruby
34
34
  require "mikado_graph"
35
35
 
36
- MikadoGraph::Generator.generate do
37
- state("State A").depends_on do
38
- state("State B").depends_on do
36
+ MikadoGraph::Generator.define do
37
+ state("State A").depends_on {
38
+ state("State B").depends_on {
39
39
  state("State D")
40
40
  state("State E")
41
- end
42
- state("State C").depends_on do
41
+ }
42
+ state("State C").depends_on {
43
43
  state("State F")
44
44
  state("State G")
45
- end
46
- end
47
- end
45
+ }
46
+ }
47
+ end.generate("png", "img/example_usage.png") # generate takes GraphViz format and output path
48
48
  ```
49
49
 
50
- You can then execute this file in the terminal using:
50
+ Save this file to `example_usage.rb` and then you can then execute this file in the terminal using:
51
51
 
52
52
  ```bash
53
- ruby multi_level_mikado_graph_generator.rb | dot -Tpng -o img/multi_level_mikado_graph.png
53
+ ruby example_usage.rb
54
54
  ```
55
55
 
56
56
  This will utilize the *GraphViz* `dot` command to create this PNG output of the above Mikado Graph generator definition:
57
57
 
58
58
  ![Multi-Level Mikado Graph](https://github.com/snasirca/mikado_graph_generator/blob/master/img/multi_level_mikado_graph.png)
59
59
 
60
+ NOTE: If you don't provide any parameters to `generate`, it'll default to a `dot` output in the STDOUT.
61
+
60
62
  ## Development
61
63
 
62
64
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/example_usage.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "mikado_graph"
2
+
3
+ MikadoGraph::Generator.define do
4
+ state("State A").depends_on {
5
+ state("State B").depends_on {
6
+ state("State D")
7
+ state("State E")
8
+ }
9
+ state("State C").depends_on {
10
+ state("State F")
11
+ state("State G")
12
+ }
13
+ }
14
+ end.generate("png", "img/example_usage.png")
@@ -1,44 +1,50 @@
1
+ require "graphviz"
2
+
1
3
  module MikadoGraph
2
- module Generator
3
- extend self
4
+ class Generator
5
+ attr_reader :dependencies, :graph
6
+
7
+ def self.define(&block)
8
+ generator_instance = new
9
+ generator_instance.dependencies.instance_eval(&block)
10
+ generator_instance
11
+ end
4
12
 
5
- def generate(&block)
6
- dependencies = Dependencies.new
7
- dependencies.instance_eval(&block)
8
- convert(dependencies.dependent_states)
13
+ def generate(format = "dot", path = nil)
14
+ add_states_to_graph(dependencies.dependent_states)
15
+ output_options = {}
16
+ output_options[format] = path
17
+ graph.output(output_options)
9
18
  end
10
19
 
11
20
  private
12
21
 
13
- def convert(states)
14
- convert_header
15
- convert_states_and_dependencies(states)
16
- convert_footer
22
+ def initialize
23
+ @dependencies = Dependencies.new
24
+ initialize_graph
17
25
  end
18
26
 
19
- def convert_header
20
- puts "digraph {"
21
- puts " node [shape=box];"
22
- puts " rankdir=\"LR\";"
27
+ def initialize_graph
28
+ @graph = GraphViz.new(nil)
29
+ @graph[:rankdir] = "LR"
30
+ @graph.node[:shape] = "box"
23
31
  end
24
32
 
25
- def convert_states_and_dependencies(states)
26
- states.each { |state| convert_dependencies(state) }
33
+ def add_states_to_graph(states)
34
+ states.each { |state| add_state_dependencies(state) }
27
35
  end
28
36
 
29
- def convert_dependencies(state)
37
+ def add_state_dependencies(state)
30
38
  state.dependent_states.each do |dependent_state|
31
- convert_dependency(state, dependent_state)
32
- convert_dependencies(dependent_state)
39
+ add_dependency(state, dependent_state)
40
+ add_state_dependencies(dependent_state)
33
41
  end
34
42
  end
35
43
 
36
- def convert_dependency(state, dependent_state)
37
- puts " \"#{dependent_state.name}\" -> \"#{state.name}\";"
38
- end
39
-
40
- def convert_footer
41
- puts "}"
44
+ def add_dependency(state, dependent_state)
45
+ state_node = graph.add_nodes(state.name)
46
+ dependent_state_node = graph.add_nodes(dependent_state.name)
47
+ graph.add_edges(dependent_state_node, state_node)
42
48
  end
43
49
  end
44
50
  end
@@ -1,3 +1,3 @@
1
1
  module MikadoGraph
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/mikado_graph.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.14"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "ruby-graphviz"
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikado_graph_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shahriyar Nasir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-graphviz
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Provides a simple DSL for generating Mikado Graphs using GraphViz.
56
70
  email:
57
71
  - contact@snasir.ca
@@ -70,7 +84,7 @@ files:
70
84
  - Rakefile
71
85
  - bin/console
72
86
  - bin/setup
73
- - img/multi_level_mikado_graph.png
87
+ - example_usage.rb
74
88
  - lib/mikado_graph.rb
75
89
  - lib/mikado_graph/dependencies.rb
76
90
  - lib/mikado_graph/generator.rb
Binary file