Class: Studium::Exams::UpcomingExams

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

Overview

Studium::Exams::UpcomingExams

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect

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(commandline_arguments = ARGV, run_already = true) ⇒ UpcomingExams

#

initialize

#


16
17
18
19
20
21
22
23
24
25
# File 'lib/studium/exams/upcoming_exams/initialize.rb', line 16

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Studium::Exams::UpcomingExams[]

#


336
337
338
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 336

def self.[](i = '')
  new(i)
end

.open_relevant_filesObject

#

Studium::Exams::UpcomingExams.open_relevant_files

#


329
330
331
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 329

def self.open_relevant_files
  ::Studium.open_important_exams
end

Instance Method Details

#check_for_duplicatesObject

#

check_for_duplicates

#


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 66

def check_for_duplicates
  hash = {}
  hash.default = 0
  @dataset_from_the_file_important_exams.each {|entry|
    splitted = entry.split('|')
    # ===================================================================== #
    # The name of the lecture is only the first part of the above variable.
    # ===================================================================== #
    name_of_the_lecture = splitted.first.strip
    hash[name_of_the_lecture] += 1
  }
  # ======================================================================= #
  # Next we will check for duplicates. If found, we will report them.
  # ======================================================================= #
  try_to_report_duplicate_entries_in_this_hash(hash)
end

#check_whether_the_entries_in_the_file_important_exams_are_correctObject

#

check_whether_the_entries_in_the_file_important_exams_are_correct (check tag)

Invocation example:

timetable --check
#


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 269

def check_whether_the_entries_in_the_file_important_exams_are_correct
  dataset_from_the_file_lecture_information =
    Studium.return_sanitized_dataset_from_the_file_lecture_information
  everything_is_ok = true
  _ = prepare_and_then_return_main_dataset
  _.each {|line|
    first    = line.first.squeeze(' ').strip
    if dataset_from_the_file_lecture_information.has_key?(first)
      # Then all is fine
    else
      everything_is_ok = false
      opnn; e 'The lecture '+sfancy(first)+' is not registered '\
              'in the file '+sfancy('lecture_information.yml')
    end
  }
  if everything_is_ok
    opnn; e 'Everything is fine - the entries in the file '
    opnn; e sfile('lecture_information.yml')+' all appear to be correct.'
  end
end

#create_html_file(into = "#{html_log_dir?}timetable.html") ⇒ Object

#

create_html_file

This method will create our .html file in question.

The first argument to this method denotes where to store the .html file in question.

#


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
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 114

def create_html_file(
    into = "#{html_log_dir?}timetable.html" # Decide where to store this.
  ) 
  # ======================================================================= #
  # Obtain the proper <div> timetable next. The code for this resides
  # in:
  #
  #   bl $RUBY_STUDIUM/toplevel_methods/return_div_timetable_of_upcoming_exams.rb
  #
  # ======================================================================= #
  div_element = ::Studium.return_div_timetable_of_upcoming_exams(
    dataset?,
    :remove_leading_lva_id_entries
  )
  string_for_html_file = ''.dup
  string_for_html_file << "<html>#{N}"
  # ======================================================================= #
  # Assume HTML4 for now; HTML5 is probably backwards-compatible.
  # ======================================================================= #
  string_for_html_file << '<meta http-equiv="content-type" content="text/html; charset=UTF-8" >'
  string_for_html_file << "<title>Timetable</title><body>#{N}"
  string_for_html_file << div_element # Append the timetable <div> here.
  string_for_html_file << '</body></html>'
  what = string_for_html_file
  write_what_into(what, into)
  opnn; e 'Storing into `'+sfile(into)+'`.'
  if File.exist?(into) and is_on_roebe?
    require 'open' unless Object.const_defined? :Open
    silently_open_in_browser(into)
  end
end

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


156
157
158
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 156

def dataset?
  @dataset
end

#do_not_exitObject

#

do_not_exit

#


163
164
165
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 163

def do_not_exit
  @exit_on_problems = false
end

#filter_away_all_but_these_months(i) ⇒ Object

#

filter_away_all_but_these_months

This method can be used to filter away all but the given input arguments months, such as 'September'.

Invocation example:

upcoming_exams --September
#


246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 246

def filter_away_all_but_these_months(i)
  i = i.delete('-')
  i.sub!(/month=/,'') if i.include? 'month='
  i = return_month_fitting_to_this_input(i)
  i = i.to_i # Don't want any '-' characters.
  @dataset.select! {|a,b|
    exams = b['exams']
    if exams.is_a? Array
      exams = exams.first
    end
    exams = remove_german_weekdays(exams).strip.delete(',')
    exams.split('.')[1].to_i == i
  }
end

#filter_away_unimportant_examsObject

#

filter_away_unimportant_exams

#


192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 192

def filter_away_unimportant_exams
  @dataset.select! {|a, b|
    unless @dataset.has_key?(a)
      opnn; e 'The key '+sfancy(a.strip)+' is not registered '\
              'in the file lecture_information.yml'
      opnn; e 'This is presently not allowed. '+
              yellow('Exiting now.')
      opnn; e 'The file that should include this lecture is `'+
              sfile(
                File.basename(main_file?)
              )+
              '`.'
      exit
    end
    @dataset_from_the_file_important_exams.include?(a)
  }
end

#main_file?Boolean Also known as: important_exams?

#

main_file?

This query-method will refer to the file called “studium/yaml/important_exams.yml”.

#

Returns:

  • (Boolean)


296
297
298
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 296

def main_file?
  Studium.file_important_exams?
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
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
# File 'lib/studium/exams/upcoming_exams/menu.rb', line 16

def menu(
    i = @commandline_arguments
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === timetable --September
    # === timetable --month=September
    # === timetable --July
    # ===================================================================== #
    when /^-?-?(month=)?August$/i,
         /^-?-?(month=)?September$/i,
         /^-?-?(month=)?November$/i,
         /^-?-?(month=)?October$/i,
         /^-?-?(month=)?December$/i,
         /^-?-?(month=)?January$/i,
         /^-?-?(month=)?February$/i,
         /^-?-?(month=)?March$/i,
         /^-?-?(month=)?April$/i,
         /^-?-?(month=)?May$/i,
         /^-?-?(month=)?June$/i,
         /^-?-?(month=)?July$/i
      # =================================================================== #
      # Next, we have to filter away all entries but the specific month.
      # =================================================================== #
      filter_away_all_but_these_months(i) # Does an in-place filter.
    # ===================================================================== #
    # === timetable --check
    # ===================================================================== #
    when /^-?-?check$/i
      check_whether_the_entries_in_the_file_important_exams_are_correct
      exit
    # ===================================================================== #
    # === timetable --master
    # ===================================================================== #
    when /^-?-?master$/i
      _ = main_dataset?.select {|name_of_the_lecture, b|
        is_a_master_lecture?(name_of_the_lecture)
      }
      set_main_dataset(_)
    # ===================================================================== #
    # === timetable --do-not-exit
    # ===================================================================== #
    when /^-?-?do(-|_)?not(-|_)?exit$/i
      do_not_exit
    # ===================================================================== #
    # === timetable --help
    # ===================================================================== #
    when /-?-?help$/
      show_help
      exit
    # ===================================================================== #
    # === timetable --open
    # ===================================================================== #
    when /open$/i
      open_all_important_files
      exit
    end
  end
end

#notify_the_user_that_this_lecture_has_no_associated_remote_url(name_of_the_lecture_that_we_wish_to_display) ⇒ Object

#

notify_the_user_that_this_lecture_has_no_associated_remote_url

#


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 49

def notify_the_user_that_this_lecture_has_no_associated_remote_url(
    name_of_the_lecture_that_we_wish_to_display
  )
  opnn; e 'It seems as if "'+
          sfancy(name_of_the_lecture_that_we_wish_to_display)+
          '" does not have an associated'
  opnn; e "remote URL. Please add this to the file "\
          "#{sfile('university_menu.rb')}"
  if @exit_on_problems
    opnn; e 'Exiting now. (--do-not-exit can be bypassed to NOT exit)'
    exit
  end
end

#notify_the_user_which_file_is_to_be_usedObject

#

notify_the_user_which_file_is_to_be_used

#


318
319
320
321
322
323
324
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 318

def notify_the_user_which_file_is_to_be_used
  e
  opnn; e 'Using the dataset from the file'
  e
  e "  #{sfile(main_file?)}"
  e
end

#open_all_important_filesObject

#

open_all_important_files (open tag)

It will open the file on my home system, rather than the one that is inside the distributed studium-gem.

To invoke this, do:

timetable --open
#


311
312
313
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 311

def open_all_important_files
  ::Studium.open_important_exams
end

#prepare_and_then_return_main_datasetObject

#

prepare_and_then_return_main_dataset

#


170
171
172
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 170

def prepare_and_then_return_main_dataset
  return read_in_the_dataset_from_the_file_important_exams
end

#read_in_the_dataset_from_the_file_important_examsObject

#

read_in_the_dataset_from_the_file_important_exams

#


177
178
179
180
181
182
183
184
185
186
187
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 177

def read_in_the_dataset_from_the_file_important_exams
  # ======================================================================= #
  # === @dataset_from_the_file_important_exams
  # ======================================================================= #
  @dataset_from_the_file_important_exams =
    readlines_with_the_default_encoding(FILE_IMPORTANT_EXAMS).reject {|line|
      line.strip.empty? or line.strip.start_with?('#')
    }.map {|inner_line| inner_line.strip.squeeze(' ')
  }
  return @dataset_from_the_file_important_exams
end

#report(i = @dataset) ⇒ Object Also known as: report_the_lectures_that_will_be_used

#

report

#


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
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 16

def report(
    i = @dataset
  )
  i.each {|name_of_the_lecture, inner_hash|
    exams = inner_hash['exams']
    # ===================================================================== #
    # We also want to use the remote_url, so add it next. However had, for
    # the time being, we require that this is registered in the project
    # BeautifulUrl. And if it is not, then we will report this as an error.
    # ===================================================================== #
    if inner_hash.has_key? :homepage
      use_this_remote_url = inner_hash[:homepage] # Get a handler first.
      if use_this_remote_url.is_a? Array
        use_this_remote_url = use_this_remote_url.first
      end
    else
      notify_the_user_that_this_lecture_has_no_associated_remote_url(
        name_of_the_lecture
      )
    end
    # ===================================================================== #
    # Tell the user on which lecture we are working right now.
    # ===================================================================== #
    _ = hh_mm_ss_dd_mm_yyyy(exams).split('-').reverse.join(', ')
    e "Working on #{steelblue(name_of_the_lecture)}"
    e "  #{orange(use_this_remote_url)} "
    e "  Exam at: #{tomato(_)}"
  }
end

#resetObject

#

reset (reset tag)

#


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/studium/exams/upcoming_exams/reset.rb', line 16

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @exit_on_problems
  # ======================================================================= #
  @exit_on_problems = false
  # ======================================================================= #
  # === @dataset
  #
  # This variable will eventually hold the lectures that we wish
  # to display. It taps into the file "lecture_information.yml"
  # originally.
  # ======================================================================= #
  @dataset = return_lectures_with_at_the_least_one_upcoming_exam
  read_in_the_dataset_from_the_file_important_exams
end

#runObject

#

run (run tag)

#


16
17
18
19
20
21
22
23
# File 'lib/studium/exams/upcoming_exams/run.rb', line 16

def run
  menu
  notify_the_user_which_file_is_to_be_used
  check_for_duplicates
  sanitize_the_dataset
  report
  create_html_file # ←  This method call should come last.
end

#sanitize_the_datasetObject

#

sanitize_the_dataset

#


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 213

def sanitize_the_dataset
  # First, filter away the unimportant exams.
  filter_away_unimportant_exams
  _ = @dataset.map {|a, inner_hash|
    exams = inner_hash['exams']
    if exams.is_a? Array
      exams = exams.first
    end
    exams.strip!
    exams.squeeze!(' ')
    exams = remove_german_weekdays(exams)
    if exams.include? '-'
      exams = exams.split('-').first
    end
    inner_hash['exams'] = Time.parse(exams)
    [a, inner_hash]
  }
  _ = _.sort_by {|a,b| b['exams'] }
  _ = Hash[_]
  @dataset = _
end

#show_helpObject

#

show_help (help tag)

Invocation example:

timetable --help
#


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/studium/exams/upcoming_exams/help.rb', line 21

def show_help
  e; opnn { :no_trailing_character }; e
  e
  e 'The following commandline-options are available:'
  e
  e '  --check           # check the format and validity '\
    'of the file important_exams.yml'
  e '  --do-not-exit     # do not exit if there is no registration '\
    'in the project beautiful_url.'
  e '  --master          # show only upcoming master-exams.'
  e '  --month=September # show only exams in that month'
  e
  e "Additionally you can pass in #{orange('--open')} to "\
    "open the yaml file."
  e
end

#silently_open_in_browser(into) ⇒ Object

#

silently_open_in_browser

#


149
150
151
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 149

def silently_open_in_browser(into)
  Open.in_browser(into) { :be_silent }
end

#try_to_report_duplicate_entries_in_this_hash(hash) ⇒ Object

#

try_to_report_duplicate_entries_in_this_hash

This method will try to find duplicate entries in the given Hash.

#


88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/studium/exams/upcoming_exams/misc.rb', line 88

def try_to_report_duplicate_entries_in_this_hash(
    hash
  )
  potential_duplicates = hash.select {|key, value| value > 1 }
  unless potential_duplicates.empty?
    opnn; e "The file #{sfile(main_file?)} has at the "\
            "least one duplicate entry."
    potential_duplicates.each {|key, value|
      opnn; e "A duplicate entry was found, called: `#{sfancy(key)}`"
      opnn; e 'The file that holds this entry is `'+sfile(main_file?)+'`.'
    }
  end
end