Class: Studium::ShowUpcomingExams

Inherits:
Base
  • Object
show all
Defined in:
lib/studium/exams/show_upcoming_exams/reset.rb,
lib/studium/exams/show_upcoming_exams/run.rb,
lib/studium/exams/show_upcoming_exams/help.rb,
lib/studium/exams/show_upcoming_exams/menu.rb,
lib/studium/exams/show_upcoming_exams/report.rb,
lib/studium/exams/show_upcoming_exams/constants.rb,
lib/studium/exams/show_upcoming_exams/initialize.rb,
lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb,
lib/studium/exams/show_upcoming_exams/consider_autogenerating_exam_aliases.rb

Overview

Studium::ShowUpcomingExams

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
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.

#
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 =
#

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::ARRAY_HTML_COLOURS_IN_USE, Base::CHECK_FOR_INCORRECT_ENTRIES_IN_THE_QUESTION_ANSWER_FILE_THAT_SHOULD_BE_COMMENTS, Base::COLOURS, Base::COMMON_YEAR_DAYS_IN_MONTH, Base::GRAY, Base::LEFT_PADDING, Base::N_CHARACTERS_PER_LINE, Base::UNICODE_RIGHT_ARROW

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, #base_dir?, #be_silent, #be_verbose?, #beautiful_url, #change_directory, #cheering_person, #cliner, #colour_for_ects_points, #colourize_percentage, #commandline_arguments?, #commandline_arguments_joined, #commandline_arguments_with_hyphens?, #convert_this_array_of_lectures_into_the_full_dataset, #copy, #cpruby, #create_directory, #create_file, #csv_file?, #current_month?, #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?, #e, #ecomment, #editor?, #ee, #enable_colours, #enable_colours_globally, #enable_debug, #encoding?, #english_to_german_weekday, #ensure_main_encoding, #ensure_that_the_log_directory_exists, #eparse, #erev, #esystem, #etomato, #exit_program, #expand_topic, #extract_dd_mm_yyyy, #file_lecture_information?, #file_read_with_proper_encoding, #filter_away_invalid_questions, #find_corresponding_exam_topic, #first_argument?, #first_non_hyphen_argument?, #from_curriculum_id_to_university, #german_date_notation, #german_weekday?, #german_weekdays?, #has_a_bachelor_curriculum?, #has_a_master_curriculum?, #has_this_exam_topic_been_solved?, #has_year_entry?, #hh_mm_ss_dd_mm_yyyy, #horizontal_bar?, #html_log_directory?, #is_a_master_lecture?, #is_a_weekday?, #is_connected_to_the_www?, #is_on_roebe?, #is_prüfungsimmanent?, #is_this_a_valid_html_colour?, #is_this_day_today?, #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, #load_yaml_dataset, #move_file, #n_days_difference_from_today_to_this_day, #no_ext_name, #no_file_at, #number_to_month, #obtain, #obtain_lectures_from_this_curriculum, #open_in_editor, #opnn, #path_to_exam_topic?, #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, #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, #rev, #right_arrow?, #rinstall2, #roebe_exam_directory?, #ruby_src_dir_at_home?, #runmode?, #sanitize_this_topic, #sanitize_url, #select_lectures_with_this_key, #set_be_quiet, #set_be_verbose, #set_commandline_arguments, #set_commandline_mode, #set_runmode, #set_this_cd_alias_to, #set_www_mode, #sfancy, #shall_we_make_use_of_unicode_symbols?, #show_todays_date, #simp, #sort_these_lecture_names_by_time, #spacer, #swarn, #this_month_has_n_days?, #total_ects_points_passed, #translate_dd_mm_yyyy_to_weekday, #try_to_require_the_rcfiles, #turn_this_array_into_the_full_dataset, #unicode_blocks_line, #use_colours?, #use_opn?, #vertical_bar?, #web_liner, #weekday?, #weekdays?, #word_wrap, #write_what_into, #www_connection_is_unavailable, #www_mode?, #yaml_dir?

Methods included from Colours

