directed_graph 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fc02a4eccc4014ced95f5e9733f9562bf5760f2
4
- data.tar.gz: 4263efeaa3fe670468c03a5f8600b890b7cae100
3
+ metadata.gz: 0adbde84d2c5293373788a5ce73f444fa41d3129
4
+ data.tar.gz: 691938d500c03589376637969b320ade01699fee
5
5
  SHA512:
6
- metadata.gz: 9637fa8cab2d210e408a27af1d9d2c7d28c3c7436dc2d3a6ab696d9f0efece71a4b4ef9b869214728556d8d0c8f3fe072f58e25fd83a30b22c15ecd520fabb87
7
- data.tar.gz: 6b7791dfac072c0a2f3c305347f225cb89f52f9b4b65afda24af5c16c5e20c6919afc8aac084835a04b8f646542902004edb2140d1c9338bec2b5fc44bcd191a
6
+ metadata.gz: 843edf49bae2d53557d2c749b1caaae3a523502f505d4306905dc43285b8f8a10047a39424617bb9edf9d97fe1e58456f9ebf1a11f6efa03ee62cebf9a68963f
7
+ data.tar.gz: df3e337f5f782951bab9974b6ade178ce10692fab50c2a0641a6efa1a38ee7a2f5f5859d116e88793a6c993a9ba9891a72cc78a709b6b3b48d1c9bcdf59dad65
data/README.md CHANGED
@@ -11,12 +11,12 @@ The `Graph` class should be instantiated with an array of edges:
11
11
  ```ruby
12
12
  # The first argument is the origin_vertex
13
13
  # and the second is the destination_vertex
14
- @ra = Edge.new("root", "a")
15
- @ab = Edge.new("a", "b")
16
- @bc = Edge.new("b", "c")
17
- @bd = Edge.new("b", "d")
18
- @ae = Edge.new("a", "e")
19
- @de = Edge.new("d", "e")
14
+ @ra = Edge.new(origin_vertex: "root", destination_vertex: "a")
15
+ @ab = Edge.new(origin_vertex: "a", destination_vertex: "b")
16
+ @bc = Edge.new(origin_vertex: "b", destination_vertex: "c")
17
+ @bd = Edge.new(origin_vertex: "b", destination_vertex: "d")
18
+ @ae = Edge.new(origin_vertex: "a", destination_vertex: "e")
19
+ @de = Edge.new(origin_vertex: "d", destination_vertex: "e")
20
20
  @edges = [@ra, @ab, @bc, @bd, @ae, @de]
21
21
  @graph = Graph.new(@edges)
22
22
  ```
@@ -4,10 +4,10 @@ module DirectedGraph
4
4
 
5
5
  attr_reader :origin_vertex, :destination_vertex, :value
6
6
 
7
- def initialize(origin_vertex, destination_vertex, value = nil)
8
- @origin_vertex = origin_vertex
9
- @destination_vertex = destination_vertex
10
- @value = value
7
+ def initialize(args)
8
+ @origin_vertex = args.fetch(:origin_vertex)
9
+ @destination_vertex = args.fetch(:destination_vertex)
10
+ @value = args.fetch(:value, nil)
11
11
  end
12
12
 
13
13
  end
@@ -8,12 +8,6 @@ module DirectedGraph
8
8
  @edges = edges
9
9
  end
10
10
 
11
- def vertices_longest_path_to_root(root_vertex)
12
- vertices.map do |v|
13
- [v, longest_path(root_vertex, v)]
14
- end
15
- end
16
-
17
11
  def vertices
18
12
  r = []
19
13
  edges.each {|e| r.push(e.origin_vertex, e.destination_vertex)}
@@ -43,8 +37,6 @@ module DirectedGraph
43
37
  end.inject([]) {|m, arr| m = arr if arr.length > m.length; m}
44
38
  end
45
39
 
46
- private
47
-
48
40
  def children(vertex)
49
41
  edges.select {|e| e.origin_vertex == vertex}.map{|e| e.destination_vertex}
50
42
  end
@@ -53,6 +45,8 @@ module DirectedGraph
53
45
  edges.select {|e| e.destination_vertex == vertex}.map{|e| e.origin_vertex}
54
46
  end
55
47
 
48
+ private
49
+
56
50
  def vertices_and_children
57
51
  vertices.map {|v| [v, children(v)]}
58
52
  end
@@ -1,3 +1,3 @@
1
1
  module DirectedGraph
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directed_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MrPowers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler