Class: Studium::AttributeBokuLectureToCurriculum
- Inherits:
-
AttributeLectureToCurriculum
- Object
- AttributeLectureToCurriculum
- Studium::AttributeBokuLectureToCurriculum
show all
- Defined in:
- lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb
Overview
AttributeBokuLectureToCurriculum.new
Constant Summary
collapse
- NAMESPACE =
inspect
- USE_THIS_REGEX =
#
USE_THIS_REGEX
See the following link at Rubular:
http://rubular.com/r/4wM8G28SGA
#
/e\)\);}"><\/span><span>(\d{3}) (.+) <\/span><span>\(?/
- REGEX_FOR_OBTAINING_THE_TITLE =
/<td class=" MaskRenderer MaskLabel"><label class="Mask ">Titel<\/label><\/td><td colspan="0" class=" MaskRenderer top"><table class=" MaskSpacing">\s*<tr>\s*<td class=" MaskRenderer"><span class="bold ">(.+)<\/span><\/td>/
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === Studium::AttributeBokuLectureToCurriculum[] ========================================================================= #.
Instance Method Summary
collapse
Constructor Details
54
55
56
57
58
59
60
61
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 54
def initialize(
this_url = ARGV,
run_already = true
)
reset
set_url(this_url)
run if run_already
end
|
Class Method Details
.[](i = '') ⇒ Object
#
Studium::AttributeBokuLectureToCurriculum[]
#
377
378
379
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 377
def self.[](i = '')
new(i)
end
|
Instance Method Details
#apply_regex ⇒ Object
#
apply_regex
This will also determine @results.
#
125
126
127
128
129
130
131
132
133
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 125
def apply_regex
if @dataset
scanned_dataset = @dataset.scan(regex?)
results = scanned_dataset.map {|inner_array|
inner_array.map(&:strip)
}.uniq
set_results(results)
end
end
|
#determine_commandline_arguments(i) ⇒ Object
#
determine_commandline_arguments
#
74
75
76
77
78
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 74
def determine_commandline_arguments(i)
if i.any? {|entry| entry.start_with?('--') }
@commandline = i.select {|entry| entry.start_with?('--') } end
end
|
#determine_title_of_the_lecture ⇒ Object
#
determine_title_of_the_lecture
#
112
113
114
115
116
117
118
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 112
def determine_title_of_the_lecture
_ = dataset?
if _
_ =~ REGEX_FOR_OBTAINING_THE_TITLE
set_title($1.to_s.dup)
end
end
|
#display_result ⇒ Object
#
display_result (display tag)
#
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 234
def display_result
report_the_title_in_use
e
e seagreen('The following curricula are attributed to the lecture '+
sfancy(title?))+seagreen(':')
e
@results.each {|inner_array|
number_of_the_curriculum = inner_array.first
name_of_the_curriculum = inner_array.last.ljust(88)
e " #{sfancy(name_of_the_curriculum)} "\
"#{orange(number_of_the_curriculum)}"
}; e end
|
#do_batch_process_all_boku_lectures(shall_we_exit = true) ⇒ Object
#
do_batch_process_all_boku_lectures
This method can be used to batch-process all passed lectures at the BOKU university.
To invoke this method, do:
attribute_boku_lecture --batch
#
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 257
def do_batch_process_all_boku_lectures(shall_we_exit = true)
all_boku_lectures = Studium.sanitized_dataset_from_file_passed_exams_per_month
all_boku_lectures.select! {|line|
line.include?(' BOKU ') }
all_boku_lectures.each {|line|
splitted = line.split('|').map(&:strip)
name_of_the_lecture = splitted.last
new_url = BeautifulUrl.new('BOKU '+name_of_the_lecture)
new_url = new_url.first if new_url.is_a? Array
set_url(new_url)
unless new_url.include? 'https'
opnn
e 'The URL ('+sfancy(new_url)+') for the lecture '+
sfancy(name_of_the_lecture)+' may possibly be wrong.'
opnn
e 'Thus, '+swarn('we will exit now.')
exit
end
perform_the_main_task_of_this_class
}
exit if shall_we_exit
end
|
#
Note that @commandline will only include “–” instructions.
#
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 147
def (i = @commandline)
if i.is_a? Array
i.each {|entry| (entry) }
else
i = i.to_s.delete('')
case i when /file/,
/location\??/
show_location_of_important_files
exit
when /batch/ do_batch_process_all_boku_lectures
else
i = match_curriculum_name_to_curriculum_number(i)
if i =~ /^-?-?0+/ if registered_curricula?.include?(i.delete('-'))
show_all_lectures_from_this_curriculum(i.delete('-'))
end
end
end
end if i
end
|
#obtain_dataset_from_the_remote_website ⇒ Object
#
obtain_dataset_from_the_remote_website
#
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 90
def obtain_dataset_from_the_remote_website
use_this_url = url?
if use_this_url
opnn; e "Obtaining the dataset from this remote "\
"website: #{sfancy(use_this_url)}"
@dataset = URI.open(use_this_url).read end
end
|
#report_the_title_in_use ⇒ Object
#
report_the_title_in_use
#
138
139
140
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 138
def report_the_title_in_use
e lightblue(title?)
end
|
#reset ⇒ Object
66
67
68
69
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 66
def reset
super()
@namespace = NAMESPACE
end
|
#return_location_of_file_that_keeps_all_lectures_registered ⇒ Object
#
return_location_of_file_that_keeps_all_lectures_registered
#
189
190
191
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 189
def return_location_of_file_that_keeps_all_lectures_registered
log_dir?+'lectures_registered_in_a_specific_curriculum.md'
end
|
#save_into_a_file ⇒ Object
#
save_into_a_file (save tag)
Do not forget that we have to load up the old dataset if it exists, before saving the file again. However had, we will do so only if we have not found the same key yet.
Note that this presently will append into the file no matter what.
If I should ever update this code, then we also need to add the ability to NOT append something IF this lecture has already been registered (and to also store the lecture-id, since some lectures may have the same name).
#
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 207
def save_into_a_file
if @do_save_into_a_file and @dataset
into = return_location_of_file_that_keeps_all_lectures_registered
key = "#{name_of_the_lecture?.dup}:"
if File.exist? into
dataset = File.read(into).split("---\n")
dataset.select! {|line|
line =~ /^[a-zA-Z]+.+:/ }
end
what = ''.dup what << "#{key}#{N}"
@results.each {|inner_array| what << " #{inner_array.join('|')}#{N}"
}
what << "#{N}---#{N}" e "Now storing into `#{sfile(into)}`."
append_what_into(what, into)
end
end
|
#show_all_lectures_from_this_curriculum(curriculum_id_as_number) ⇒ Object
#
show_all_lectures_from_this_curriculum
Invoce this method like so:
attribute_boku --033217
attribute_boku --033255
#
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 304
def show_all_lectures_from_this_curriculum(
curriculum_id_as_number
)
curriculum_id_as_number = curriculum_id_as_number.to_s
use_this_encoding = encoding?
name_of_the_curriculum = assigned_exams?[curriculum_id_as_number]
if name_of_the_curriculum.include? '#'
name_of_the_curriculum = name_of_the_curriculum[0..(name_of_the_curriculum.index('#')-1)].strip
end
dataset = curricula_assigned_exams?
selection = dataset.select {|key, array_values|
key if array_values.include? curriculum_id_as_number
}
n_passed_exams = selection.size.to_s
e
e darkslateblue('Curriculum: ')+
sfancy(name_of_the_curriculum)+
darkslateblue(' (CurriculumID: ')+
lightblue(curriculum_id_as_number.to_s)+
darkslateblue(')')
e
e crimson('The passed ')+simp(n_passed_exams)+crimson(' exams are:')
e
hash_statistics = {} index_counter = 0
n_total_ects_points = 0
selection.each_pair {|name_of_the_lecture, array_values|
index_counter += 1
name_of_the_lecture = name_of_the_lecture.dup if name_of_the_lecture.frozen?
name_of_the_lecture = name_of_the_lecture.force_encoding(use_this_encoding)
_remote_url = BeautifulUrl.new(name_of_the_lecture).first
lv_id_number = ::Studium.return_lv_id_number(name_of_the_lecture).to_s
index = sienna((index_counter.to_s+')').rjust(5)) n_ects_points = ::Studium.return_ects_from_this_lva_number(
lv_id_number, name_of_the_lecture
).to_f
n_total_ects_points += n_ects_points date_when_this_exam_was_passed = Studium.when_was_this_lecture_passed?(name_of_the_lecture)
year = date_when_this_exam_was_passed.split('.').last.to_i
hash_statistics[year] = { n_ects_points: 0 } unless hash_statistics.has_key? year hash_statistics[year][:n_ects_points] += n_ects_points
e ' '+index+' '+
slateblue(name_of_the_lecture.ljust(60))+' '+
'('+palegoldenrod('LV-ID:')+' '+lv_id_number.to_s+
'; '+palegoldenrod('n ECTS:')+' '+
n_ects_points.to_s.rjust(4)+
'; '+palegoldenrod('Passed at:')+
' '+date_when_this_exam_was_passed.to_s+
') '
}
e
e 'In total, '+simp(n_total_ects_points.to_s)+' ECTS points were '\
'passed in the curriculum '+sfancy(name_of_the_curriculum)+'.'
e
unless hash_statistics.empty?
e 'The statistics are as follows:'
e
hash_statistics.each_pair {|year, hash_n_ects_points_passed_in_that_year|
n_ects_points_passed_in_that_year = hash_n_ects_points_passed_in_that_year[:n_ects_points]
e ' In the year '+sfancy(year.to_s)+' '+
orange(n_ects_points_passed_in_that_year.to_s.rjust(4))+
' ECTS points were passed.'
}; e end
end
|
#show_location_of_important_files ⇒ Object
#
show_location_of_important_files
#
182
183
184
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 182
def show_location_of_important_files
e return_location_of_file_that_keeps_all_lectures_registered
end
|
#url? ⇒ Boolean
Also known as:
input?
83
84
85
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 83
def url?
@url
end
|
#use_this_regex? ⇒ Boolean
Also known as:
regex?
105
106
107
|
# File 'lib/studium/utility_scripts/attribute_lecture_to_curriculum/attribute_boku_lecture_to_curriculum.rb', line 105
def use_this_regex?
USE_THIS_REGEX
end
|