gviz 0.3.3 → 0.3.4

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: 111365e7127ce64d1645957d112c7ea204dd6aed
4
- data.tar.gz: 5784cd73f99d927fa79378d020e176f742717546
3
+ metadata.gz: b24e07887d8c7f4d4337ec7de04cfdec4f1ea10d
4
+ data.tar.gz: 79ca3e661bc0e17025907bb475d08d854ec75dfa
5
5
  SHA512:
6
- metadata.gz: a239468f16cbbb6583724c8752da66b29227551b51727607ad69dfef87137e22f0ad0ce9c5f02dc53e66a66e2df7d03c606d2ea4841f1157cdafc1a03b1fe7d1
7
- data.tar.gz: 1daf776b599733172e81f856eec100039d0a2083a2f8731547cae76a21e2695489cc39f794b0a598affc9e9b02caf3fe8ed7cc5110edce30dddfefd3956279a7
6
+ metadata.gz: d489810c365bf0159f82a09832c49e03ee39e8df515264b029069044befb31033a7d5fb4b0c76b7a809718aac5b582fae97cb287e9726cec25e5383dd8fc69c8
7
+ data.tar.gz: 96f0516da3abf0f01bd6d6e789f08984255b37b42554287be871ecba4eba3261f186f65508b7baefebafe81140e204e18d8308af9fbe523cc2ab2befdb00ff08
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gviz
2
2
 
