acts-as-dag 1.1.2 → 1.1.3

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.1.3
@@ -515,7 +515,7 @@ module Dag
515
515
  def longest_path_between(ancestor, descendant, path=[])
516
516
  longest = []
517
517
  ancestor.children.each do |child|
518
- if child == descendent
518
+ if child == descendant
519
519
  temp = path.clone
520
520
  temp << child
521
521
  if temp.length > longest.length
@@ -533,6 +533,28 @@ module Dag
533
533
  return longest
534
534
  end
535
535
 
536
+ #Finds the shortest path between ancestor and descendant returning as an array
537
+ def shortest_path_between(ancestor, descendant, path=[])
538
+ shortest = []
539
+ ancestor.children.each do |child|
540
+ if child == descendant
541
+ temp = path.clone
542
+ temp << child
543
+ if shortest.blank? || temp.length < shortest.length
544
+ shortest = temp
545
+ end
546
+ elsif self.connected?(child, descendant)
547
+ temp = path.clone
548
+ temp << child
549
+ temp = self.shortest_path_between(child, descendant, temp)
550
+ if shortest.blank? || temp.length < shortest.length
551
+ shortest = temp
552
+ end
553
+ end
554
+ end
555
+ return shortest
556
+ end
557
+
536
558
  #Determines if an edge exists between two points
537
559
  def edge?(ancestor, descendant)
538
560
  return !self.find_edge(ancestor, descendant).nil?
@@ -811,4 +811,32 @@ class DagTest < Test::Unit::TestCase
811
811
  b.reload
812
812
  assert !b.root_for_beta_nodes?
813
813
  end
814
+ #Tests that longest_path_between works
815
+ def test_longest_path_between
816
+ a = Node.create!
817
+ b = Node.create!
818
+ c = Node.create!
819
+ d = Node.create!
820
+ e = Default.create_edge(a,b)
821
+ e = Default.create_edge(b,c)
822
+ e = Default.create_edge(a,c)
823
+ e = Default.create_edge(c,d)
824
+ path = Default.longest_path_between(a,d)
825
+ assert_equal [b,c,d], path
826
+ end
827
+
828
+ #Tests that shortest_path_between works
829
+ def test_shortest_path_between
830
+ a = Node.create!
831
+ b = Node.create!
832
+ c = Node.create!
833
+ d = Node.create!
834
+ e = Default.create_edge(a,b)
835
+ e = Default.create_edge(b,c)
836
+ e = Default.create_edge(a,c)
837
+ e = Default.create_edge(c,d)
838
+ path = Default.shortest_path_between(a,d)
839
+ assert_equal [c,d], path
840
+ end
841
+
814
842
  end
Binary file
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-dag
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 1
9
- - 2
10
- version: 1.1.2
8
+ - 3
9
+ version: 1.1.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Matthew Leventi
@@ -16,7 +15,7 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-10-13 00:00:00 -07:00
18
+ date: 2011-02-04 00:00:00 -08:00
20
19
  default_executable:
21
20
  dependencies: []
22
21
 
@@ -42,8 +41,8 @@ homepage: http://github.com/resgraph/acts-as-dag
42
41
  licenses: []
43
42
 
44
43
  post_install_message:
45
- rdoc_options:
46
- - --charset=UTF-8
44
+ rdoc_options: []
45
+
47
46
  require_paths:
48
47
  - lib
49
48
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -51,7 +50,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
- hash: 3
55
53
  segments:
56
54
  - 0
57
55
  version: "0"
@@ -60,7 +58,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  requirements:
61
59
  - - ">="
62
60
  - !ruby/object:Gem::Version
63
- hash: 3
64
61
  segments:
65
62
  - 0
66
63
  version: "0"