#bold_blue, #bold_red, #bold_yellow, #cadetblue, #chartreuse, crimson, #darkgray, darkgreen, darkseagreen, deepskyblue, #deepskyblue, default_colour, #dimgray, disable_colours, #dodgerblue, e, #efancy, enable_colours, #ewarn, #forestgreen, gold, #grey, lightblue, lightgreen, #lightslategray, #lightsteelblue, #mediumorchid, #mediumseagreen, #oldlace, #olivedrab, orange, orangered, #orchid, palevioletred, #papayawhip, rev, royalblue, sdir, #sdir, sfancy, #sfancy, sfile, #sfile, simp, #simp, slateblue, steelblue, #steelblue, #swarn, swarn, #teal, turquoise, use_colours?, use_this_colour_for_exam_answers, use_this_colour_for_exam_questions, #yellow

Constructor Details

#initialize(i = nil, run_already = true) ⇒ 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 }
#


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/studium/exams/show_upcoming_exams/initialize.rb', line 19

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  case i
  when :be_silent,
       :do_not_report_anything
    be_silent
    i = nil
    @report_result = false
  end
  set_input(i)
  # ======================================================================= #
  # === Handle blocks next
  #
  # Next handle blocks given to the initializer:
  # ======================================================================= #
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      # =================================================================== #
      # === :show_n_upcoming_exams
      # =================================================================== #
      if yielded.has_key? :show_n_upcoming_exams
        set_show_n_upcoming_exams(
          yielded.delete(:show_n_upcoming_exams)
        )
      # =================================================================== #
      # === :show_n_exams
      # =================================================================== #
      elsif yielded.has_key? :show_n_exams
        set_show_n_upcoming_exams(
          yielded.fetch(:show_n_exams)
        )
      end
    else
      case yielded # case tag
      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 = '', &block) ⇒ Object

#

Studium::ShowUpcomingExams[]

#


419
420
421
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 419

def self.[](i = '', &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'.

#

Returns:

  • (Boolean)


395
396
397
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 395

def self.next_exam?
  new(:be_silent).result?.first
end

.return_all_registered_upcoming_examsObject

#

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
#


411
412
413
414
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 411

def self.return_all_registered_upcoming_exams
  result = Studium::ShowUpcomingExams.new(:do_not_report_anything).result?
  return result
end

Instance Method Details

#colourize_ects_points(i) ⇒ Object

#

colourize_ects_points

#


242
243
244
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 242

def colourize_ects_points(i)
  lightgreen(i)
end

#consider_autogenerating_exam_aliases(use_this_file = 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
#


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/studium/exams/show_upcoming_exams/consider_autogenerating_exam_aliases.rb', line 25

def consider_autogenerating_exam_aliases(
    use_this_file =
      FILE_ALL_REGISTERED_UPCOMING_EXAMS # Defaults to "/root/Studium/all_registered_upcoming_exams.yml".
  )
  if is_on_roebe? # Only do so on roebe-systems.
    # ===================================================================== #
    # Next we have to determine whether the file 'lecture_information.yml'
    # has any different entry. If so, the cd_aliases entries will be
    # autogenerated.
    # ===================================================================== #
    if File.exist? use_this_file
      existing_dataset = YAML.load_file(use_this_file)
      # =================================================================== #
      # This may be in the wrong encoding, so we have to sanitize the
      # Encoding still. Since as of April 2022 this is no longer in use.
      # =================================================================== #
      # existing_dataset = ensure_main_encoding(existing_dataset)
      # =================================================================== #
      # Next compare this to the dataset from the file
      # 'lecture_information.yml'. We have to load up the
      # original dataset again because the one available
      # from the method reset(), may have been altered
      # lateron.
      # =================================================================== #
      _ = ::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
      }
      # =================================================================== #
      # Finally, compare the two Arrays, but sort them via Time:
      # =================================================================== #
      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)
        # ================================================================= #
        # In this case, we pass through, as it is the very same dataset.
        # ================================================================= #
      else
        # ================================================================= #
        # Else we must update the cd-aliases.
        # ================================================================= #
        update_the_cd_aliases_with_new_exam_entries
      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.

#


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 277

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
      # =================================================================== #
      # We will also use a small icon for the KDE-renaming action.
      # =================================================================== #
      e Roebe.return_important_notification("Next #{n_exams?} exams")
      system 'clear' # Required to get rid of the annoying KDebug output from KDE Konsole.
    end
  end
end

#create_the_auto_stud_aliases(shall_we_exit = true, be_verbose = true) ⇒ Object

#

create_the_auto_stud_aliases

To invoke this class, do:

show_upcoming_exams --autostud
#


109
110
111
112
113
114
115
116
117
118
119
120
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
# File 'lib/studium/exams/show_upcoming_exams/consider_autogenerating_exam_aliases.rb', line 109

def create_the_auto_stud_aliases(
    shall_we_exit = true,
    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(' ','_')
    # ===================================================================== #
    # Sanitize the name of the lecture:
    # ===================================================================== #
    name_of_the_lecture.delete!(':/(),') # Get rid of ':','/','(',')', ','.
    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? '_+_' # Replace '_+_' with '_'
      name_of_the_lecture.gsub!(/_\+_/,'_')
    end
    if name_of_the_lecture.include? '__'
      name_of_the_lecture.squeeze!('_')
    end
    university = inner_hash[:university].dup
    # ===================================================================== #
    # Note that the entries matched in the following variable will be
    # upcased lateron anyway.
    # ===================================================================== #
    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
      opnn; e 'Settting alias '+
              simp(pwdstud_name.to_s.rjust(10))+
              ' pointing to the directory '+
              sdir(target_dir)
    end
    # ===================================================================== #
    # Delegate towards Studium.set_this_cd_alias_to() next,
    # in the file "studium/toplevel_methods/set_this_cd_alias_to.rb".
    # ===================================================================== #
    set_this_cd_alias_to(
      pwdstud_name,
      target_dir,
      :be_quiet # But be quiet there.
    )
    begin
      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?

#

dataset?

#

Returns:

  • (Boolean)


378
379
380
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 378

def dataset?
  @dataset
end

#display_total_ectsObject

#

display_total_ects

#


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 148

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
    e (' ' * 60)+
      limegreen('Total ECTS passed so far: ').to_s+
      colourize_ects_points(::Studium.n_ects_passed_so_far).to_s
    e (' ' * 60).to_s+
      limegreen('ECTS of the above exams:  ')+
      colourize_ects_points(plus)
  end
end

#do_not_report_anythingObject

#

do_not_report_anything

#


73
74
75
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 73

def do_not_report_anything
  @report_result = false
end

#in_n_days(i) ⇒ Object

#

in_n_days

#


187
188
189
190
191
192
193
194
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 187

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

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


56
57
58
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 56

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.

#

Returns:

  • (Boolean)


263
264
265
266
267
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 263

def is_part_of_the_vector_curriculum?(i = '')
  ::Studium.is_this_lecture_part_of_the_vector_curriculum( # <- In the file studium/toplevel_methods/is_this_lecture_part_of_the_vector_curriculum.rb
    i, :be_lenient
  )
end
#

menu (menu tag)

#


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/studium/exams/show_upcoming_exams/menu.rb', line 16

def menu(
    i = @input
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === show_upcoming_exams --auto-stud
    # ===================================================================== #
    when /^-?-?auto(-|_)?stud$/
      create_the_auto_stud_aliases
    # ===================================================================== #
    # === show_upcoming_exams --be_silent
    # ===================================================================== #
    when /^-?-?be(_|-)?silent$/i
      do_not_report_anything
    # ===================================================================== #
    # === show_upcoming_exams --disable-colours
    # ===================================================================== #
    when /^-?-?disable(_|-)?colours$/,
         /^-?-?no(_|-)?colours$/
      @use_colours = false
    # ===================================================================== #
    # === show_upcoming_exams --help
    # ===================================================================== #
    when /^-?-?help$/
      show_help
      exit
    else
      if i.to_s =~ /^(\d+)$/ # Is it a number? 
        set_show_n_upcoming_exams($1.to_s.dup) # If so, feed into this method here.
      end
    end
  end
end

#n_exams?Boolean

#

n_exams?

#

Returns:

  • (Boolean)


169
170
171
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 169

def n_exams?
  @dataset.size
end

#parse_time_entry_from_this_string(the_exam_will_happen_when) ⇒ Object

#

parse_time_entry_from_this_string

#


298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 298

def parse_time_entry_from_this_string(
    the_exam_will_happen_when
  )
  the_exam_will_happen_when = remove_german_weekdays(the_exam_will_happen_when).strip
  the_exam_will_happen_when =~ REGEX_TO_EXTRACT_DATE_AND_TIME_FROM_AN_UPCOMING_EXAM
  this_time = $1.to_s.dup
  begin
    Time.parse(this_time) # This method will return a time-parsed entry.
  rescue Exception => error
    e 'Input to this method was:'
    e
    e '  '+sfancy(the_exam_will_happen_when)
    e
    pp error
    exit
  end
end

#reportObject

#

report (report tag)

#


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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
# File 'lib/studium/exams/show_upcoming_exams/report.rb', line 14

def report
  _ = @dataset
  if _.empty?
    opnn; e 'You have not registered for any upcoming exams.'
  else
    current_month = month?
    # ===================================================================== #
    # At this point, we assume (usually correctly so) that the main
    # dataset was already sorted.
    # ===================================================================== #
    index = 0
    case @show_n_upcoming_exams
    when :all_of_them
      # In this case, we show 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
    _.each {|name_of_the_lecture, inner_hash| index += 1
      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
      colourized_and_padded_index = (' ' * (2 - index.to_s.size ))
      colourized_and_padded_index << orange('(')+
                                     goldenrod(index.to_s)+
                                     orange(') ')
      priority_of_the_lecture = inner_hash[:priority]
      n_ects_points = inner_hash[:ects] # How many ECTS this lecture has.
      startzeit = return_startzeit_from(the_exam_will_happen_when)
      colourized_startzeit = royalblue(' Startzeit: ')+
                             slateblue(startzeit)
      # =================================================================== #
      # === Consider showing the lva-id number next:
      # =================================================================== #
      unless SHOW_LEADING_LVA_ID_NUMBER
        splitted = name_of_the_lecture.split(' ')
        name_of_the_lecture = splitted[1..-1].join(' ').strip 
      end
      # =================================================================== #
      # === Add the date of the exam.
      # =================================================================== #
      date_of_the_exam = return_date_of_the_exam(the_exam_will_happen_when)
      colourized_date_of_the_exam = return_red_vertical_bar+
        yellowgreen(
          date_of_the_exam+', '
        )
      german_weekday = german_weekday?(date_of_the_exam).ljust(11) # "Donnerstag" is the longest name.
      colourized_german_weekday = mediumpurple(german_weekday)
      # =================================================================== #
      # Justify the name of the lecture a bit.
      # =================================================================== #
      if inner_hash.has_key? 'not_yet_registered'
        name_of_the_lecture = name_of_the_lecture.dup if name_of_the_lecture.frozen?
        name_of_the_lecture << ' ← we still have to register for this exam!'
      end
      padded_name_of_the_lecture = name_of_the_lecture.ljust(@n_ljust_to_the_left)
      if padded_name_of_the_lecture.size > @n_ljust_to_the_left
        padded_name_of_the_lecture = padded_name_of_the_lecture[
          0 .. (@n_ljust_to_the_left - 6)
        ]+'[...]'
      end
      if inner_hash.has_key? 'not_yet_registered'
        # ================================================================= #
        # If we aren't yet registered for an exam, then we will
        # always colourize this in crimson().
        # ================================================================= #
        colourized_and_padded_name_of_the_lecture =
            crimson(padded_name_of_the_lecture)
      else
        # ================================================================= #
        # === Colourize the lecture based on the priority
        #
        # Next, colourize the name of the lecture according to the
        # priority. Lectures that are part of the vector-curriculum
        # will always be re-assigned priority one.
        # ================================================================= #
        if is_part_of_the_vector_curriculum?(name_of_the_lecture)
          colourized_and_padded_name_of_the_lecture =
            mediumturquoise(padded_name_of_the_lecture)
        else
          case priority_of_the_lecture
          when 1
            colourized_and_padded_name_of_the_lecture =
              lightsteelblue(padded_name_of_the_lecture)
          else
            colourized_and_padded_name_of_the_lecture =
              lightslategray(padded_name_of_the_lecture)
          end
        end
      end
      # =================================================================== #
      # Add the "Ort" of the exam.
      # =================================================================== #
      the_location = return_location(the_exam_will_happen_when).lstrip
      colourized_location = paleturquoise(
        the_location
      ).sub(/:/, swarn(" #{RIGHT_ARROW}")+paleturquoise) # Return the "Ort" here.
      # =================================================================== #
      # Next, find out in how many days the exam will happen:
      # =================================================================== #
      the_exam_will_happen_in_n_days = in_n_days(date_of_the_exam+' '+startzeit.to_s)
      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
      # =================================================================== #
      # Display a horizontal bar if we are at a new month.
      # =================================================================== #
      if DISPLAY_HORIZONTAL_BAR_TO_INDICATE_A_NEW_MONTH and @report_result
        # ================================================================= #
        # Must first check whether it is a new month.
        # ================================================================= #
        actual_month = date_of_the_exam.scan(/\d{1,2}\.(\d{1,2})\.\d{4}/).flatten
        if actual_month == current_month
        else
          # =============================================================== #
          # Ok, this means we have a new month then.
          # =============================================================== #
          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
      # =================================================================== #
      # Next, output the colourized variants - the big display part:
      # =================================================================== #
      if @report_result
        result = '  '+
                 colourized_and_padded_index+                   # First, we will show the index.
                 colourized_and_padded_name_of_the_lecture+' '+ # Now we will show the name of the lecture.
                 colourized_date_of_the_exam+                   # THe date when the exam happens
                 colourized_german_weekday+ # The weekday in german.
                 colourized_in_n_days+
                 colourized_startzeit
        e result
      end
      # =================================================================== #
      # Also show the location of the exam at hand.
      # =================================================================== #
      location_of_the_exam = (' ' * (@n_ljust_to_the_left+8))+
                             return_red_vertical_bar.rstrip+
                             (' ' * 12)+colourized_location # Add the Ort too.
      if TRY_TO_SHOW_PRIORITIES_FOR_THE_LECTURES
        # ================================================================= #
        # And append the priority as well.
        # ================================================================= #
        colourized_priority = springgreen(
          ' Priorität: '+priority_of_the_lecture.to_s
        )
        location_of_the_exam << colourized_priority
      end
      # =================================================================== #
      # Next append how many ECTS points this exam has.
      # =================================================================== #
      location_of_the_exam << limegreen(
        ' ('+n_ects_points.to_s+' ECTS)'
      )
      e location_of_the_exam if @report_result
    }
    if @report_result
      display_total_ects
      e
    end
  end
end

#report_result?Boolean

#

report_result?

#

Returns:

  • (Boolean)


213
214
215
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 213

def report_result?
  @report_result
end

#report_today(show_n_exams = show_n_exams? ) ⇒ Object

#

report_today

#


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 220

def report_today(
    show_n_exams = show_n_exams?
  )
  if @report_result
    opnn
    e yellowgreen('Heute ist der ')+
      sfancy(dd_mm_yyyy)+' '+
      yellowgreen('(')+
      lightgreen(
        # translate_dd_mm_yyy_to_weekday(dd_mm_yyyy)
        german_weekday?(dd_mm_yyyy)
      )+
      yellowgreen('). Die nächsten ')+
      lightslategray(show_n_exams.to_s)+
      yellowgreen(' Prüfungen sind: ')
    e
  end
end

#resetObject

#

reset (reset tag)

#


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/studium/exams/show_upcoming_exams/reset.rb', line 12

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @report_result
  # ======================================================================= #
  @report_result = true
  # ======================================================================= #
  # === @show_n_upcoming_exams
  #
  # By default all upcoming exams will be shown.
  # ======================================================================= #
  @show_n_upcoming_exams = :all_of_them
  # ======================================================================= #
  # === @dataset_from_file_lecture_information
  # ======================================================================= #
  @dataset_from_file_lecture_information = 
    return_dataset_from_file_lecture_information
  # ======================================================================= #
  # === @n_ljust_to_the_left
  # ======================================================================= #
  @n_ljust_to_the_left = 68
  sanitize_dataset
end

#return_date_of_the_exam(i) ⇒ Object

#

return_date_of_the_exam

This method will extract dd.mm.yyyy.

#


178
179
180
181
182
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 178

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)

#


249
250
251
252
253
254
255
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 249

def return_location(i)
  if i.include? 'Ort'
    ' '+i.scan(/(Ort: .+)$/).flatten.first
  else
    '(No specific Ort has been found - or is known)'
  end
end

#return_red_vertical_barObject

#

return_red_vertical_bar

#


199
200
201
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 199

def return_red_vertical_bar
  swarn("#{SEPARATOR_TOKEN_TO_USE} ")
end

#return_startzeit_from(i) ⇒ Object

#

return_startzeit_from

#


139
140
141
142
143
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 139

def return_startzeit_from(i)
  return i.scan(
    /\d{1,2}:\d{1,2}-\d{1,2}:\d{1,2}/ # This is the regex we are currently using.
  ).flatten.first
end

#runObject

#

run (run tag)

#


12
13
14
15
16
17
18
# File 'lib/studium/exams/show_upcoming_exams/run.rb', line 12

def run
  menu
  consider_renaming_the_konsole_tab
  consider_autogenerating_exam_aliases
  report
  store_old_upcoming_exams # ← Store the upcoming-exams into a file as well.
end

#sanitize_datasetObject

#

sanitize_dataset

#


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 80

def sanitize_dataset
  # ======================================================================= #
  # Select all lectures for which we are either registered, or
  # not_yet_registered_for_an_upcoming_exam_at - the latter applies
  # to lectures where we will still have to register for.
  # ======================================================================= #
  @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_input(i = '') ⇒ Object

#

set_input

#


47
48
49
50
51
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 47

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

#


63
64
65
66
67
68
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 63

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

#show_helpObject

#

show_help (help tag)

Invoke this method via:

show_upcoming_exams --help
#


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/studium/exams/show_upcoming_exams/help.rb', line 19

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) ⇒ Object

