curricula 0.0.3 → 0.0.4
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 +4 -4
- data/lib/curricula/version.rb +1 -1
- data/lib/curricula.rb +14 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26cc57f5199a90d580f3541b80502c703d5b09ff
|
4
|
+
data.tar.gz: c994ad2722c81170f87a8392cd9db55d63a7b0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922778ca9071d1f81bd7b5915b587d82e5fbdffe20ea67f3662e9096f9c0b5ba6859b96834460f859ce39248eaf2291ea0a6608f4733ee08d833bc7b87f83965
|
7
|
+
data.tar.gz: f7c5a85865c4efbcf70347eff6f7610cb9c6c21357fe13bcfd79b3eec978bb96b2bfdb3f28af7c6c4df001bc7ebd645ee01415c0469dd6d0498c0b171d1c2fd2
|
data/lib/curricula/version.rb
CHANGED
data/lib/curricula.rb
CHANGED
@@ -6,12 +6,13 @@ module Curricula
|
|
6
6
|
class Course
|
7
7
|
|
8
8
|
attr_reader :name, :hours
|
9
|
-
attr_accessor :prereqs
|
9
|
+
attr_accessor :prereqs, :cruciality
|
10
10
|
|
11
11
|
def initialize name, hours
|
12
12
|
@name = name
|
13
13
|
@hours = hours
|
14
14
|
@prereqs = []
|
15
|
+
@cruciality = 0
|
15
16
|
end
|
16
17
|
|
17
18
|
def graph_edges
|
@@ -51,6 +52,10 @@ module Curricula
|
|
51
52
|
@courses.each_value.map(&:graph_edges).flatten(1).reject &:empty?
|
52
53
|
end
|
53
54
|
|
55
|
+
def cruciality
|
56
|
+
@courses.each_value.map { |course| [course.name,course.cruciality] }
|
57
|
+
end
|
58
|
+
|
54
59
|
private
|
55
60
|
|
56
61
|
def process
|
@@ -64,6 +69,7 @@ module Curricula
|
|
64
69
|
Spreadsheet.open(@spreadsheet).worksheets.first.each do |row|
|
65
70
|
if row[1]
|
66
71
|
@courses[row.last].prereqs << @courses[row.first]
|
72
|
+
increase_cruciality @courses[row.first], @courses[row.last]
|
67
73
|
else
|
68
74
|
@courses[row.first] = Course.new row.first, row.last
|
69
75
|
end
|
@@ -71,11 +77,16 @@ module Curricula
|
|
71
77
|
end
|
72
78
|
|
73
79
|
def course_hours course, visited = []
|
74
|
-
|
80
|
+
error :circular if visited.include? course
|
75
81
|
visited << course
|
76
82
|
course.hours + course.prereqs.map{ |prereq| course_hours(prereq, visited).to_i }.reduce(:+).to_i
|
77
83
|
end
|
78
|
-
|
84
|
+
|
85
|
+
def increase_cruciality course, prerequisite
|
86
|
+
prerequisite.cruciality += course.hours
|
87
|
+
prerequisite.prereqs.each { |prereq| increase_cruciality @courses[course], prereq }
|
88
|
+
end
|
89
|
+
|
79
90
|
def error name
|
80
91
|
case name
|
81
92
|
when :format
|