3
+ [![Build Status](https://travis-ci.org/melborne/Gviz.png?branch=master)](https://travis-ci.org/melborne/Gviz)
4
+
3
5
  Ruby's interface of graphviz. It generate a dot file with simple ruby's syntax. Some implementations of `Gviz` are inspired by Ryan Davis's [Graph](https://github.com/seattlerb/graph 'seattlerb/graph').
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -18,5 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.required_ruby_version = '>=2.0.0'
20
20
  gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency "bundler", "~> 1.5"
22
+ gem.add_development_dependency "rake"
21
23
  gem.add_dependency 'thor'
22
24
  end
@@ -11,6 +11,10 @@ def Graph(name=:G, type=:digraph, &blk)
11
11
  Gviz.new(name, type).graph(&blk)
12
12
  end
13
13
 
14
+ # This value will be changed to ':graph' only when Graph initiate with :graph type.
15
+ # then effect globally to edge connectors from '->' to '--'.
16
+ $graph_type = :digraph
17
+
14
18
  %w(core node edge version system_extension command).each do |lib|
15
19
  require 'gviz/' + lib
16
20
  end
@@ -1,7 +1,8 @@
1
1
  class Gviz
2
- attr_reader :gnode_attrs, :gedge_attrs, :graph_attrs, :subgraphs, :ranks
2
+ attr_reader :gnode_attrs, :gedge_attrs, :graph_attrs, :subgraphs, :ranks, :name
3
3
  def initialize(name=:G, type=:digraph)
4
4
  @name, @type = name, type
5
+ $graph_type = type.intern if type.intern==:graph
5
6
  @edges = {}
6
7
  @nodes = {}
7
8
  @gnode_attrs = {}
@@ -10,7 +11,7 @@ class Gviz
10
11
  @subgraphs = []
11
12
  @ranks = []
12
13
  end
13
-
14
+
14
15
  # Access to all defined node objects.
15
16
  def nodeset
16
17
  @nodes.values
@@ -108,8 +109,8 @@ class Gviz
108
109
  # add :a => :b
109
110
  # end
110
111
  #
111
- def subgraph(&blk)
112
- Gviz.new("cluster#{subgraphs.size}", :subgraph).tap do |graph|
112
+ def subgraph(name=:"cluster#{subgraphs.size}", &blk)
113
+ Gviz.new(name, :subgraph).tap do |graph|
113
114
  subgraphs << graph
114
115
  graph.instance_eval &blk
115
116
  end
@@ -9,7 +9,8 @@ class Gviz::Edge < Struct.new(:id, :attrs)
9
9
  def to_s
10
10
  stp = ":#{st_port}" if st_port
11
11
  edp = ":#{ed_port}" if ed_port
12
- "#{st}#{stp} -> #{ed}#{edp}"
12
+ edge = $graph_type==:graph ? "--" : "->"
13
+ "#{st}#{stp} #{edge} #{ed}#{edp}"
13
14
  end
14
15
 
15
16
  def nodes
@@ -1,3 +1,3 @@
1
1
  class Gviz
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -66,7 +66,7 @@ describe Gviz::Command do
66
66
  graph G {
67
67
  a;
68
68
  b;
69
- a -> b;
69
+ a -- b;
70
70
  }
71
71
  EOS
72
72
  end
@@ -84,4 +84,18 @@ describe Gviz::Edge do
84
84
  end
85
85
  end
86
86
  end
87
+
88
+ describe "#to_s" do
89
+ context "when type of graph is 'graph'" do
90
+ before do
91
+ $graph_type = :graph
92
+ end
93
+ it "returns undirected graph edges" do
94
+ expect(Gviz::Edge.new('a_b').to_s).to eq "a -- b"
95
+ end
96
+ after() do
97
+ $graph_type = :digraph
98
+ end
99
+ end
100
+ end
87
101
  end
@@ -195,7 +195,7 @@ describe Gviz do
195
195
  its(:size) { should eq 1 }
196
196
  end
197
197
 
198
- context "when add one" do
198
+ context "when add two" do
199
199
  before do
200
200
  gv.subgraph { add :main => [:a, :b] }
201
201
  gv.subgraph { add :main => [:a, :b] }
@@ -204,9 +204,31 @@ describe Gviz do
204
204
  its(:size) { should eq 2 }
205
205
  end
206
206
 
207
+ context "without name" do
208
+ before do
209
+ @sub1 = gv.subgraph { add :main => [:a, :b] }
210
+ @sub2 = gv.subgraph { add :main => [:a, :b] }
211
+ end
212
+ it "returns a default name" do
213
+ expect(@sub1.name).to eq :cluster0
214
+ expect(@sub2.name).to eq :cluster1
215
+ end
216
+ end
217
+
218
+ context "with a name" do
219
+ before do
220
+ @sub1 = gv.subgraph(:cluA) { add :main => [:a, :b] }
221
+ @sub2 = gv.subgraph(:cluB) { add :main => [:a, :b] }
222
+ end
223
+ it "returns passed name" do
224
+ expect(@sub1.name).to eq :cluA
225
+ expect(@sub2.name).to eq :cluB
226
+ end
227
+ end
228
+
207
229
  context "it has a name other than `cluster**`" do
208
- it "raise an error" do
209
- ->{ gv.subgraph(:clu) {} }.should raise_error
230
+ it "not raise an error" do
231
+ ->{ gv.subgraph(:clu) {} }.should_not raise_error
210
232
  end
211
233
  end
212
234
  end
@@ -507,6 +529,51 @@ describe Gviz do
507
529
  EOS
508
530
  end
509
531
  end
532
+
533
+ context "for undirected graph" do
534
+ before do
535
+ @gv = Gviz.new(:G, :graph)
536
+ @gv.add :main => [:init, :parse]
537
+ @gv.add :init => :printf
538
+ end
539
+ subject { @gv.to_s }
540
+ it do
541
+ should eq ~<<-EOS
542
+ graph G {
543
+ main;
544
+ init;
545
+ parse;
546
+ printf;
547
+ main -- init;
548
+ main -- parse;
549
+ init -- printf;
550
+ }
551
+ EOS
552
+ end
553
+
554
+ context "with subgraph" do
555
+ before do
556
+ @gv = Gviz.new(:G, :graph)
557
+ @gv.route(:a => :b)
558
+ @gv.subgraph { route :c => :d }
559
+ end
560
+ subject { @gv.to_s }
561
+ it do
562
+ should eql ~<<-EOS
563
+ graph G {
564
+ subgraph cluster0 {
565
+ c;
566
+ d;
567
+ c -- d;
568
+ }
569
+ a;
570
+ b;
571
+ a -- b;
572
+ }
573
+ EOS
574
+ end
575
+ end
576
+ end
510
577
  end
511
578
  end
512
579
 
@@ -10,4 +10,7 @@ end
10
10
 
11
11
  RSpec.configure do |c|
12
12
  c.include Helpers
13
+ c.before do
14
+ $graph_type = :digraph
15
+ end
13
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: thor
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -47,6 +75,7 @@ extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
77
  - ".gitignore"
78
+ - ".travis.yml"
50
79
  - Gemfile
51
80
  - LICENSE.txt
52
81
  - README.md