#

show_horizontal_bar

This will show a red, horizontal bar - or, alternatively, also the name of the month at hand..

#


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
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 322

def show_horizontal_bar(
    optional_this_month = nil
  )
  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
  result = '  '.dup
  result << swarn('-' * (@n_ljust_to_the_left+6)).dup
  if optional_this_month
    n_tokens_to_the_right = 30
    result << saddlebrown('[Beginn ')
    german_name_for_this_month = return_german_name_for_this_english_month(optional_this_month).dup
    result << darkgoldenrod(german_name_for_this_month)
    if use_unicode_symbols?
      # =================================================================== #
      # Display a little smiley-face next, if we make use of unicode
      # symbols.
      # =================================================================== #
      result << " #{darkgoldenrod(Roebe.black_smiling_face)}"
    end
    result << saddlebrown(']')
    # ===================================================================== #
    # The user may pass a special Hash to this method, in which case we
    # may display some more - in particular n ECTS points registered so
    # far for the given month.
    # ===================================================================== #
    if block_given?
      yielded = yield
      if yielded.is_a? Hash
        # ================================================================= #
        # === :n_ects_points_in_this_month
        # ================================================================= #
        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] "
            colourized_n_ects_points_string = colourize_ects_points(
              n_ects_points_string
            )
            result << colourized_n_ects_points_string
            n_tokens_to_the_right -= n_ects_points_string.size
          end
        end
      end
    end
    result << swarn('-' * n_tokens_to_the_right)
  end
  e result
