gpa 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gpa.gemspec +0 -2
- data/lib/gpa.rb +48 -38
- data/lib/gpa/course.rb +234 -200
- data/lib/gpa/version.rb +1 -1
- data/spec/course_spec.rb +15 -15
- data/spec/gpa_spec.rb +13 -10
- data/spec/support/courses.yml +88 -104
- data/spec/support/spec_helper.rb +63 -63
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6653a21e5b18b9b4c5e130c9d918852f5ccb3278
|
4
|
+
data.tar.gz: 9550f6daeafd69232d497632bbb6c43552587d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ff09cdb950afa1bf9f6803289fd42cc9ea4662ddf8b1d7bc9ba5655259e95e68b87a89820030422508207facae0cd9f85d265e38f5e2e5d75def8dd6f37852
|
7
|
+
data.tar.gz: dc5ed77378c3e05d0f02c54204e3a4ce239ebe0a9572a580b61cf07e938bc23174a9d5b5cd12ae3ab03f2317a88d38ad38946811b7b5881eb755459c49c4cc43
|
data/gpa.gemspec
CHANGED
@@ -8,8 +8,6 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.summary = %q{Academic course data manipulation and GPA calculation module}
|
9
9
|
gem.homepage = "https://github.com/dmorrill10/GPA"
|
10
10
|
|
11
|
-
gem.add_dependency 'dmorrill10-utils', '~> 2.0.0'
|
12
|
-
|
13
11
|
gem.add_development_dependency 'simplecov', '~> 0.8.2'
|
14
12
|
gem.add_development_dependency 'minitest', '~> 5.2.0'
|
15
13
|
|
data/lib/gpa.rb
CHANGED
@@ -1,49 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'dmorrill10-utils/enumerable'
|
1
|
+
require_relative "gpa/version"
|
2
|
+
require_relative "gpa/course"
|
5
3
|
require 'yaml'
|
6
|
-
|
7
|
-
|
8
|
-
class Array
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
!course.respond_to?(:grade_points) || course.grade_points.nil?
|
14
|
-
end.sort_courses_by_date_completed.inject([]) do |accum_array, course|
|
15
|
-
accum_array << course
|
16
|
-
break accum_array if accum_array.units_completed >= num_most_recent_units
|
17
|
-
accum_array
|
4
|
+
|
5
|
+
module Gpa
|
6
|
+
class CourseArray < Array
|
7
|
+
def self.load_courses_from_file(yaml_file_path)
|
8
|
+
load_yaml_from_file(yaml_file_path).inject(new) do |new_instance, yaml_course|
|
9
|
+
new_instance << Course.from_hash(yaml_course)
|
10
|
+
end
|
18
11
|
end
|
19
12
|
|
20
|
-
|
21
|
-
|
13
|
+
# @param [Integer] num_most_recent_units
|
14
|
+
# @returns [Numeric] The GPA calculated with +num_most_recent_units+ most recent units completed.
|
15
|
+
def gpa(num_most_recent_units = units_completed)
|
16
|
+
courses = sort_courses_by_date_completed.inject(CourseArray.new) do |accum_array, course|
|
17
|
+
next accum_array unless course.grade_has_points?
|
18
|
+
accum_array << course
|
19
|
+
break accum_array if accum_array.units_completed >= num_most_recent_units
|
20
|
+
accum_array
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
23
|
+
courses.inject(0) do |sum, course|
|
24
|
+
sum += course.grade_points / courses.units_completed.to_f
|
25
|
+
end
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def units_completed
|
29
|
+
completed_courses.inject(0) do |sum, course|
|
30
|
+
sum += course.units
|
31
|
+
end
|
32
32
|
end
|
33
|
-
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
def sort_courses_by_date_completed
|
35
|
+
self.class().new(
|
36
|
+
completed_courses.sort do |c1, c2|
|
37
|
+
c2.date_completed <=> c1.date_completed
|
38
|
+
end
|
39
|
+
)
|
41
40
|
end
|
42
|
-
end
|
43
|
-
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
def completed_courses
|
43
|
+
current_date = DateTime.now
|
44
|
+
select do |course|
|
45
|
+
course.respond_to?(:date_completed) &&
|
46
|
+
course.date_completed < current_date &&
|
47
|
+
!course.grade.nil?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Load the document contained in +filename+. Returns the yaml contained in
|
54
|
+
# +filename+ as a ruby object
|
55
|
+
def self.load_yaml_from_file(filename)
|
56
|
+
File.open(filename, 'r:bom|utf-8') { |f| YAML.load_stream f, filename }
|
57
|
+
end
|
48
58
|
end
|
49
59
|
end
|
data/lib/gpa/course.rb
CHANGED
@@ -1,209 +1,243 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Gpa
|
2
|
+
class Grade < String
|
3
|
+
# @return [Hash<String, Numeric>] University of Alberta grade to grade points hash.
|
4
|
+
UNIVERSITY_OF_ALBERTA_GRADE_TO_POINTS = {
|
5
|
+
'A+' => 4.0,
|
6
|
+
'A' => 4.0,
|
7
|
+
'A-' => 3.7,
|
8
|
+
'B+' => 3.3,
|
9
|
+
'B' => 3.0,
|
10
|
+
'B-' => 2.7,
|
11
|
+
'C+' => 2.3,
|
12
|
+
'C' => 2.0,
|
13
|
+
'C-' => 1.7,
|
14
|
+
'D+' => 1.3,
|
15
|
+
'D' => 1.0,
|
16
|
+
'F' => 0.0
|
17
|
+
}
|
18
|
+
|
19
|
+
# @returns [Numeric] Number of grade points for this grade
|
20
|
+
def points
|
21
|
+
points_ = UNIVERSITY_OF_ALBERTA_GRADE_TO_POINTS[self]
|
22
|
+
unless points_
|
23
|
+
raise StandarError.new("Grade of \"#{self}\" has no point value!")
|
24
|
+
end
|
25
|
+
points_
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_points?
|
29
|
+
!UNIVERSITY_OF_ALBERTA_GRADE_TO_POINTS[self].nil?
|
30
|
+
end
|
5
31
|
end
|
6
|
-
end
|
7
32
|
|
8
|
-
class Course
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
class Course
|
34
|
+
# @todo Incomplete list of subjects. Not a big deal though because faculty can be specified on a per course basis.
|
35
|
+
# @return [Hash<String, Array<String>>] University of Alberta subject hierarchy.
|
36
|
+
UNIVERSITY_OF_ALBERTA_SUBJECT_HIERARCHY = {
|
37
|
+
'ALES' => [
|
38
|
+
# Agricultural and Resource Economics
|
39
|
+
'AREC',
|
40
|
+
# Agricultural, Food and Nutritional Science
|
41
|
+
'AFNS',
|
42
|
+
# Agricultural, Life and Environmental Sciences
|
43
|
+
'ALES',
|
44
|
+
# Animal Science
|
45
|
+
'AN SC',
|
46
|
+
# Environmental and Conservation Sciences
|
47
|
+
'ENCS',
|
48
|
+
# Forest Economics
|
49
|
+
'FOREC',
|
50
|
+
# Forest Engineering
|
51
|
+
'FOREN',
|
52
|
+
# Forest Science
|
53
|
+
'FOR',
|
54
|
+
# Human Ecology
|
55
|
+
'HECOL',
|
56
|
+
# Interdisciplinary Courses
|
57
|
+
'INT D',
|
58
|
+
# Nutrition
|
59
|
+
'NUTR',
|
60
|
+
# Nutrition and Food Sciences
|
61
|
+
'NU FS',
|
62
|
+
# Plant Science
|
63
|
+
'PL SC',
|
64
|
+
# Renewable Resources
|
65
|
+
'REN R',
|
66
|
+
# Rural Sociology
|
67
|
+
'R SOC',
|
68
|
+
# Soil Science
|
69
|
+
'SOILS',
|
70
|
+
# University
|
71
|
+
'UNIV',
|
72
|
+
# Work Experience
|
73
|
+
'WKEXP'
|
74
|
+
],
|
75
|
+
'Arts' => [
|
76
|
+
'ANTHR',
|
77
|
+
'ART H',
|
78
|
+
'ART',
|
79
|
+
'DES',
|
80
|
+
'DRAMA',
|
81
|
+
'ECON',
|
82
|
+
'ENGL',
|
83
|
+
'FS',
|
84
|
+
'HIST',
|
85
|
+
'POL S',
|
86
|
+
'RELIG',
|
87
|
+
'WRITE',
|
88
|
+
'WRS',
|
89
|
+
'LING',
|
90
|
+
'CLASS',
|
91
|
+
'GREEK',
|
92
|
+
'LATIN',
|
93
|
+
'MUSIC',
|
94
|
+
'PHIL',
|
95
|
+
# 'PSYCO', Must be specified per course since could be art or science
|
96
|
+
'SOC',
|
97
|
+
'CSL',
|
98
|
+
'C LIT',
|
99
|
+
'INT D',
|
100
|
+
'W ST'
|
101
|
+
],
|
102
|
+
'Science' => [
|
103
|
+
# Astronomy
|
104
|
+
'ASTRO',
|
105
|
+
# Biochemistry (taught by the Faculty of Medicine and Dentistry)
|
106
|
+
'BIOCH',
|
107
|
+
# Biochimie (Faculté Saint-Jean)
|
108
|
+
'BIOCM',
|
109
|
+
# Biological Science - Biology
|
110
|
+
'BIOL',
|
111
|
+
# Biological Science - Botany
|
112
|
+
'BOT',
|
113
|
+
# Biological Science - Entomology
|
114
|
+
'ENT',
|
115
|
+
# Biological Science - Genetics
|
116
|
+
'GENET',
|
117
|
+
# Biological Science - Microbiology
|
118
|
+
'MICRB',
|
119
|
+
# Biological Science - Zoology
|
120
|
+
'ZOOL',
|
121
|
+
# Biologie (Faculté Saint-Jean)
|
122
|
+
'BIOLE',
|
123
|
+
# Cell Biology (taught by the Faculty of Medicine and Dentistry)
|
124
|
+
'CELL',
|
125
|
+
# Chemistry
|
126
|
+
'CHEM',
|
127
|
+
# Chimie (Faculté Saint-Jean)
|
128
|
+
'CHIM',
|
129
|
+
# Computing Science
|
130
|
+
'CMPUT',
|
131
|
+
# Earth and Atmospheric Sciences [formerly Geography and Geology
|
132
|
+
'EAS',
|
133
|
+
# Environmental Physical Sciences
|
134
|
+
'ENVPS',
|
135
|
+
# Geophysics
|
136
|
+
'GEOPH',
|
137
|
+
# Immunology and Infection
|
138
|
+
'IMIN',
|
139
|
+
# Laboratory Animal Management
|
140
|
+
'LB AN',
|
141
|
+
# Marine Science
|
142
|
+
'MA SC',
|
143
|
+
# Mathematical Physics
|
144
|
+
'MA PH',
|
145
|
+
# Mathematics
|
146
|
+
'MATH',
|
147
|
+
# Mathématiques (Faculté Saint-Jean)
|
148
|
+
'MATHQ',
|
149
|
+
# Neuroscience (taught by the Faculty of Medicine and Dentistry)
|
150
|
+
'NEURO',
|
151
|
+
# Paleontology
|
152
|
+
'PALEO',
|
153
|
+
# Pharmacology (taught by the Faculty of Medicine and Dentistry)
|
154
|
+
'PMCOL',
|
155
|
+
# Physiology (taught by the Faculty of Medicine and Dentistry)
|
156
|
+
'PHYSL',
|
157
|
+
# Physics
|
158
|
+
'PHYS',
|
159
|
+
# Physique (Faculté Saint-Jean)
|
160
|
+
'PHYSQ',
|
161
|
+
# Psychology
|
162
|
+
# 'PSYCO', Must be specified per course since could be art or science
|
163
|
+
# Sciences de la Terre et de l'atmosphére (Faculté Saint-Jean)
|
164
|
+
'SCTA',
|
165
|
+
# Statistics
|
166
|
+
'STAT',
|
167
|
+
# Statistique (Faculté Saint-Jean)
|
168
|
+
'STATQ'
|
169
|
+
]
|
24
170
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
#
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
'FOREN',
|
43
|
-
# Forest Science
|
44
|
-
'FOR',
|
45
|
-
# Human Ecology
|
46
|
-
'HECOL',
|
47
|
-
# Interdisciplinary Courses
|
48
|
-
'INT D',
|
49
|
-
# Nutrition
|
50
|
-
'NUTR',
|
51
|
-
# Nutrition and Food Sciences
|
52
|
-
'NU FS',
|
53
|
-
# Plant Science
|
54
|
-
'PL SC',
|
55
|
-
# Renewable Resources
|
56
|
-
'REN R',
|
57
|
-
# Rural Sociology
|
58
|
-
'R SOC',
|
59
|
-
# Soil Science
|
60
|
-
'SOILS',
|
61
|
-
# University
|
62
|
-
'UNIV',
|
63
|
-
# Work Experience
|
64
|
-
'WKEXP'
|
65
|
-
],
|
66
|
-
'Arts' => [
|
67
|
-
'ANTHR',
|
68
|
-
'ART H',
|
69
|
-
'ART',
|
70
|
-
'DES',
|
71
|
-
'DRAMA',
|
72
|
-
'ECON',
|
73
|
-
'ENGL',
|
74
|
-
'FS',
|
75
|
-
'HIST',
|
76
|
-
'POL S',
|
77
|
-
'RELIG',
|
78
|
-
'WRITE',
|
79
|
-
'WRS',
|
80
|
-
'LING',
|
81
|
-
'CLASS',
|
82
|
-
'GREEK',
|
83
|
-
'LATIN',
|
84
|
-
'MUSIC',
|
85
|
-
'PHIL',
|
86
|
-
# 'PSYCO', Must be specified per course since could be art or science
|
87
|
-
'SOC',
|
88
|
-
'CSL',
|
89
|
-
'C LIT',
|
90
|
-
'INT D',
|
91
|
-
'W ST'
|
92
|
-
],
|
93
|
-
'Science' => [
|
94
|
-
# Astronomy
|
95
|
-
'ASTRO',
|
96
|
-
# Biochemistry (taught by the Faculty of Medicine and Dentistry)
|
97
|
-
'BIOCH',
|
98
|
-
# Biochimie (Faculté Saint-Jean)
|
99
|
-
'BIOCM',
|
100
|
-
# Biological Science - Biology
|
101
|
-
'BIOL',
|
102
|
-
# Biological Science - Botany
|
103
|
-
'BOT',
|
104
|
-
# Biological Science - Entomology
|
105
|
-
'ENT',
|
106
|
-
# Biological Science - Genetics
|
107
|
-
'GENET',
|
108
|
-
# Biological Science - Microbiology
|
109
|
-
'MICRB',
|
110
|
-
# Biological Science - Zoology
|
111
|
-
'ZOOL',
|
112
|
-
# Biologie (Faculté Saint-Jean)
|
113
|
-
'BIOLE',
|
114
|
-
# Cell Biology (taught by the Faculty of Medicine and Dentistry)
|
115
|
-
'CELL',
|
116
|
-
# Chemistry
|
117
|
-
'CHEM',
|
118
|
-
# Chimie (Faculté Saint-Jean)
|
119
|
-
'CHIM',
|
120
|
-
# Computing Science
|
121
|
-
'CMPUT',
|
122
|
-
# Earth and Atmospheric Sciences [formerly Geography and Geology
|
123
|
-
'EAS',
|
124
|
-
# Environmental Physical Sciences
|
125
|
-
'ENVPS',
|
126
|
-
# Geophysics
|
127
|
-
'GEOPH',
|
128
|
-
# Immunology and Infection
|
129
|
-
'IMIN',
|
130
|
-
# Laboratory Animal Management
|
131
|
-
'LB AN',
|
132
|
-
# Marine Science
|
133
|
-
'MA SC',
|
134
|
-
# Mathematical Physics
|
135
|
-
'MA PH',
|
136
|
-
# Mathematics
|
137
|
-
'MATH',
|
138
|
-
# Mathématiques (Faculté Saint-Jean)
|
139
|
-
'MATHQ',
|
140
|
-
# Neuroscience (taught by the Faculty of Medicine and Dentistry)
|
141
|
-
'NEURO',
|
142
|
-
# Paleontology
|
143
|
-
'PALEO',
|
144
|
-
# Pharmacology (taught by the Faculty of Medicine and Dentistry)
|
145
|
-
'PMCOL',
|
146
|
-
# Physiology (taught by the Faculty of Medicine and Dentistry)
|
147
|
-
'PHYSL',
|
148
|
-
# Physics
|
149
|
-
'PHYS',
|
150
|
-
# Physique (Faculté Saint-Jean)
|
151
|
-
'PHYSQ',
|
152
|
-
# Psychology
|
153
|
-
# 'PSYCO', Must be specified per course since could be art or science
|
154
|
-
# Sciences de la Terre et de l'atmosphére (Faculté Saint-Jean)
|
155
|
-
'SCTA',
|
156
|
-
# Statistics
|
157
|
-
'STAT',
|
158
|
-
# Statistique (Faculté Saint-Jean)
|
159
|
-
'STATQ'
|
160
|
-
]
|
171
|
+
}
|
172
|
+
attr_reader(
|
173
|
+
# @returns [String]
|
174
|
+
:subject,
|
175
|
+
# @returns [Integer]
|
176
|
+
:number,
|
177
|
+
# @returns [String]
|
178
|
+
:name,
|
179
|
+
# @returns [Grade]
|
180
|
+
:grade,
|
181
|
+
# @returns [Integer]
|
182
|
+
:units,
|
183
|
+
# @returns [Date]
|
184
|
+
:date_completed,
|
185
|
+
# @returns [String]
|
186
|
+
:faculty
|
187
|
+
)
|
161
188
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
189
|
+
def self.from_hash(hash)
|
190
|
+
begin
|
191
|
+
new(
|
192
|
+
hash['subject'],
|
193
|
+
hash['number'],
|
194
|
+
hash['name'],
|
195
|
+
hash['grade'],
|
196
|
+
hash['units'],
|
197
|
+
hash['date_completed'],
|
198
|
+
hash['faculty']
|
199
|
+
)
|
200
|
+
rescue
|
201
|
+
new(
|
202
|
+
hash[:subject],
|
203
|
+
hash[:number],
|
204
|
+
hash[:name],
|
205
|
+
hash[:grade],
|
206
|
+
hash[:units],
|
207
|
+
hash[:date_completed],
|
208
|
+
hash[:faculty]
|
209
|
+
)
|
210
|
+
end
|
211
|
+
end
|
179
212
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
213
|
+
def initialize(
|
214
|
+
subject_,
|
215
|
+
number_,
|
216
|
+
name_,
|
217
|
+
grade_,
|
218
|
+
units_,
|
219
|
+
date_completed_,
|
220
|
+
faculty_=nil
|
221
|
+
)
|
222
|
+
@subject = subject_
|
223
|
+
@number = number_
|
224
|
+
@name = name_
|
225
|
+
@grade = Grade.new(grade_ || "N/A")
|
226
|
+
@units = units_
|
227
|
+
@date_completed = date_completed_
|
195
228
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
229
|
+
# @todo This is totally wrong, but I'm not using this right now so I'm not in a rush to fix it.
|
230
|
+
@faculty = if faculty_.nil?
|
231
|
+
UNIVERSITY_OF_ALBERTA_SUBJECT_HIERARCHY[@subject]
|
232
|
+
else
|
233
|
+
faculty_
|
234
|
+
end
|
201
235
|
end
|
202
|
-
end
|
203
236
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
237
|
+
def grade_has_points?() @grade.has_points? end
|
238
|
+
|
239
|
+
def grade_points
|
240
|
+
@units * @grade.points
|
241
|
+
end
|
208
242
|
end
|
209
|
-
end
|
243
|
+
end
|
data/lib/gpa/version.rb
CHANGED
data/spec/course_spec.rb
CHANGED
@@ -18,30 +18,30 @@ ExpectedCourse = Struct.new(
|
|
18
18
|
# @returns [String]
|
19
19
|
:faculty,
|
20
20
|
# @returns [Numeric]
|
21
|
-
:grade_points
|
21
|
+
:grade_points
|
22
22
|
)
|
23
|
-
|
24
|
-
describe Course do
|
23
|
+
describe Gpa::Course do
|
25
24
|
it "should initialize properly" do
|
26
25
|
@expected_course = ExpectedCourse.new(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
26
|
+
"WRS",
|
27
|
+
123,
|
28
|
+
"C4 Name",
|
29
|
+
"B",
|
30
|
+
2,
|
31
|
+
Date.parse('2008-12-01'),
|
32
|
+
'Arts',
|
33
|
+
6.0
|
35
34
|
)
|
36
|
-
@patient = Course.new(
|
37
|
-
@expected_course.subject,
|
35
|
+
@patient = Gpa::Course.new(
|
36
|
+
@expected_course.subject,
|
38
37
|
@expected_course.number,
|
39
38
|
@expected_course.name,
|
40
39
|
@expected_course.grade,
|
41
40
|
@expected_course.units,
|
42
|
-
@expected_course.date_completed
|
41
|
+
@expected_course.date_completed,
|
42
|
+
@expected_course.faculty
|
43
43
|
)
|
44
|
-
|
44
|
+
|
45
45
|
check_patient
|
46
46
|
end
|
47
47
|
|
data/spec/gpa_spec.rb
CHANGED
@@ -3,23 +3,26 @@ require_relative 'support/spec_helper'
|
|
3
3
|
|
4
4
|
require_relative '../lib/gpa'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
describe Gpa do
|
6
|
+
describe Gpa::CourseArray do
|
9
7
|
it "should load courses from a YAML file properly" do
|
10
|
-
Gpa.load_courses_from_file(TEST_COURSES_FILE).
|
11
|
-
|
12
|
-
|
8
|
+
Gpa::CourseArray.load_courses_from_file(TEST_COURSES_FILE).each_with_index do |course, i|
|
9
|
+
{
|
10
|
+
subject: course.subject,
|
11
|
+
number: course.number,
|
12
|
+
name: course.name,
|
13
|
+
grade: course.grade,
|
14
|
+
units: course.units,
|
15
|
+
date_completed: course.date_completed
|
16
|
+
}.must_equal EXPECTED_COURSES_IN_HASH_FORM_FROM_COURSES_FILE[i]
|
17
|
+
end
|
13
18
|
end
|
14
|
-
end
|
15
19
|
|
16
|
-
describe Array do
|
17
20
|
describe 'should calculate the gpa of all courses inside itself' do
|
18
21
|
it "for all courses" do
|
19
|
-
Gpa.load_courses_from_file(TEST_COURSES_FILE).gpa.must_equal
|
22
|
+
Gpa::CourseArray.load_courses_from_file(TEST_COURSES_FILE).gpa.must_equal 3.669696969696969
|
20
23
|
end
|
21
24
|
it "for a specified number of most recent courses" do
|
22
|
-
Gpa.load_courses_from_file(TEST_COURSES_FILE).gpa(60).must_equal 3.
|
25
|
+
Gpa::CourseArray.load_courses_from_file(TEST_COURSES_FILE).gpa(60).must_equal 3.9550000000000014
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
data/spec/support/courses.yml
CHANGED
@@ -1,200 +1,184 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
number: 101
|
6
|
-
name: Exploring Writing
|
1
|
+
---
|
2
|
+
subject: BIOL
|
3
|
+
number: 659
|
4
|
+
name: BIOL Course name
|
7
5
|
grade: B
|
8
6
|
units: 27
|
9
7
|
date_completed: 2008-12-1
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
name: Integrated Science
|
8
|
+
---
|
9
|
+
subject: PHYS
|
10
|
+
number: 222
|
11
|
+
name: Course name
|
15
12
|
grade: A-
|
16
13
|
units: 3
|
17
|
-
date_completed: 2009-
|
18
|
-
|
19
|
-
|
20
|
-
--- !ruby/object:Course
|
21
|
-
subject: CMPUT
|
14
|
+
date_completed: 2009-9-1
|
15
|
+
---
|
16
|
+
subject: ECON
|
22
17
|
number: 175
|
23
|
-
name:
|
18
|
+
name: Course name
|
24
19
|
grade: A+
|
25
20
|
units: 3
|
26
21
|
date_completed: 2009-12-1
|
27
|
-
---
|
28
|
-
subject:
|
22
|
+
---
|
23
|
+
subject: ECON
|
29
24
|
number: 272
|
30
|
-
name:
|
25
|
+
name: Course name
|
31
26
|
grade: A+
|
32
27
|
units: 3
|
33
28
|
date_completed: 2009-12-1
|
34
|
-
---
|
29
|
+
---
|
35
30
|
subject: DRAMA
|
36
|
-
number:
|
37
|
-
name:
|
31
|
+
number: 297
|
32
|
+
name: Course name
|
38
33
|
grade: B+
|
39
34
|
units: 3
|
40
35
|
date_completed: 2009-12-1
|
41
|
-
---
|
36
|
+
---
|
42
37
|
subject: MATH
|
43
38
|
number: 120
|
44
|
-
name:
|
39
|
+
name: Course name
|
45
40
|
grade: A
|
46
41
|
units: 3
|
47
42
|
date_completed: 2009-12-1
|
48
|
-
|
49
|
-
|
50
|
-
subject: CMPUT
|
43
|
+
---
|
44
|
+
subject: ECON
|
51
45
|
number: 201
|
52
|
-
name:
|
46
|
+
name: Course name
|
53
47
|
grade: A+
|
54
48
|
units: 3
|
55
|
-
date_completed: 2010-
|
56
|
-
---
|
57
|
-
subject:
|
58
|
-
number:
|
59
|
-
name:
|
49
|
+
date_completed: 2010-9-1
|
50
|
+
---
|
51
|
+
subject: ECON
|
52
|
+
number: 209
|
53
|
+
name: Course name
|
60
54
|
grade: A+
|
61
55
|
units: 3
|
62
|
-
date_completed: 2010-
|
63
|
-
---
|
64
|
-
subject:
|
56
|
+
date_completed: 2010-9-1
|
57
|
+
---
|
58
|
+
subject: ECON
|
65
59
|
number: 229
|
66
|
-
name:
|
60
|
+
name: Course name
|
67
61
|
grade: A+
|
68
62
|
units: 3
|
69
|
-
date_completed: 2010-
|
70
|
-
---
|
63
|
+
date_completed: 2010-9-1
|
64
|
+
---
|
71
65
|
subject: ENGL
|
72
66
|
number: 125
|
73
|
-
name:
|
67
|
+
name: Course name
|
74
68
|
grade: A
|
75
69
|
units: 3
|
76
|
-
date_completed: 2010-
|
77
|
-
---
|
70
|
+
date_completed: 2010-9-1
|
71
|
+
---
|
78
72
|
subject: PHIL
|
79
73
|
number: 215
|
80
|
-
name:
|
74
|
+
name: Course name
|
81
75
|
grade: A
|
82
76
|
units: 3
|
83
|
-
date_completed: 2010-
|
84
|
-
|
85
|
-
--- !ruby/object:Course
|
77
|
+
date_completed: 2010-9-1
|
78
|
+
---
|
86
79
|
subject: PHIL
|
87
80
|
number: 265
|
88
|
-
name:
|
81
|
+
name: Course name
|
89
82
|
grade: A
|
90
83
|
units: 3
|
91
84
|
date_completed: 2010-8-1
|
92
|
-
|
93
|
-
|
94
|
-
--- !ruby/object:Course
|
95
|
-
subject: CMPUT
|
85
|
+
---
|
86
|
+
subject: ECON
|
96
87
|
number: 325
|
97
|
-
name:
|
88
|
+
name: Course name
|
98
89
|
grade: A+
|
99
90
|
units: 3
|
100
91
|
date_completed: 2010-12-1
|
101
|
-
---
|
102
|
-
subject:
|
92
|
+
---
|
93
|
+
subject: ECON
|
103
94
|
number: 366
|
104
|
-
name:
|
95
|
+
name: Course name
|
105
96
|
grade: A+
|
106
97
|
units: 3
|
107
98
|
date_completed: 2010-12-1
|
108
|
-
---
|
99
|
+
---
|
109
100
|
subject: MATH
|
110
|
-
number:
|
111
|
-
name:
|
101
|
+
number: 219
|
102
|
+
name: Course name
|
112
103
|
grade: A-
|
113
104
|
units: 3
|
114
105
|
date_completed: 2010-12-1
|
115
|
-
---
|
106
|
+
---
|
116
107
|
subject: MATH
|
117
108
|
number: 225
|
118
|
-
name:
|
109
|
+
name: Course name
|
119
110
|
grade: A-
|
120
111
|
units: 3
|
121
112
|
date_completed: 2010-12-1
|
122
|
-
---
|
113
|
+
---
|
123
114
|
subject: STAT
|
124
115
|
number: 265
|
125
|
-
name:
|
116
|
+
name: Course name
|
126
117
|
grade: A
|
127
118
|
units: 3
|
128
119
|
date_completed: 2010-12-1
|
129
|
-
|
130
|
-
|
131
|
-
subject: CMPUT
|
120
|
+
---
|
121
|
+
subject: ECON
|
132
122
|
number: 379
|
133
|
-
name:
|
123
|
+
name: Course name
|
134
124
|
grade: A-
|
135
125
|
units: 3
|
136
|
-
date_completed: 2011-
|
137
|
-
---
|
138
|
-
subject:
|
126
|
+
date_completed: 2011-9-1
|
127
|
+
---
|
128
|
+
subject: ECON
|
139
129
|
number: 396
|
140
|
-
name:
|
130
|
+
name: Course name
|
141
131
|
grade: A
|
142
132
|
units: 3
|
143
|
-
date_completed: 2011-
|
144
|
-
---
|
145
|
-
subject:
|
146
|
-
number:
|
147
|
-
name:
|
133
|
+
date_completed: 2011-9-1
|
134
|
+
---
|
135
|
+
subject: ECON
|
136
|
+
number: 912
|
137
|
+
name: Course name
|
148
138
|
grade: A+
|
149
139
|
units: 3
|
150
|
-
date_completed: 2011-
|
151
|
-
---
|
140
|
+
date_completed: 2011-9-1
|
141
|
+
---
|
152
142
|
subject: STAT
|
153
143
|
number: 266
|
154
|
-
name:
|
144
|
+
name: Course name
|
155
145
|
grade: A+
|
156
146
|
units: 3
|
157
|
-
date_completed: 2011-
|
158
|
-
|
159
|
-
|
160
|
-
subject: CMPUT
|
147
|
+
date_completed: 2011-9-1
|
148
|
+
---
|
149
|
+
subject: ECON
|
161
150
|
number: 399
|
162
|
-
name:
|
151
|
+
name: Course name
|
163
152
|
grade: A+
|
164
153
|
units: 3
|
165
154
|
date_completed: 2011-8-1
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
number: 400
|
171
|
-
name: Industrial Internship Practicum
|
155
|
+
---
|
156
|
+
subject: ECON
|
157
|
+
number: 900
|
158
|
+
name: Course name
|
172
159
|
grade: ~
|
173
160
|
units: 3
|
174
161
|
date_completed: 2012-12-1
|
175
|
-
---
|
176
|
-
subject:
|
177
|
-
number:
|
178
|
-
name:
|
162
|
+
---
|
163
|
+
subject: ECON
|
164
|
+
number: 918
|
165
|
+
name: Course name
|
179
166
|
grade: A
|
180
167
|
units: 3
|
181
168
|
date_completed: 2012-12-1
|
182
|
-
---
|
183
|
-
subject:
|
184
|
-
number:
|
185
|
-
name:
|
169
|
+
---
|
170
|
+
subject: ECON
|
171
|
+
number: 695
|
172
|
+
name: Course name
|
186
173
|
grade: A+
|
187
174
|
units: 3
|
188
175
|
date_completed: 2012-12-1
|
189
|
-
---
|
176
|
+
---
|
190
177
|
subject: STAT
|
191
|
-
number:
|
192
|
-
name:
|
178
|
+
number: 699
|
179
|
+
name: Course name
|
193
180
|
grade: A
|
194
181
|
units: 3
|
195
182
|
date_completed: 2012-12-1
|
196
183
|
|
197
|
-
## Winter
|
198
184
|
|
199
|
-
# Fifth year
|
200
|
-
## Fall
|
data/spec/support/spec_helper.rb
CHANGED
@@ -7,41 +7,41 @@ require 'minitest/autorun'
|
|
7
7
|
TEST_COURSES_FILE = File.expand_path('../courses.yml', __FILE__)
|
8
8
|
EXPECTED_COURSES_IN_HASH_FORM_FROM_COURSES_FILE = [
|
9
9
|
{
|
10
|
-
:subject => "
|
11
|
-
:number =>
|
12
|
-
:name => "
|
10
|
+
:subject => "BIOL",
|
11
|
+
:number => 659,
|
12
|
+
:name => "BIOL Course name",
|
13
13
|
:grade => "B",
|
14
14
|
:units => 27,
|
15
15
|
:date_completed => Date.parse('2008-12-01')
|
16
16
|
},
|
17
17
|
{
|
18
|
-
:subject => "
|
19
|
-
:number =>
|
20
|
-
:name => "
|
18
|
+
:subject => "PHYS",
|
19
|
+
:number => 222,
|
20
|
+
:name => "Course name",
|
21
21
|
:grade => "A-",
|
22
22
|
:units => 3,
|
23
|
-
:date_completed => Date.parse('2009-
|
23
|
+
:date_completed => Date.parse('2009-09-01')
|
24
24
|
},
|
25
25
|
{
|
26
|
-
:subject => "
|
26
|
+
:subject => "ECON",
|
27
27
|
:number => 175,
|
28
|
-
:name => "
|
28
|
+
:name => "Course name",
|
29
29
|
:grade => "A+",
|
30
30
|
:units => 3,
|
31
31
|
:date_completed => Date.parse('2009-12-01')
|
32
32
|
},
|
33
33
|
{
|
34
|
-
:subject => "
|
34
|
+
:subject => "ECON",
|
35
35
|
:number => 272,
|
36
|
-
:name => "
|
36
|
+
:name => "Course name",
|
37
37
|
:grade => "A+",
|
38
38
|
:units => 3,
|
39
39
|
:date_completed => Date.parse('2009-12-01')
|
40
40
|
},
|
41
41
|
{
|
42
42
|
:subject => "DRAMA",
|
43
|
-
:number =>
|
44
|
-
:name => "
|
43
|
+
:number => 297,
|
44
|
+
:name => "Course name",
|
45
45
|
:grade => "B+",
|
46
46
|
:units => 3,
|
47
47
|
:date_completed => Date.parse('2009-12-01')
|
@@ -49,79 +49,79 @@ EXPECTED_COURSES_IN_HASH_FORM_FROM_COURSES_FILE = [
|
|
49
49
|
{
|
50
50
|
:subject => "MATH",
|
51
51
|
:number => 120,
|
52
|
-
:name => "
|
52
|
+
:name => "Course name",
|
53
53
|
:grade => "A",
|
54
54
|
:units => 3,
|
55
55
|
:date_completed => Date.parse('2009-12-01')
|
56
56
|
},
|
57
57
|
{
|
58
|
-
:subject => "
|
58
|
+
:subject => "ECON",
|
59
59
|
:number => 201,
|
60
|
-
:name => "
|
60
|
+
:name => "Course name",
|
61
61
|
:grade => "A+",
|
62
62
|
:units => 3,
|
63
|
-
:date_completed => Date.parse('2010-
|
63
|
+
:date_completed => Date.parse('2010-09-01')
|
64
64
|
},
|
65
65
|
{
|
66
|
-
:subject => "
|
67
|
-
:number =>
|
68
|
-
:name => "
|
66
|
+
:subject => "ECON",
|
67
|
+
:number => 209,
|
68
|
+
:name => "Course name",
|
69
69
|
:grade => "A+",
|
70
70
|
:units => 3,
|
71
|
-
:date_completed => Date.parse('2010-
|
71
|
+
:date_completed => Date.parse('2010-09-01')
|
72
72
|
},
|
73
73
|
{
|
74
|
-
:subject => "
|
74
|
+
:subject => "ECON",
|
75
75
|
:number => 229,
|
76
|
-
:name => "
|
76
|
+
:name => "Course name",
|
77
77
|
:grade => "A+",
|
78
78
|
:units => 3,
|
79
|
-
:date_completed => Date.parse('2010-
|
79
|
+
:date_completed => Date.parse('2010-09-01')
|
80
80
|
},
|
81
81
|
{
|
82
82
|
:subject => "ENGL",
|
83
83
|
:number => 125,
|
84
|
-
:name => "
|
84
|
+
:name => "Course name",
|
85
85
|
:grade => "A",
|
86
86
|
:units => 3,
|
87
|
-
:date_completed => Date.parse('2010-
|
87
|
+
:date_completed => Date.parse('2010-09-01')
|
88
88
|
},
|
89
89
|
{
|
90
90
|
:subject => "PHIL",
|
91
91
|
:number => 215,
|
92
|
-
:name => "
|
92
|
+
:name => "Course name",
|
93
93
|
:grade => "A",
|
94
94
|
:units => 3,
|
95
|
-
:date_completed => Date.parse('2010-
|
95
|
+
:date_completed => Date.parse('2010-09-01')
|
96
96
|
},
|
97
97
|
{
|
98
98
|
:subject => "PHIL",
|
99
99
|
:number => 265,
|
100
|
-
:name => "
|
100
|
+
:name => "Course name",
|
101
101
|
:grade => "A",
|
102
102
|
:units => 3,
|
103
103
|
:date_completed => Date.parse('2010-08-01')
|
104
104
|
},
|
105
105
|
{
|
106
|
-
:subject => "
|
106
|
+
:subject => "ECON",
|
107
107
|
:number => 325,
|
108
|
-
:name => "
|
108
|
+
:name => "Course name",
|
109
109
|
:grade => "A+",
|
110
110
|
:units => 3,
|
111
111
|
:date_completed => Date.parse('2010-12-01')
|
112
112
|
},
|
113
113
|
{
|
114
|
-
:subject => "
|
114
|
+
:subject => "ECON",
|
115
115
|
:number => 366,
|
116
|
-
:name => "
|
116
|
+
:name => "Course name",
|
117
117
|
:grade => "A+",
|
118
118
|
:units => 3,
|
119
119
|
:date_completed => Date.parse('2010-12-01')
|
120
120
|
},
|
121
121
|
{
|
122
122
|
:subject => "MATH",
|
123
|
-
:number =>
|
124
|
-
:name => "
|
123
|
+
:number => 219,
|
124
|
+
:name => "Course name",
|
125
125
|
:grade => "A-",
|
126
126
|
:units => 3,
|
127
127
|
:date_completed => Date.parse('2010-12-01')
|
@@ -129,7 +129,7 @@ EXPECTED_COURSES_IN_HASH_FORM_FROM_COURSES_FILE = [
|
|
129
129
|
{
|
130
130
|
:subject => "MATH",
|
131
131
|
:number => 225,
|
132
|
-
:name => "
|
132
|
+
:name => "Course name",
|
133
133
|
:grade => "A-",
|
134
134
|
:units => 3,
|
135
135
|
:date_completed => Date.parse('2010-12-01')
|
@@ -137,79 +137,79 @@ EXPECTED_COURSES_IN_HASH_FORM_FROM_COURSES_FILE = [
|
|
137
137
|
{
|
138
138
|
:subject => "STAT",
|
139
139
|
:number => 265,
|
140
|
-
:name => "
|
140
|
+
:name => "Course name",
|
141
141
|
:grade => "A",
|
142
142
|
:units => 3,
|
143
143
|
:date_completed => Date.parse('2010-12-01')
|
144
144
|
},
|
145
145
|
{
|
146
|
-
:subject => "
|
146
|
+
:subject => "ECON",
|
147
147
|
:number => 379,
|
148
|
-
:name => "
|
148
|
+
:name => "Course name",
|
149
149
|
:grade => "A-",
|
150
150
|
:units => 3,
|
151
|
-
:date_completed => Date.parse('2011-
|
151
|
+
:date_completed => Date.parse('2011-09-01')
|
152
152
|
},
|
153
153
|
{
|
154
|
-
:subject => "
|
154
|
+
:subject => "ECON",
|
155
155
|
:number => 396,
|
156
|
-
:name => "
|
156
|
+
:name => "Course name",
|
157
157
|
:grade => "A",
|
158
158
|
:units => 3,
|
159
|
-
:date_completed => Date.parse('2011-
|
159
|
+
:date_completed => Date.parse('2011-09-01')
|
160
160
|
},
|
161
161
|
{
|
162
|
-
:subject => "
|
163
|
-
:number =>
|
164
|
-
:name => "
|
162
|
+
:subject => "ECON",
|
163
|
+
:number => 912,
|
164
|
+
:name => "Course name",
|
165
165
|
:grade => "A+",
|
166
166
|
:units => 3,
|
167
|
-
:date_completed => Date.parse('2011-
|
167
|
+
:date_completed => Date.parse('2011-09-01')
|
168
168
|
},
|
169
169
|
{
|
170
170
|
:subject => "STAT",
|
171
171
|
:number => 266,
|
172
|
-
:name => "
|
172
|
+
:name => "Course name",
|
173
173
|
:grade => "A+",
|
174
174
|
:units => 3,
|
175
|
-
:date_completed => Date.parse('2011-
|
175
|
+
:date_completed => Date.parse('2011-09-01')
|
176
176
|
},
|
177
177
|
{
|
178
|
-
:subject => "
|
178
|
+
:subject => "ECON",
|
179
179
|
:number => 399,
|
180
|
-
:name => "
|
180
|
+
:name => "Course name",
|
181
181
|
:grade => "A+",
|
182
182
|
:units => 3,
|
183
183
|
:date_completed => Date.parse('2011-08-01')
|
184
184
|
},
|
185
185
|
{
|
186
|
-
:subject => "
|
187
|
-
:number =>
|
188
|
-
:name => "
|
189
|
-
:grade =>
|
186
|
+
:subject => "ECON",
|
187
|
+
:number => 900,
|
188
|
+
:name => "Course name",
|
189
|
+
:grade => "N/A",
|
190
190
|
:units => 3,
|
191
191
|
:date_completed => Date.parse('2012-12-01')
|
192
192
|
},
|
193
193
|
{
|
194
|
-
:subject => "
|
195
|
-
:number =>
|
196
|
-
:name => "
|
194
|
+
:subject => "ECON",
|
195
|
+
:number => 918,
|
196
|
+
:name => "Course name",
|
197
197
|
:grade => "A",
|
198
198
|
:units => 3,
|
199
199
|
:date_completed => Date.parse('2012-12-01')
|
200
200
|
},
|
201
201
|
{
|
202
|
-
:subject => "
|
203
|
-
:number =>
|
204
|
-
:name => "
|
202
|
+
:subject => "ECON",
|
203
|
+
:number => 695,
|
204
|
+
:name => "Course name",
|
205
205
|
:grade => "A+",
|
206
206
|
:units => 3,
|
207
207
|
:date_completed => Date.parse('2012-12-01')
|
208
208
|
},
|
209
209
|
{
|
210
210
|
:subject => "STAT",
|
211
|
-
:number =>
|
212
|
-
:name => "
|
211
|
+
:number => 699,
|
212
|
+
:name => "Course name",
|
213
213
|
:grade => "A",
|
214
214
|
:units => 3,
|
215
215
|
:date_completed => Date.parse('2012-12-01')
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Morrill
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: dmorrill10-utils
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: simplecov
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|