Class: Studium::ShowUpcomingExams
- Inherits:
-
Base
- Object
- Base
- Studium::ShowUpcomingExams
show all
- Defined in:
- lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb
Overview
Studium::ShowUpcomingExams
Constant Summary
collapse
- REGEX_TO_EXTRACT_DATE_AND_TIME_FROM_AN_UPCOMING_EXAM =
#
REGEX_TO_EXTRACT_DATE_AND_TIME_FROM_AN_UPCOMING_EXAM
#
/(\d{1,2}\.\d{1,2}\.\d{4},?\s*\d{1,2}:\d{1,2}-\d{1,2}:\d{1,2})/
- SHOW_LEADING_LVA_ID_NUMBER =
#
SHOW_LEADING_LVA_ID_NUMBER
If the following constant is set to true, then we will also display the leading LVA-ID number.
If it is false, that LVA-ID number will NOT be shown.
The numbers make the display a bit uglier, but it may be more useful for the user if that user wants to use the LVA at hand via the browser. For instance I need to know the LVA-ID number, because that way I can quickly copy/paste the full name, and have the remote lecture course opened in my browser of choice. This is very convenient.
#
true
- TRY_TO_SHOW_PRIORITIES_FOR_THE_LECTURES =
#
TRY_TO_SHOW_PRIORITIES_FOR_THE_LECTURES
The following constant will also attempt to show the priorities of a given lecture at hand.
This depends on the priority value having been set in the file called “lecture_information.yml”.
If, however had, such a file exists, and the following constant is set to true, then this class will show the priority of the lecture. Lower number means higher priority, and the colours picked will reflect this priority loosely - the lower the priority, the brighter the colour.
The reasoning behind this is that brighter colours should be easier to notice by the human eyes, and hence may signal a higher “importance”.
The whole idea behind this constant is to visualize more easily on the commandline which upcoming exams are more important than others.
#
true
- USE_OPN =
true
- DISPLAY_HORIZONTAL_BAR_TO_INDICATE_A_NEW_MONTH =
#
DISPLAY_HORIZONTAL_BAR_TO_INDICATE_A_NEW_MONTH
If this constant is set to true, then a horizontal bar will be shown when a new month begins.
#
true
- SEPARATOR_TOKEN_TO_USE =
#
SEPARATOR_TOKEN_TO_USE
This is the vertical separator token that is used to “separate” the display. Since as of January 2021, a unicode token is used; the original ASCII token can be seen in the following comment still.
#
'▏'
- SHOW_TOTAL_ECTS_POINTS_PASSED =
#
SHOW_TOTAL_ECTS_POINTS_PASSED
#
true
Constants inherited
from Base
Base::COMMON_YEAR_DAYS_IN_MONTH, Base::LEFT_PADDING, Base::NAMESPACE, Base::N_CHARACTERS_PER_LINE
Constants included
from Colours
Colours::COLOURS
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#add_proper_year_entry_to_this_line, #already_solved_this_lva_number?, #append_what_into, #available_topics_as_short_name, #average_grade, #bachelor_master_or_diploma, #be_silent, #be_verbose?, #beautiful_url, #change_directory, #cheering_person, #chmod, #cliner, #colour_for_ects_points, #colourize_percentage, #convert_this_array_of_lectures_into_the_full_dataset, #copy, #course_filter, #cpruby, #create_directory, #create_file, #csv_file?, #current_month?, #current_semester?, #datum?, #day_month_year, #debug?, #delete_file, #directory_of_the_exam_topics?, #directory_to_my_exam_topics, #directory_to_the_exam_topics?, #disable_colours, #disable_colours_globally, #do_not_be_verbose, #do_not_use_opn, #do_these_curricula_include_both_a_bachelor_and_a_master_curriculum?, #does_this_line_include_a_german_weekday?, #does_this_line_include_a_html_colour?, #does_this_line_include_an_english_weekday?, #does_this_line_start_with_a_german_weekday?, #e, #ecomment, #editor?, #ee, #egrey, #enable_colours, #enable_colours_globally, #enable_debug, #encoding?, #english_to_german_weekday, #ensure_that_a_base_directory_exists_for_this_file, #ensure_that_the_log_directory_exists, #eparse, #esystem, #etomato, #exit_program, #extract_dd_mm_yyyy, #fetch_this_curriculum, #file_important_exams?, #file_lecture_information?, #file_passed_exams_per_month, #file_read_with_proper_encoding, #filter_away_already_answered_questions, #filter_away_invalid_questions, #filter_for_all_passed_exams, #find_corresponding_exam_topic, #from_curriculum_id_to_university, #german_date_notation, #german_weekday?, #german_weekdays?, #german_weekend_for?, #german_yes_or_no, #has_a_bachelor_and_a_master_curriculum?, #has_a_bachelor_curriculum?, #has_a_master_curriculum?, #has_lva_dates_registered?, #has_this_exam_topic_been_solved?, #has_year_entry?, #hh_mm_ss_dd_mm_yyyy, #horizontal_bar?, #html_log_directory?, #infer_the_namespace, #initialize_the_internal_hash, #internal_hash?, #is_a_master_lecture?, #is_a_registered_curriculum?, #is_a_weekday?, #is_connected_to_the_www?, #is_german_weekday?, #is_on_roebe?, #is_prüfungsimmanent?, #is_this_a_registered_exam_topic?, #is_this_a_valid_html_colour?, #is_this_day_today?, #is_this_lecture_a_practical_course?, #konsole_support?, #last_file?, #lectures_from_indi1, #lectures_from_indi2, #lectures_from_indi3, #lectures_from_indi4, #lectures_from_the_bachelor_genetik_curriculum, #lectures_from_the_individual_vektor_curricula, #left_arrow?, #load_yaml_dataset, #map_input_to_this_curriculum_filename, #move_file, #n_days_difference_from_today_to_this_day, #n_seconds_to_n_days, #namespace?, #no_ext_name, #no_file_exists_at, #number_to_month, #obtain, #obtain_lectures_from_this_curriculum, #open_in_browser, #open_in_editor, #opne, #opnerev, #opnn, #padded_current_month?, #parse_dd_mm_yyyy, #parse_this_line_for_date_entry, #path_to_exam_topic?, #project_yaml_directory?, #rds, #read_dataset_from_a_curriculum_file, #read_in_exam_dataset_from_this_file, #read_this_file_with_default_encoding, #readlines_from_this_input_file, #register_sigint, #remove_empty_strings, #remove_escape_sequences, #remove_internal_comments, #remove_leading_comments, #remove_leading_weekday_names_from, #remove_newlines, #remove_tags_from_this_input, #rename_kde_konsole_tab, #rename_konsole_tab?, #replace_all_html_colours_in_this, #replace_bold_token_with_default_colour, #replace_italic_token_with_default_colour, #replace_italic_token_with_this_colour, #replace_regular_numbers_with_unicode_numbers, #replace_underline_token_with_default_colour, #replace_underline_token_with_this_colour, #require_open_uri, #reset_the_internal_state, #return_all_bachelor_lectures, #return_all_exams_on_this_day, #return_all_numbers_from, #return_all_registered_curricula, #return_all_steop_lectures, #return_current_year, #return_dataset_for_this_topic, #return_dataset_from_this_curriculum_file, #return_dd_mm_yy_and_time_from, #return_directory_for, #return_ects_points_from_these_lectures, #return_either_grey_or_the_custom_colour_for_answers, #return_either_grey_or_the_custom_colour_for_questions, #return_file_for_this_curriculum, #return_german_name_for_this_english_month, #return_german_weekday_of?, #return_hh_mm_ss_from, #return_hour_from_this, #return_lectures_from_bachelor_vektor_curriculum, #return_lectures_with_at_the_least_one_upcoming_exam, #return_local_path_of_this_pwdstud, #return_lva_number_of_this_lecture, #return_month_fitting_to_this_input, #return_n_days_until_monday, #return_n_days_until_sunday, #return_n_exam_questions_in, #return_n_questions_were_answered_for_this_topic, #return_name_of_the_weekday, #return_name_of_this_curriculum, #return_name_of_this_curriculum_based_on_its_id_number, #return_opnn, #return_passed_courses, #return_pwd, #return_random_curriculum, #return_sanitized_dataset_from_the_file_lecture_information, #return_solved_lectures, #return_steop_lectures, #return_the_remote_homepage_url, #return_this_line_has_n_characters_as_html_colour_tags, #return_title_from_this_curriculum_file, #right_arrow?, #rinstall2, #roebe_exam_directory?, #roebe_path_to_file_lecture_information?, #ruby_src_dir_at_home?, #sanitize_this_topic, #sanitize_url, #select_for_prüfungsimmanente_LVs, #select_lectures_with_this_key, #set_be_verbose, #set_this_cd_alias_to, #set_xorg_buffer, #sfancy, #shall_we_make_use_of_unicode_symbols?, #show_todays_date, #silently_open_in_browser, #simp, #sort_these_lecture_names_by_time, #spacer, #studium_log_dir?, #this_month_has_n_days?, #total_ects_points_passed, #translate_dd_mm_yyyy_to_weekday, #try_to_require_html_templates, #try_to_require_the_open_gem, #try_to_require_the_rcfiles, #try_to_require_the_verbose_truth_gem, #turn_this_array_into_the_full_dataset, #unicode_blocks_line, #use_colours?, #use_opn?, #web_liner, #weekday?, #weekdays?, #word_wrap, #write_what_into, #www_connection_is_unavailable, #yaml_dir?, #yellowrev, #yes_or_no
#commandline?, #runmode?, #set_commandline_mode, #set_runmode, #set_www_mode, #www_mode?
#commandline_arguments?, #commandline_arguments_joined, #commandline_arguments_with_hyphens?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_non_hyphen_argument?, #reset_the_commandline_arguments, #set_commandline_arguments, #set_first_argument
#aquamarine, #blanchedalmond, #brown, #cadetblue, #chocolate, #coral, #cornflowerblue, #crimson, #cyan, #darkblue, #darkcyan, #darkgoldenrod, #darkgreen, #darkkhaki, #darkolivegreen, #darkorange, #darkred, #darkseagreen, #darkslateblue, #darkslategray, #darkturquoise, #deepskyblue, #firebrick, #forestgreen, #gold, #goldenrod, #green, #grey, #indianred, #khaki, #lavender, #lawngreen, #lightblue, #lightcoral, #lightgreen, #lightred, #lightseagreen, #lightskyblue, #lightslategray, #lightslategrey, #lime, #limegreen, #mediumaquamarine, #mediumblue, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mediumvioletred, #mintcream, #moccasin, #oldlace, #olive, #olivedrab, #orange, #orangered, #orchid, #palegoldenrod, #palegreen, #paleturquoise, #palevioletred, #peru, #plum, #powderblue, #red, #rosybrown, #royalblue, #saddlebrown, #salmon, #sandybrown, #seagreen, #sienna, #silver, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #tan, #teal, #thistle, #tomato, #turquoise, #violet, #whitesmoke, #yellow, #yellowgreen
Methods included from Colours
#bold_blue, #bold_red, #bold_yellow, cadetblue, #cadetblue, #chartreuse, #coral, coral, #cornflowerblue, cornflowerblue, crimson, #cyan, cyan, darkgoldenrod, #darkgoldenrod, #darkgray, darkgreen, darkolivegreen, darkseagreen, #darkslateblue, darkslateblue, #darkslategray, darkslategray, #darkturquoise, darkturquoise, #deepskyblue, deepskyblue, default_colour, #dimgray, disable_colours, #dodgerblue, e, #efancy, enable_colours, #erev, #ewarn, #forestgreen, forestgreen, gold, #goldenrod, goldenrod, #grey, grey, indianred, #indianred, khaki, #khaki, lawngreen, #lawngreen, lightblue, lightgreen, lightsalmon, #lightseagreen, lightseagreen, lightskyblue, #lightskyblue, #lightslategray, lightslategray, #lightsteelblue, lime, #lime, limegreen, #limegreen, #mediumaquamarine, mediumaquamarine, #mediumorchid, #mediumpurple, mediumpurple, #mediumseagreen, mediumseagreen, #mediumslateblue, mediumslateblue, #mediumspringgreen, mediumspringgreen, #mediumturquoise, mediumturquoise, #oldlace, olive, #olive, olivedrab, #olivedrab, orange, orangered, #orchid, orchid, palegreen, #palegreen, paleturquoise, #paleturquoise, palevioletred, #papayawhip, peru, #peru, plum, #plum, #powderblue, powderblue, rev, #rev?, royalblue, saddlebrown, #saddlebrown, #sandybrown, sandybrown, sdir, #sdir, seagreen, #seagreen, sfancy, #sfancy, sfile, #sfile, #simp, simp, #skyblue, skyblue, slateblue, #slategray, slategray, springgreen, #springgreen, #steelblue, steelblue, #swarn, swarn, #tan, tan, teal, #teal, #tomato, tomato, turquoise, use_colours?, use_this_colour_for_exam_answers, use_this_colour_for_exam_questions, #yellow, yellowgreen, #yellowgreen
Constructor Details
#initialize(i = nil, run_already = true, &block) ⇒ ShowUpcomingExams
#
initialize
The first argument will keep track of the commandline-input.
The input to this method should also handle blocks given, such as:
Studium::ShowUpcomingExams.new { :disable_colours }
#
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 121
def initialize(
i = nil,
run_already = true,
&block
)
reset
case i
when :be_silent,
:do_not_report_anything
be_silent
i = nil
@report_result = false
when :do_not_report_anything_and_do_not_update_the_cd_aliases
be_silent
i = nil
@report_result = false
@internal_hash[:shall_we_update_the_cd_aliases_with_new_exam_entries] = false
end
set_input(i)
if block_given?
yielded = yield
if yielded.is_a? Hash
if yielded.has_key? :show_n_upcoming_exams
set_show_n_upcoming_exams(
yielded.delete(:show_n_upcoming_exams)
)
elsif yielded.has_key? :show_n_exams
set_show_n_upcoming_exams(
yielded.fetch(:show_n_exams)
)
end
if yielded.has_key? :array_of_symbols
array_of_symbols.each {|this_symbol|
case this_symbol
when :do_not_exit
set_do_not_exit(false)
else
e 'Unhandled symbol: :'+this_symbol.to_s
end
}
end
else
case yielded when :do_not_exit
set_do_not_exit(false)
when :disable_colours,
:no_colours
no_colours
end
end
end
if i.is_a? Symbol
case i
when :do_not_report_anything
do_not_report_anything
end
end
case run_already
when :dont_run_yet,
:do_not_run_yet
run_already = false
end
run if run_already
end
|
Class Method Details
.[](i = ARGV, &block) ⇒ Object
#
Studium::ShowUpcomingExams[]
#
1336
1337
1338
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 1336
def self.[](i = ARGV, &block)
new(i, &block)
end
|
.next_exam? ⇒ Boolean
#
Studium::ShowUpcomingExams.next_exam?
This class-method will always tell us which exam will come next.
This method will return an Array, such as:
["500157 Populationsgenetik", {:ects=>1.5, :sws=>1.5,
The first entry is the LVA-id and the name of the course; then comes the Hash with the data, exactly as it is stored in the file called ‘lecture_information.yml’.
#
976
977
978
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 976
def self.next_exam?
new(:be_silent).result?.first
end
|
.return_all_registered_upcoming_exams(&block) ⇒ Object
#
Studium::ShowUpcomingExams.return_all_registered_upcoming_exams
Return all upcoming exams, without limitation, as an Array. This Array can then be used, for example, in a GUI where it is displayed to the user.
Usage example:
dataset = Studium::ShowUpcomingExams.return_all_registered_upcoming_exams
#
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 1311
def self.return_all_registered_upcoming_exams(&block)
result = Studium::ShowUpcomingExams.new(
:do_not_report_anything_and_do_not_update_the_cd_aliases
).result?
if block_given?
yielded = yield
case yielded
when :only_for_registered_exams
result = result.select {|a, b|
b.has_key?('registered')
}
end
end
return result
end
|
Instance Method Details
#colourize_and_return_the_beginning_of_the_month(i) ⇒ Object
#
colourize_and_return_the_beginning_of_the_month
This method must colourize a String such as:
"[Beginn Oktober 2023] ☻ ----------------------------------------------------"
#
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 845
def colourize_and_return_the_beginning_of_the_month(i)
i = i.dup
i.gsub!(/-/, tomato('-'))
if i.include?('☻')
i.sub!(/☻/, gold('☻'))
end
i.gsub!(/(\d{4})/, darkgoldenrod('\1'))
i.sub!(/(\[Beginn (.+))/, saddlebrown('\1'))
i.sub!(/\]/, saddlebrown(']'))
if i.include? 'ECTS' i.sub!(
/(\[\^\^\^ \d{1,3}\.\d{1} ECTS\])/,
colourize_ects_points('\1')
)
end
return i
end
|
#colourize_ects_points(i) ⇒ Object
#
colourize_ects_points
#
716
717
718
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 716
def colourize_ects_points(i)
lightgreen(i)
end
|
#consider_autogenerating_exam_aliases(use_this_file = Studium.file_all_registered_upcoming_exams) ⇒ Object
#
consider_autogenerating_exam_aliases
This method will autogenerate the proper cd_aliases entries.
It will only do so if these three conditions are met:
(1) the target system is a "roebe-system"
(2) a new entry has been added or removed in the file
'lecture_information.yml'
(3) a file exists as specified by the constant
FILE_ALL_REGISTERED_UPCOMING_EXAMS
#
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 224
def consider_autogenerating_exam_aliases(
use_this_file =
Studium.file_all_registered_upcoming_exams )
if is_on_roebe? and commandline_mode? if File.exist? use_this_file
existing_dataset = YAML.load_file(use_this_file)
_ = ::Studium.return_sanitized_dataset_from_the_file_lecture_information.select {|a, b|
b.has_key?('registered') or
b.has_key?('not_yet_registered')
}
array = _.map {|name_of_the_lecture, inner_hash|
if inner_hash.has_key? 'registered'
entry = inner_hash['registered']
elsif inner_hash.has_key? 'not_yet_registered'
entry = inner_hash['not_yet_registered']
end
entry = entry.first
entry
}
array = array.sort_by {|line|
line = line.split(',').first if line.include? ','
line = remove_weekdays(line)
Time.parse(line)
}
existing_dataset = existing_dataset.sort_by {|line|
line = line.split(',').first if line.include? ','
line = remove_weekdays(line)
Time.parse(line)
}
if (array == existing_dataset)
else
if @internal_hash[:shall_we_update_the_cd_aliases_with_new_exam_entries]
update_the_cd_aliases_with_new_exam_entries
end
end
end
end
end
|
#consider_renaming_the_konsole_tab(use_this_namespace = :Roebe) ⇒ Object
#
consider_renaming_the_konsole_tab
We should actually check whether we are using Kde Konsole or not.
We will then run system ‘clear’, but only if we have enabled reporting.
#
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 756
def consider_renaming_the_konsole_tab(
use_this_namespace = :Roebe
)
if report_result? and
konsole_support?
begin
require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
rescue LoadError; end
if Object.const_defined? use_this_namespace
e Roebe.return_important_notification("Next #{n_exams?} exams")
system 'clear' end
end
end
|
#create_the_auto_stud_aliases(shall_we_exit = shall_we_exit?,
, be_verbose = true) ⇒ Object
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 317
def create_the_auto_stud_aliases(
shall_we_exit = shall_we_exit?,
be_verbose = true
)
case be_verbose
when :be_quiet
be_verbose = false
end
case shall_we_exit
when :do_not_exit
shall_we_exit = false
end
base_dir = ROEBE_STUDIUM_DIR.dup
index = 0
@dataset.each {|name_of_the_lecture, inner_hash| index += 1
name_of_the_lecture = name_of_the_lecture.tr(' ','_')
name_of_the_lecture.delete!(':/(),') if name_of_the_lecture.end_with? '.'
name_of_the_lecture.chop!
end
if name_of_the_lecture.include? '_-_'
name_of_the_lecture.gsub!(/_-_/,'_')
end
if name_of_the_lecture.include? '_+_' name_of_the_lecture.gsub!(/_\+_/,'_')
end
if name_of_the_lecture.include? '__'
name_of_the_lecture.squeeze!('_')
end
university = inner_hash[:university].dup
case university
when /^vetmed$/i
university = 'VETMED_UNI'
when 'tu_vienna','TU_VIENNA','TU Vienna'
university = 'TU_WIEN'
when 'meduni','MEDUNI','Meduni',
'boku','BOKU'
university << '_WIEN'
end
target_dir = base_dir+university.upcase.tr(' ','_')+'/'.dup
target_dir << name_of_the_lecture
pwdstud_name = "pwdstud#{index}:"
if be_verbose
opne rev+'Settting alias '+
simp(pwdstud_name.to_s.rjust(10))+
rev+' pointing to the directory '+
sdir(target_dir)
end
set_this_cd_alias_to(
pwdstud_name,
target_dir,
:be_quiet )
begin
if is_on_roebe?
opne 'Autogenerating the cd-aliases next.'
end
require 'rcfiles'
Rcfiles.generate_files(:cd_aliases) {{ be_verbose: be_verbose? }}
rescue LoadError; end
}
exit if shall_we_exit
end
|
#dataset? ⇒ Boolean
Also known as:
result?
805
806
807
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 805
def dataset?
@dataset
end
|
#display_total_ects ⇒ Object
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 620
def display_total_ects
if SHOW_TOTAL_ECTS_POINTS_PASSED
total_n_ects = @dataset.select {|a, b|
b[:ects]
}.map {|a,b|
b[:ects]
}.sum.to_s
plus = "+#{total_n_ects}"
e
result = ((' ' * 60)+
limegreen('Total ECTS passed so far: ').to_s+
colourize_ects_points(::Studium.n_ects_passed_so_far).to_s).dup
if @emoji_checkbox and !@emoji_checkbox.empty?
result << goldenrod(' '+@emoji_checkbox+' ... ← registered for that course')
end
e result
result = ((' ' * 59).to_s+
limegreen('ECTS of the above exams: ')+
colourize_ects_points(plus)).dup
if @warning_sign and !@warning_sign.empty? result << crimson(" #{@warning_sign} ... ← outdated course exam-registration")
end
e result
end
end
|
#do_not_report_anything ⇒ Object
#
do_not_report_anything
#
558
559
560
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 558
def do_not_report_anything
@report_result = false
end
|
#do_show_only_exams_for_which_we_are_registered ⇒ Object
#
do_show_only_exams_for_which_we_are_registered
#
511
512
513
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 511
def do_show_only_exams_for_which_we_are_registered
@internal_hash[:show_only_exams_for_which_we_are_registered] = true
end
|
#in_n_days(i) ⇒ Object
667
668
669
670
671
672
673
674
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 667
def in_n_days(i)
if i.include? '-'
i = i.split('-').first
end
future_time = Time.parse(i).to_i - Time.now.to_i
result = future_time.to_f / ONE_DAY.to_f
result.ceil(1)
end
|
541
542
543
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 541
def input?
@input
end
|
#is_part_of_the_vector_curriculum?(i = '') ⇒ Boolean
#
is_part_of_the_vector_curriculum?
This checks whether the lecture at hand is part of the individual Vector-Curriculum.
#
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 417
def (
i = @input
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /^-?-?only(-|_)?registered$/
do_show_only_exams_for_which_we_are_registered
when /^-?-?auto(-|_)?stud$/
create_the_auto_stud_aliases
when /^-?-?be(_|-)?silent$/i
do_not_report_anything
when /^-?-?disable(_|-)?colours$/,
/^-?-?no(_|-)?colours$/
@use_colours = false
when /^-?-?help$/
show_help
exit
else
if i.to_s =~ /^(\d+)$/ set_show_n_upcoming_exams($1.to_s.dup) end
end
end
end
|
#n_exams? ⇒ Boolean
649
650
651
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 649
def n_exams?
@dataset.size
end
|
#n_ljust_to_the_left? ⇒ Boolean
Also known as:
left_pad?
812
813
814
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 812
def n_ljust_to_the_left?
@internal_hash[:n_ljust_to_the_left]
end
|
#parse_time_entry_from_this_string(the_exam_will_happen_when) ⇒ Object
#
parse_time_entry_from_this_string
#
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 777
def parse_time_entry_from_this_string(
the_exam_will_happen_when
)
return if the_exam_will_happen_when.empty?
sanitized_the_exam_will_happen_when = remove_german_weekdays(the_exam_will_happen_when).strip
sanitized_the_exam_will_happen_when =~ REGEX_TO_EXTRACT_DATE_AND_TIME_FROM_AN_UPCOMING_EXAM
this_time = $1.to_s.dup
begin
this_time = Time.parse(this_time) rescue Exception => error
e 'The original input to the method parse_time_entry_from_this_string() was:'
e
e " #{sfancy(the_exam_will_happen_when)}"
e
pp error
e
e 'The caller() stack was:'
e
pp caller()
e
exit
end
return this_time
end
|
#report ⇒ Object
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 1005
def report
_ = dataset?
if _.empty?
opne 'You have not registered for any upcoming exams.'
else
left_pad = left_pad?
current_month = month?
if show_only_exams_for_which_we_are_registered?
_.select! {|name_of_the_course, inner_hash|
inner_hash.has_key?('registered')
}
end
index = 0
case show_n_upcoming_exams?
when :all_of_them
else
if show_n_upcoming_exams?.to_s =~ /^(\d+)$/
n_exams_to_show = $1.to_s.dup.to_i
_ = _[0 .. (n_exams_to_show - 1)]
end
end
e
report_today(_.size) n_ects_in_this_month = 0 today_is = ::Time.now
_.each {|name_of_the_lecture, inner_hash| index += 1
unless SHOW_LEADING_LVA_ID_NUMBER
splitted = name_of_the_lecture.split(' ')
name_of_the_lecture = splitted[1 .. -1].join(' ').strip
end
use_this_as_ljust_value = left_pad
new_line_index = 10 all_exams = inner_hash['exams']
next_exam_date = ::Studium.return_next_exam_date(all_exams)
next_exam_date_as_time_object = ::Time.parse(next_exam_date)
this_line = ''.dup n_ects_points = inner_hash[:ects] priority_of_the_lecture = inner_hash[:priority]
if inner_hash.has_key? 'registered'
the_exam_will_happen_when = inner_hash['registered'].first
else the_exam_will_happen_when = inner_hash['not_yet_registered'].first
end the_location = return_location( the_exam_will_happen_when.delete("\t")
).lstrip
date_of_the_exam = return_date_of_the_exam(the_exam_will_happen_when)
german_weekday = german_weekday?(date_of_the_exam).ljust(11) if DISPLAY_HORIZONTAL_BAR_TO_INDICATE_A_NEW_MONTH and @report_result
actual_month = date_of_the_exam.scan(/\d{1,2}\.(\d{1,2})\.\d{4}/).flatten
if actual_month == current_month
else
current_month = actual_month.dup
show_horizontal_bar(current_month) {{ n_ects_points_in_this_month: n_ects_in_this_month }}
if n_ects_in_this_month > 0
n_ects_in_this_month = 0
end
end
end
n_ects_in_this_month += n_ects_points
colourized_german_weekday = mediumpurple(german_weekday)
startzeit = return_startzeit_from(the_exam_will_happen_when).strip.dup
colourized_startzeit = royalblue('Startzeit: ')+
steelblue(startzeit)+rev
the_exam_will_happen_in_n_days = in_n_days(date_of_the_exam+' '+startzeit.to_s)
colourized_and_padded_index = (' ' * (3 - index.to_s.size ))
use_this_as_leading_padding = ' ' if next_exam_date_as_time_object < today_is
use_this_as_leading_padding = ''.dup
if index > 9
use_this_as_leading_padding << ' '
use_this_as_ljust_value -= 1
else
new_line_index -= 1
end
use_this_as_leading_padding << crimson(@warning_sign) use_this_as_leading_padding << ' '
use_this_as_ljust_value += 1
elsif inner_hash.has_key? 'registered' use_this_as_leading_padding = ' '+goldenrod(@emoji_checkbox)+' '
end
colourized_and_padded_index << use_this_as_leading_padding+
orange('(')+
goldenrod(index.to_s)+
orange(') ')
this_line << colourized_and_padded_index
copy_of_the_lecture_name = name_of_the_lecture.dup
if copy_of_the_lecture_name.size > 62
copy_of_the_lecture_name = copy_of_the_lecture_name[0 .. 58]+
' [...] '
end
if inner_hash.has_key? 'not_yet_registered'
unless copy_of_the_lecture_name.size + 34 >= use_this_as_ljust_value copy_of_the_lecture_name << ' ← [TODO: register for this exam]' end
end
copy_of_the_lecture_name = copy_of_the_lecture_name.ljust(use_this_as_ljust_value, ' ')
if inner_hash.has_key? 'registered'
copy_of_the_lecture_name = lightgreen(copy_of_the_lecture_name)
else if priority_of_the_lecture == 1
copy_of_the_lecture_name = olivedrab(copy_of_the_lecture_name)
else
copy_of_the_lecture_name = darkolivegreen(copy_of_the_lecture_name)
end
end
if copy_of_the_lecture_name.include?(' ← [TODO: register for this exam]')
copy_of_the_lecture_name.sub!(
/ ← \[TODO: register for this exam\]/,
rev+indianred(' ← [TODO: register for this exam]')
)
end
this_line << copy_of_the_lecture_name
this_line << " #{return_red_vertical_bar} "
this_line << colourized_german_weekday this_line << " #{mediumorchid(next_exam_date)}"
this_line << " #{return_red_vertical_bar}"
if the_exam_will_happen_in_n_days < 0.5 colourized_in_n_days = crimson('[ HEUTE ] ')
else
colourized_in_n_days = skyblue('[+ ')+
orangered(
the_exam_will_happen_in_n_days.to_s.rjust(4)
)+
skyblue(' days] ')
end
this_line << "#{colourized_in_n_days}"
this_line << colourized_startzeit
if @report_result
e this_line end
if @report_result
sanitized_the_location = the_location.dup
if sanitized_the_location.size > 49
sanitized_the_location = word_wrap(sanitized_the_location, 49)
end
if sanitized_the_location.include? "\n"
sanitized_the_location = sanitized_the_location.split("\n")
else
sanitized_the_location = [sanitized_the_location]
end
sanitized_the_location.map! {|entry|
entry.strip!
entry = entry.prepend(
(
(' ' * (use_this_as_ljust_value+new_line_index))
)+'|'+(' ' * 14)
)
entry }
joined_location = sanitized_the_location.join("\n").dup
if TRY_TO_SHOW_PRIORITIES_FOR_THE_LECTURES
joined_location << ' Priorität: '+priority_of_the_lecture.to_s end
joined_location << ' ('+n_ects_points.to_s+' ECTS)' if joined_location.include?(':')
joined_location.sub!(
/:/, " #{RIGHT_ARROW}"
)
end
if joined_location.include?('|')
joined_location.gsub!(/\|/, vertical_bar?)
end
if joined_location.include?('Priorität')
array = [] splitted = joined_location.split('Priorität')
array << 'Priorität'+splitted.last
splitted = splitted.first
splitted = splitted.split('→')
array.prepend splitted.last
array.prepend splitted.first
array[2] = limegreen(array[2])
if array[1].include? vertical_bar?
splitted = array[1].split(vertical_bar?)
splitted[0] = slategray(" #{splitted[0].lstrip}")
splitted[1] = slategray(splitted[1])
splitted = splitted.join(swarn(vertical_bar?))
array[1] = splitted
else
array[1] = slategray(array[1])
end
if array[0].include?(vertical_bar?)
splitted = array[0].split(vertical_bar?)
splitted[1] = paleturquoise(splitted[1]) array[0] = splitted[0] + swarn(vertical_bar?) + splitted[1]
else
array[0] = paleturquoise(array[0])
end
joined_location = array[0] + swarn('→')+
array[1] + array[2]
end
e joined_location
end
}
if @report_result
display_total_ects
e
end
end
end
|
#report_result? ⇒ Boolean
709
710
711
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 709
def report_result?
@report_result
end
|
#report_today(show_n_exams = show_n_exams?
) ⇒ Object
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 819
def report_today(
show_n_exams = show_n_exams?
)
if @report_result
opne yellowgreen('Heute ist der ')+
sfancy(dd_mm_yyyy)+' '+
yellowgreen('(')+
lightgreen(
german_weekday?(dd_mm_yyyy)
)+
yellowgreen('). Die nächsten ')+
lightslategray(show_n_exams.to_s)+
yellowgreen(' Prüfungen sind: ')
e
end
end
|
#reset ⇒ Object
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 464
def reset
super()
infer_the_namespace
@internal_hash[:shall_we_exit] = true
@report_result = true
@show_n_upcoming_exams = :all_of_them
@dataset_from_file_lecture_information =
return_dataset_from_file_lecture_information
@internal_hash[:show_only_exams_for_which_we_are_registered] = false
@internal_hash[:n_ljust_to_the_left] = 66
@internal_hash[:shall_we_update_the_cd_aliases_with_new_exam_entries] = true
sanitize_dataset
if Object.const_defined?(:EmojiParadise)
@emoji_checkbox = EmojiParadise.return_checkbox
@warning_sign = EmojiParadise.warning_sign
else
@emoji_checkbox = ''
@warning_sign = ''
end
end
|
#return_date_of_the_exam(i) ⇒ Object
#
return_date_of_the_exam
This method will extract dd.mm.yyyy.
#
658
659
660
661
662
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 658
def return_date_of_the_exam(i)
i.scan(
/(\d{1,2}\.\d{1,2}\.\d{4})/
).flatten.first
end
|
#return_location(i) ⇒ Object
#
return_location (ort tag)
This method will return a String, depending on whether the substring ‘Ort’ is part of the given input or whether it is not.
#
726
727
728
729
730
731
732
733
734
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 726
def return_location(i)
if i.include? 'Ort'
scan_result = i.scan(/(Ort: .+)$/).flatten
scan_result = scan_result.first if scan_result.respond_to?(:first)
" #{scan_result}"
else
'(No specific Ort has been found - or is known)'
end
end
|
#return_red_vertical_bar ⇒ Object
Also known as:
return_vertical_bar
#
return_red_vertical_bar
Note that this will have the proper colour already.
#
681
682
683
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 681
def return_red_vertical_bar
"#{short_vertical_bar} "
end
|
#return_smiley_face ⇒ Object
936
937
938
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 936
def return_smiley_face
Roebe.black_smiling_face
end
|
#return_startzeit_from(i) ⇒ Object
#
return_startzeit_from
#
611
612
613
614
615
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 611
def return_startzeit_from(i)
return i.scan(
/\d{1,2}:\d{1,2}-\d{1,2}:\d{1,2}/ ).flatten.first
end
|
#run ⇒ Object
994
995
996
997
998
999
1000
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 994
def run
consider_renaming_the_konsole_tab
consider_autogenerating_exam_aliases
report
store_old_upcoming_exams end
|
#sanitize_dataset ⇒ Object
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 943
def sanitize_dataset
@dataset = @dataset_from_file_lecture_information.select {|name, inner_hash|
if inner_hash.nil?
e "#{rev}Some erroneous entry for `#{tomato(name)}#{rev}`."
end
inner_hash.has_key?('registered') or
inner_hash.has_key?('not_yet_registered')
}
sort_dataset_by_time
end
|
#set_do_not_exit(i = true) ⇒ Object
534
535
536
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 534
def set_do_not_exit(i = true)
@internal_hash[:shall_we_exit] = i
end
|
525
526
527
528
529
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 525
def set_input(i = '')
i = i.first if i.is_a? Array
i = i.to_s.dup
@input = i
end
|
#set_show_n_upcoming_exams(i = :all_of_them) ⇒ Object
#
set_show_n_upcoming_exams
#
548
549
550
551
552
553
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 548
def set_show_n_upcoming_exams(
i = :all_of_them
)
i = i.to_i if i.is_a? String
@show_n_upcoming_exams = i
end
|
#shall_we_exit? ⇒ Boolean
305
306
307
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 305
def shall_we_exit?
@internal_hash[:shall_we_exit]
end
|
#short_vertical_bar ⇒ Object
695
696
697
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 695
def short_vertical_bar
swarn(SEPARATOR_TOKEN_TO_USE)
end
|
#show_help ⇒ Object
400
401
402
403
404
405
406
407
408
409
410
411
412
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 400
def show_help
help_string = <<-EOF
Input a number n, which means to show n upcoming exams.
Other documented help options are:
--autostud # automatically set the proper
# cd-alias for all upcoming exams
EOF
e help_string
end
|
#show_horizontal_bar(optional_this_month = nil, current_year = current_year?
) ⇒ Object
#
show_horizontal_bar
This will show a red, horizontal bar - or, alternatively, also the name of the month at hand.
#
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 869
def show_horizontal_bar(
optional_this_month = nil,
current_year = current_year?
)
if optional_this_month
if optional_this_month.is_a? Array
optional_this_month = optional_this_month.first
end
optional_this_month = number_to_month(optional_this_month)
end
if optional_this_month
the_left_string = ''.dup
the_left_string << '[Beginn '+
"#{to_german_month(optional_this_month)} #{current_year}"+
']'
if use_unicode_symbols?
the_left_string << " #{return_smiley_face}"
end
if block_given?
yielded = yield
if yielded.is_a? Hash
if yielded.has_key? :n_ects_points_in_this_month
n_ects_points = yielded[:n_ects_points_in_this_month]
if n_ects_points > 0
n_ects_points_string = " [^^^ #{n_ects_points} ECTS] "
the_left_string << n_ects_points_string
end
end
end
end
the_left_string = the_left_string.ljust(
@internal_hash[:n_ljust_to_the_left]+9, '-' )
the_left_string = colourize_and_return_the_beginning_of_the_month(the_left_string)
the_left_string << short_vertical_bar+
palegreen(' [Datum] ')+
swarn('-'*1)+
tomato(' ⌛')+
swarn('-'*48)+
"\n"
e tomato('-')+the_left_string
end
end
|
#show_n_upcoming_exams? ⇒ Boolean
Also known as:
show_n_exams?
#
show_n_upcoming_exams?
#
702
703
704
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 702
def show_n_upcoming_exams?
@show_n_upcoming_exams
end
|
#show_only_exams_for_which_we_are_registered? ⇒ Boolean
#
show_only_exams_for_which_we_are_registered?
#
518
519
520
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 518
def show_only_exams_for_which_we_are_registered?
@internal_hash[:show_only_exams_for_which_we_are_registered]
end
|
#sort_dataset_by_time ⇒ Object
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 565
def sort_dataset_by_time
@dataset = @dataset.sort_by {|name_of_the_lecture, inner_hash|
if inner_hash.has_key? 'registered'
if inner_hash['registered'].respond_to? :first
the_exam_will_happen_when = inner_hash['registered'].first
else
opne crimson(name_of_the_lecture)+' has no key called `'+
sfancy('registered')+'`.'
opne swarn('Please fix this error before we can continue.')
exit
end
else
the_exam_will_happen_when = inner_hash['not_yet_registered']
if the_exam_will_happen_when and
the_exam_will_happen_when.respond_to?(:first)
the_exam_will_happen_when = the_exam_will_happen_when.first
else
opnn; ewarn 'No dataset found for the key '+
slateblue('not_yet_registered')
opnn; ewarn 'This may be because you forgot to add '\
'a " -" entry for this key.'
opnn; ewarn 'Please correct this error. '\
'Exiting now until this error has been resolved.'
exit
end
end
result = parse_time_entry_from_this_string(the_exam_will_happen_when)
if result.nil?
e 'A problem was encountered for this lecture: '+name_of_the_lecture.to_s
e 'This should be corrected.'
exit
end
result
}
end
|
#store_old_upcoming_exams ⇒ Object
#
store_old_upcoming_exams
This method will store the old upcoming exams. It will always trigger the storing-routine, so if you need to make additional checks, do so before calling that method.
#
#update_the_cd_aliases_with_new_exam_entries ⇒ Object
#
update_the_cd_aliases_with_new_exam_entries
This will do a semi-silent update.
#
295
296
297
298
299
300
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 295
def update_the_cd_aliases_with_new_exam_entries
opne "Updating the #{gold('cd-aliases')} next - this "\
"may take a few seconds."
create_the_auto_stud_aliases(:do_not_exit, :be_quiet)
system 'history -c'
end
|
#vertical_bar? ⇒ Boolean
688
689
690
|
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 688
def vertical_bar?
SEPARATOR_TOKEN_TO_USE
end
|