end

#show_n_upcoming_exams?Boolean Also known as: show_n_exams?

#

show_n_upcoming_exams?

#

Returns:

  • (Boolean)


206
207
208
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 206

def show_n_upcoming_exams?
  @show_n_upcoming_exams
end

#sort_dataset_by_timeObject

#

sort_dataset_by_time

#


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 99

def sort_dataset_by_time
  @dataset = @dataset.sort_by {|name_of_the_lecture, inner_hash|
    # ===================================================================== #
    # We will next select lectures that have the entry called
    # registered.
    # However had, not all lectures may have this entry - for example,
    # some lectures have exam entries for which we have not yet
    # registered. So the following code has to keep this in "mind".
    # ===================================================================== #
    if inner_hash.has_key? 'registered'
      if inner_hash['registered'].respond_to? :first
        the_exam_will_happen_when = inner_hash['registered'].first
      else
        opnn; e crimson(name_of_the_lecture)+
                ' has no key called `'+
                sfancy('registered')+'`.'
        opnn; e 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
        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
    parse_time_entry_from_this_string(the_exam_will_happen_when)
  }
end

#store_old_upcoming_examsObject

#

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.

#


430
431
432
# File 'lib/studium/exams/show_upcoming_exams/show_upcoming_exams.rb', line 430

def store_old_upcoming_exams
  Studium.save_all_registered_upcoming_exams # ← Save the upcoming exams here. 
end

#update_the_cd_aliases_with_new_exam_entriesObject

#

update_the_cd_aliases_with_new_exam_entries

This will do a semi-silent update.

#


94
95
96
97
98
99
# File 'lib/studium/exams/show_upcoming_exams/consider_autogenerating_exam_aliases.rb', line 94

def update_the_cd_aliases_with_new_exam_entries
  opnn; e "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