yargi 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTE ADDED
@@ -0,0 +1,11 @@
1
+ = Contribute
2
+
3
+ You are welcome to contribute to this graph implementation. Useful links are:
4
+
5
+ [http://rubyforge.org/projects/yargi/]
6
+ Rubyforge project, issue manager, forum, etc. Ideas and questions are welcome.
7
+ Don't hesitate to send me an e-mail if I don't answer quickly.
8
+ [http://github.com/blambeau/yargi/tree/master]
9
+ Sources are on github. Fork the thing there to submit contributions. Particularly
10
+ welcome: documentation reviewers, bug fixes (we love tests to prove bugs),
11
+ efficiency patches, useful graph algorithms, etc.
data/README CHANGED
@@ -5,7 +5,7 @@ Yargi is Yet Another (Ruby) Graph Implementation: we all have implemented a grap
5
5
  in almost every language that we use, probably many times. The reason is probably that each
6
6
  implementation has its own design decisions that makes the data-structure well-designed for
7
7
  the task at hand, or not. Below are the main design decisions made by Yargi; this way you can
8
- easily see if it fits your needs.
8
+ easily see if Yargi fits your needs.
9
9
 
10
10
  [Digraph, Vertex and Edge] Unlike {RGL}[http://rubyforge.org/projects/rgl/], Yargi implements
11
11
  graph components through concrete classes, not modules (that is, in
@@ -0,0 +1,50 @@
1
+ digraph G {
2
+ graph[rankdir="LR"]
3
+ V0 [fontsize="16" shape="folder" style="filled" fillcolor="cornsilk2" file="/Users/blambeau/work/chefbe/devel/yargi" width="1.6" label="yargi" height="0.4" fontname="Arial"]
4
+ V1 [fontsize="16" shape="box" fontcolor="white" style="filled, rounded" fillcolor="gray25" file="/Users/blambeau/work/chefbe/devel/yargi/CONTRIBUTE" width="1.6" label="CONTRIBUTE (0 kb)" height="0.4" fontname="Arial"]
5
+ V2 [fontsize="16" shape="folder" style="filled" fillcolor="white" file="/Users/blambeau/work/chefbe/devel/yargi/doc" width="1.6" label="doc" height="0.4" fontname="Arial"]
6
+ V3 [fontsize="16" shape="folder" fontcolor="black" style="filled" fillcolor="gold" file="/Users/blambeau/work/chefbe/devel/yargi/examples" width="1.6" label="examples" height="0.4" fontname="Arial"]
7
+ V4 [fontsize="16" shape="box" style="filled, rounded" file="/Users/blambeau/work/chefbe/devel/yargi/examples/fs2dot.dot" width="1.6" label="fs2dot.dot (5 kb)" height="0.4" fontname="Arial"]
8
+ V5 [fontsize="16" shape="box" style="filled, rounded" file="/Users/blambeau/work/chefbe/devel/yargi/examples/fs2dot.gif" width="1.6" label="fs2dot.gif (42 kb)" height="0.4" fontname="Arial"]
9
+ V6 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/examples/fs2dot.rb" width="1.6" label="fs2dot.rb (1 kb)" height="0.4" fontname="Arial"]
10
+ V7 [fontsize="16" shape="folder" fontcolor="black" style="filled" fillcolor="gold" file="/Users/blambeau/work/chefbe/devel/yargi/lib" width="1.6" label="lib" height="0.4" fontname="Arial"]
11
+ V8 [fontsize="16" shape="folder" fontcolor="black" style="filled" fillcolor="gold" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi" width="1.6" label="yargi" height="0.4" fontname="Arial"]
12
+ V9 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/digraph.rb" width="1.6" label="digraph.rb (9 kb)" height="0.4" fontname="Arial"]
13
+ V10 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/digraph_edge.rb" width="1.6" label="digraph_edge.rb (2 kb)" height="0.4" fontname="Arial"]
14
+ V11 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/digraph_vertex.rb" width="1.6" label="digraph_vertex.rb (2 kb)" height="0.4" fontname="Arial"]
15
+ V12 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/edge_set.rb" width="1.6" label="edge_set.rb (0 kb)" height="0.4" fontname="Arial"]
16
+ V13 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/element_set.rb" width="1.6" label="element_set.rb (4 kb)" height="0.4" fontname="Arial"]
17
+ V14 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/markable.rb" width="1.6" label="markable.rb (1 kb)" height="0.4" fontname="Arial"]
18
+ V15 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/predicate.rb" width="1.6" label="predicate.rb (4 kb)" height="0.4" fontname="Arial"]
19
+ V16 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi/vertex_set.rb" width="1.6" label="vertex_set.rb (1 kb)" height="0.4" fontname="Arial"]
20
+ V17 [fontsize="16" shape="parallelogram" fontcolor="white" style="filled, rounded" fillcolor="blue4" file="/Users/blambeau/work/chefbe/devel/yargi/lib/yargi.rb" width="1.6" label="yargi.rb (0 kb)" height="0.4" fontname="Arial"]
21
+ V18 [fontsize="16" shape="box" fontcolor="white" style="filled, rounded" fillcolor="gray25" file="/Users/blambeau/work/chefbe/devel/yargi/LICENCE" width="1.6" label="LICENCE (1 kb)" height="0.4" fontname="Arial"]
22
+ V19 [fontsize="16" shape="folder" style="filled" fillcolor="cornsilk2" file="/Users/blambeau/work/chefbe/devel/yargi/pkg" width="1.6" label="pkg" height="0.4" fontname="Arial"]
23
+ V20 [fontsize="16" shape="box3d" style="filled, rounded" fillcolor="gold" file="/Users/blambeau/work/chefbe/devel/yargi/pkg/yargi-0.1.0.gem" width="1.6" label="yargi-0.1.0.gem (91 kb)" height="0.4" fontname="Arial"]
24
+ V21 [fontsize="16" shape="box" style="filled, rounded" file="/Users/blambeau/work/chefbe/devel/yargi/Rakefile" width="1.6" label="Rakefile (1 kb)" height="0.4" fontname="Arial"]
25
+ V22 [fontsize="16" shape="box" fontcolor="white" style="filled, rounded" fillcolor="gray25" file="/Users/blambeau/work/chefbe/devel/yargi/README" width="1.6" label="README (5 kb)" height="0.4" fontname="Arial"]
26
+ V23 [fontsize="16" shape="folder" style="filled" fillcolor="white" file="/Users/blambeau/work/chefbe/devel/yargi/test" width="1.6" label="test" height="0.4" fontname="Arial"]
27
+ V3 -> V4 []
28
+ V3 -> V5 []
29
+ V3 -> V6 []
30
+ V8 -> V9 []
31
+ V8 -> V10 []
32
+ V8 -> V11 []
33
+ V8 -> V12 []
34
+ V8 -> V13 []
35
+ V8 -> V14 []
36
+ V8 -> V15 []
37
+ V8 -> V16 []
38
+ V7 -> V8 []
39
+ V7 -> V17 []
40
+ V19 -> V20 []
41
+ V0 -> V1 []
42
+ V0 -> V2 []
43
+ V0 -> V3 []
44
+ V0 -> V7 []
45
+ V0 -> V18 []
46
+ V0 -> V19 []
47
+ V0 -> V21 []
48
+ V0 -> V22 []
49
+ V0 -> V23 []
50
+ }
Binary file
@@ -0,0 +1,57 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'yargi'
3
+
4
+ module DirVertex; end
5
+ module FileVertex; end
6
+
7
+ # Recursively create vertices and edges in the graph
8
+ def build_graph(dir, graph, parent)
9
+ return if /test|doc$/ =~ dir
10
+ subnodes = Dir["#{dir}/*"].collect do |f|
11
+ is_dir = File.directory?(f)
12
+ vertex = graph.add_vertex(is_dir ? DirVertex : FileVertex, {:file => f})
13
+ build_graph(f, graph, vertex) if is_dir
14
+ vertex
15
+ end
16
+ graph.connect(parent, subnodes)
17
+ end
18
+
19
+ # Starts the creation
20
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
21
+ graph = Yargi::Digraph.new
22
+ root = graph.add_vertex(DirVertex, {:file => dir})
23
+ build_graph(dir, graph, root)
24
+
25
+ # Add dot attributes
26
+ graph.add_marks(:rankdir => 'LR')
27
+ graph.vertices.add_marks(
28
+ :shape => :box, :width => 1.6, :height => 0.4,
29
+ :fontname => 'Arial', :fontsize => '16'
30
+ )
31
+
32
+ graph.vertices(DirVertex).add_marks(:shape => 'folder', :style => "filled", :fillcolor => 'cornsilk2') do |v|
33
+ {:label => "#{File.basename(v.file)}"}
34
+ end
35
+ graph.vertices(DirVertex){|v| v.out_edges.empty?}.add_marks(:fillcolor => 'white')
36
+
37
+ graph.vertices(FileVertex).add_marks(:style => "filled, rounded") do |v|
38
+ weight = File.size(v.file)/1024
39
+ {:label => "#{File.basename(v.file)} (#{weight} kb)"}
40
+ end
41
+ graph.vertices(FileVertex){|v| /\.gem$/ =~ v.file}.add_marks(
42
+ :shape => 'box3d', :fillcolor => 'gold'
43
+ )
44
+ graph.vertices(FileVertex){|v| /^[A-Z]+ (.*)$/ =~ v.label}.add_marks(
45
+ :fillcolor => 'gray25', :fontcolor => 'white'
46
+ )
47
+ graph.vertices(FileVertex){|v| /\.rb (.*)$/ =~ v.label}.add_marks(
48
+ :shape => 'parallelogram', :fillcolor => 'blue4', :fontcolor => 'white'
49
+ )
50
+ graph.vertices(FileVertex){|v| /\.rb (.*)$/ =~ v.label}.in_adjacent.add_marks do |v|
51
+ {:fillcolor => 'gold', :fontcolor => 'black'}
52
+ end
53
+
54
+ # Save it
55
+ File.open(File.join(File.dirname(__FILE__), 'fs2dot.dot'), 'w') do |f|
56
+ f << graph.to_dot
57
+ end
data/lib/yargi.rb CHANGED
@@ -3,7 +3,7 @@ require 'yargi/predicate'
3
3
  module Yargi
4
4
 
5
5
  # Current Yargi version
6
- VERSION = "0.1.0".freeze
6
+ VERSION = "0.1.1".freeze
7
7
 
8
8
  # When _what_ is not nil, converts it to a predicate (typically a module).
9
9
  # Otherwise, a block is expected, which is converted to a LambdaPredicate.
data/lib/yargi/digraph.rb CHANGED
@@ -201,6 +201,7 @@ module Yargi
201
201
  # TODO: some values must be encoded (backquoting and the like)
202
202
  buffer = ""
203
203
  hash.each_pair do |k,v|
204
+ buffer << " " unless buffer.empty?
204
205
  buffer << "#{k}=\"#{v}\""
205
206
  end
206
207
  buffer
@@ -1,10 +1,10 @@
1
1
  digraph G {
2
2
  graph[]
3
- V0 [shape="circle"label=""]
4
- V1 [shape="circle"label=""]
5
- V2 [shape="circle"label=""]
6
- V3 [shape="circle"label=""]
7
- V4 [shape="circle"label=""]
3
+ V0 [shape="circle" label=""]
4
+ V1 [shape="circle" label=""]
5
+ V2 [shape="circle" label=""]
6
+ V3 [shape="circle" label=""]
7
+ V4 [shape="circle" label=""]
8
8
  V0 -> V0 [label="From 0 to 0"]
9
9
  V0 -> V1 [label="From 0 to 1"]
10
10
  V0 -> V2 [label="From 0 to 2"]
@@ -1,15 +1,15 @@
1
1
  digraph G {
2
2
  graph[]
3
- V0 [label=""shape="diamond"fixedsize="true"width="0.5"]
4
- V1 [label=""shape="diamond"fixedsize="true"width="0.5"]
5
- V2 [label=""shape="diamond"fixedsize="true"width="0.5"]
6
- V3 [label=""shape="diamond"fixedsize="true"width="0.5"]
7
- V4 [label=""shape="diamond"fixedsize="true"width="0.5"]
8
- V5 [label=""shape="doublecircle"fixedsize="true"width="0.5"]
9
- V6 [label=""shape="doublecircle"fixedsize="true"width="0.5"]
10
- V7 [label=""shape="doublecircle"fixedsize="true"width="0.5"]
11
- V8 [label=""shape="doublecircle"fixedsize="true"width="0.5"]
12
- V9 [label=""shape="doublecircle"fixedsize="true"width="0.5"]
3
+ V0 [label="" shape="diamond" fixedsize="true" width="0.5"]
4
+ V1 [label="" shape="diamond" fixedsize="true" width="0.5"]
5
+ V2 [label="" shape="diamond" fixedsize="true" width="0.5"]
6
+ V3 [label="" shape="diamond" fixedsize="true" width="0.5"]
7
+ V4 [label="" shape="diamond" fixedsize="true" width="0.5"]
8
+ V5 [label="" shape="doublecircle" fixedsize="true" width="0.5"]
9
+ V6 [label="" shape="doublecircle" fixedsize="true" width="0.5"]
10
+ V7 [label="" shape="doublecircle" fixedsize="true" width="0.5"]
11
+ V8 [label="" shape="doublecircle" fixedsize="true" width="0.5"]
12
+ V9 [label="" shape="doublecircle" fixedsize="true" width="0.5"]
13
13
  V0 -> V5 [label="from 0 to 5"]
14
14
  V0 -> V6 [label="from 0 to 6"]
15
15
  V0 -> V7 [label="from 0 to 7"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yargi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -22,6 +22,7 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  - LICENCE
25
+ - CONTRIBUTE
25
26
  files:
26
27
  - lib/yargi
27
28
  - lib/yargi/digraph.rb
@@ -49,8 +50,12 @@ files:
49
50
  - test/yargi/source-sink.gif
50
51
  - test/yargi/star.dot
51
52
  - test/yargi/vertex_set_test.rb
53
+ - examples/fs2dot.dot
54
+ - examples/fs2dot.gif
55
+ - examples/fs2dot.rb
52
56
  - README
53
57
  - LICENCE
58
+ - CONTRIBUTE
54
59
  has_rdoc: true
55
60
  homepage: https://code.chefbe.net/
56
61
  post_install_message: