Class: Studium::Exams::ExamRegistrationAt

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

Overview

Studium::Exams::ExamRegistrationAt

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
LOOK_N_DAYS_INTO_THE_FUTURE =
#

LOOK_N_DAYS_INTO_THE_FUTURE

How many days to look into upcoming registrations (for exams, although the entry may also be used for lectures that have a mandatory course presence).

Currently the default is 90 days into the future.

#
90
ONE_DAY =
#

ONE_DAY

Measured in seconds.

#
60 * 60 * 24
ENCODING_TO_USE_IN_THIS_FILE =
#

ENCODING_TO_USE_IN_THIS_FILE

#
{
  encoding: ::Studium.main_encoding?
}
FILE =
#

FILE

#
'$RUBY_SRC/studium/lib/studium/exams/exam_registration_at/exam_registration_at.rb'
THIS_FILE =

Pointer to the above.

FILE

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, #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, #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(optional_commandline_arguments = ARGV, run_already = true) ⇒ ExamRegistrationAt

#

initialize

#


36
37
38
39
40
41
42
43
44
45
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 36

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

Class Method Details

.[](i = '') ⇒ Object

#

Studium::Exams::ExamRegistrationAt[]

#


237
238
239
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 237

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

Instance Method Details

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


122
123
124
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 122

def dataset?
  @dataset
end

#do_notify_the_user_that_no_registered_upcoming_exam_was_foundObject

#

do_notify_the_user_that_no_registered_upcoming_exam_was_found

#


16
17
18
19
20
21
# File 'lib/studium/exams/exam_registration_at/report.rb', line 16

def do_notify_the_user_that_no_registered_upcoming_exam_was_found
  if @notify_the_user_that_no_registered_upcoming_exam_registry_was_found
    opnn; e 'No "'+orange('Anmeldung')+'" (registry to an exam) is '\
            'upcoming in the next '+sfancy(n_days?.to_s)+' days.'
  end
end

#exit_program(exit_code_to_use = 0) ⇒ Object

#

exit_program

Use this unified exit-method for this class.

Exit code 1 here means that an important file was not found.

#


54
55
56
57
58
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 54

def exit_program(
    exit_code_to_use = 0
  )
  exit(exit_code_to_use) if @may_we_exit # Will be true by default.
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
78
79
# File 'lib/studium/exams/exam_registration_at/menu.rb', line 16

def menu(
    i = @commandline_arguments
  )
  if i.is_a? Hash # === Handle Hashes here (a rare case)
    if i.has_key? :n_days_in_the_future
      set_days( i.delete(:n_days_in_the_future) )
    end
    if i.has_key? :use_colours
      disable_colours unless i.delete(:use_colours)
    end
  elsif i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === anm --location?
    # ===================================================================== #
    when /^-?-?location\??$/i
      show_file_location
      exit
    # ===================================================================== #
    # === anm --open-all
    # ===================================================================== #
    when /^-?-?open(-|_)?all$/i
      open_this_file_here
      open_the_yaml_file
    # ===================================================================== #
    # === anm --show
    # ===================================================================== #
    when /^-?-?show$/i,
         /^-?-?available$/,
         /^-?-?file\??/i,
         /^-?-?show(-|_)?all$/i,
         /^-?-?all$/i,
         /^-?-?everything$/i
      show_all_anmeldungen
      exit
    # ===================================================================== #
    # === anm --debug
    # ===================================================================== #
    when /-?-?debug/
      enable_debug
    # ===================================================================== #
    # === anm --help
    # ===================================================================== #
    when 'HELP',/-?-?help/
      show_help
      exit
    # ===================================================================== #
    # === anm --open
    # ===================================================================== #
    when /^-?-?open$/i
      open_the_yaml_file
      exit
    else
      # =================================================================== #
      # === Handle instructions such as "anm --55"
      # =================================================================== #
      if i.include? '--' and i=~ /\d+/
        set_n_days(i.delete('-').strip)
      end
    end
  end
end

#n_days?Boolean Also known as: report_in_the_next_n_days?

#

n_days?

#

Returns:

  • (Boolean)


82
83
84
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 82

def n_days?
  @look_n_days_into_the_future
end

#open_in_editor(file = YAML_FILE) ⇒ Object

#

open_in_editor

Pass the file-path to this method, in order to open it in bluefish.

#


158
159
160
161
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 158

def open_in_editor(file = YAML_FILE)
  _ = USE_THIS_EDITOR+' '+file
  esystem _
end

#open_the_yaml_file(i = FILE_LECTURE_INFORMATION) ⇒ Object

#

open_the_yaml_file

#


193
194
195
196
197
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 193

def open_the_yaml_file(
    i = FILE_LECTURE_INFORMATION
  )
  open_in_editor(i)
end

#open_this_file_here(shall_we_exit = true) ⇒ Object

#

open_this_file_here (open tag)

#


173
174
175
176
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 173

def open_this_file_here(shall_we_exit = true)
  open_in_editor(this_file_here)
  exit_program if shall_we_exit
end

#opnnObject

#

opnn

#


89
90
91
92
93
94
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 89

def opnn
  super({
    use_colours:        use_colours?,
    use_this_namespace: NAMESPACE
  }) { yield }
end

#report_lectures_that_are_up_for_exam_registrationObject Also known as: report

#

report_lectures_that_are_up_for_exam_registration (report tag)

#


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
# File 'lib/studium/exams/exam_registration_at/report.rb', line 26

def report_lectures_that_are_up_for_exam_registration
  if @dataset.empty?
    do_notify_the_user_that_no_registered_upcoming_exam_was_found
  else
    # ===================================================================== #
    # Show the date only when there is at the least one upcoming exam
    # registration.
    # ===================================================================== #
    e
    e "#{rev}Today is the #{royalblue(return_dd_mm_yyyy.to_s)} "\
      "(#{german_weekday(return_dd_mm_yyyy.to_s)}). "\
      "The following #{gold('exam-registrations')} are upcoming:"
    e
    today = Time.now
    # ===================================================================== #
    # Report the individual entries next.
    # ===================================================================== #
    @dataset.each {|name_of_the_lecture, inner_hash|
      # =================================================================== #
      # Obtain the specific exam-registration next:
      # =================================================================== #
      upcoming_exam_at = inner_hash[:exam_registration_at]
      upcoming_exam_at = upcoming_exam_at.first if upcoming_exam_at.is_a? Array
      upcoming_exam_at = remove_german_weekdays_from(upcoming_exam_at)
      if upcoming_exam_at.is_a? String
        upcoming_exam_at = Time.parse(upcoming_exam_at)
      end
      properly_sanitized_upcoming_exam_at = dd_mm_yyyy(upcoming_exam_at)+
                                            ' [ab: '+
                                            return_hh_mm_ss_from(
                                              upcoming_exam_at
                                            )+']'
      # =================================================================== #
      # The colour teal will be used; and a bit padding towards left and
      # right.
      # =================================================================== #
      colourized_and_padded_name_of_the_lecture = teal(
        "  #{name_of_the_lecture.ljust(@n_ljust)} "
      )
      # =================================================================== #
      # We must determine if the day passed is "today". If so then we
      # will colourize this slightly differently.
      # =================================================================== #
      if is_this_day_today?(upcoming_exam_at)
        colourized_upcoming_exam_at = crimson(properly_sanitized_upcoming_exam_at)
        # =================================================================== #
        # Also show the remote URL.
        # =================================================================== #
        remote_url = beautiful_url(name_of_the_lecture)
        if remote_url.is_a? Array
          remote_url = remote_url.first
        end
        colourized_and_padded_remote_url = "          "\
                                           "#{lightgreen('rf')} "\
                                           "#{royalblue('"')}"\
                                           "#{royalblue(remote_url)}"\
                                           "#{royalblue('"')}"
      elsif today > upcoming_exam_at
        # ================================================================= #
        # Lighter colour when we can already register for that exam (or
        # when we could do so in the past).
        # ================================================================= #
        colourized_upcoming_exam_at = lightblue(properly_sanitized_upcoming_exam_at).dup
      else
        # ================================================================= #
        # Otherwise we will use a slightly darker colour for the date.
        # ================================================================= #
        colourized_upcoming_exam_at = slateblue(properly_sanitized_upcoming_exam_at)
      end
      result = colourized_and_padded_name_of_the_lecture.dup
      result << colourized_upcoming_exam_at
      result << "\n"
      if colourized_and_padded_remote_url
        result << "\n#{colourized_and_padded_remote_url}\n\n"
      end
      e result
      colourized_and_padded_remote_url = nil
    }
    e # And a newline, for prettier output.
  end
end

#resetObject

#

reset

#


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

def reset
  super()
  # ======================================================================= #
  # === @dataset
  #
  # Only look at lectures that have an exam_registration_at entry.
  # ======================================================================= #
  @dataset = select_lectures_with_this_key(:exam_registration_at)
  # ======================================================================= #
  # === @notify_the_user_that_no_registered_upcoming_exam_registry_was_found
  #
  # The next instance variable will determine whether we will notify the
  # user that there is no upcoming exam registry. This also allows a
  # silent mode, aka not reporting anything to the user.
  # ======================================================================= #
  @notify_the_user_that_no_registered_upcoming_exam_registry_was_found = true
  # ======================================================================= #
  # === @look_n_days_into_the_future
  # ======================================================================= #
  @look_n_days_into_the_future = LOOK_N_DAYS_INTO_THE_FUTURE # 3 weeks by default.
  # ======================================================================= #
  # === @may_we_exit
  # ======================================================================= #
  @may_we_exit = true
  # ======================================================================= #
  # === @n_ljust
  #
  # This determines how much we should pad to the left-hand side,
  # via ' ' characters.
  # ======================================================================= #
  @n_ljust = 75
end

#runObject

#

run

#


227
228
229
230
231
232
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 227

def run
  menu
  sanitize_dataset
  sanitize_fitting_lectures
  report_lectures_that_are_up_for_exam_registration
end

#sanitize_datasetObject

#

sanitize_dataset

This method will clean up the @dataset variable, by removing weekday names such as “Montag” from the time string. After that, the date entry will be parsed via Time.parse(). This allows us to make accurate predictions as to when there will be an upcoming exam registration.

#


105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 105

def sanitize_dataset
  new_hash = {}
  @dataset.each_pair {|a, b|
    exam_registration_at = b[:exam_registration_at]
    exam_registration_at.map! {|entry|
      entry = remove_leading_weekdays(entry)
      Time.parse(entry)
    }
    b[:exam_registration_at] = exam_registration_at
    new_hash[a] = b
  }
  @dataset = new_hash
end

#sanitize_fitting_lecturesObject

#

sanitize_fitting_lectures

Here we make use of the time range, e. g. for how many days we will look into the future.

#


132
133
134
135
136
137
138
139
140
141
142
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 132

def sanitize_fitting_lectures
  future_time = @look_n_days_into_the_future * ONE_DAY
  time_now = Time.now
  future_time_date = time_now + future_time
  @dataset.select! {|a, b|
    time = b[:exam_registration_at]
    time = time.first if time.is_a? Array
    time < future_time_date
  }
  sort_the_dataset
end

#set_look_n_days_into_the_future(i = :default) ⇒ Object Also known as: set_days, set_n_days, set_report_in_the_next_n_days, set_n_days_into_the_future

#

set_look_n_days_into_the_future

We require an integer number ultimately.

#


65
66
67
68
69
70
71
72
73
74
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 65

def set_look_n_days_into_the_future(
    i = :default
  )
  i = :default if i.nil?
  case i
  when :default
    i = LOOK_N_DAYS_INTO_THE_FUTURE
  end
  @look_n_days_into_the_future = i.to_i
end

#show_all_anmeldungenObject

#

show_all_anmeldungen

Here we will show all Anmeldungen, in lightslategray colours.

To invoke this method, do:

anm --show
#


209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 209

def show_all_anmeldungen
  the_dataset = dataset?
  # ======================================================================= #
  # Next, re-arrange the dataset to sort it by date first.
  # ======================================================================= #
  the_dataset = the_dataset.sort_by {|line|
    splitted = line.split(' ')
    time_entry = Time.parse(splitted[1])
    time_entry # Return it here.
  }
  e; the_dataset.each {|line|
    e "  #{lightslategray(line)}"
  }; e
end

#show_file_location(i = FILE_LECTURE_INFORMATION) ⇒ Object

#

show_file_location

Commandline invocation:

anm --location?
#


186
187
188
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 186

def show_file_location(i = FILE_LECTURE_INFORMATION)
  e sfile(i)
end

#show_helpObject

#

show_help (help tag)

To invoke this method do:

ereg --help
#


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/exam_registration_at/help.rb', line 21

def show_help

help_string = <<-EOF

You can instruct this class to show all upcoming exams n days into 
the future:

#{sfancy('  --55')}

That number given will tell this class to show all upcoming
exams next 55 days into the future.
  
You can also show all available Anmeldungen:

#{sfancy('  --available')}

If you wish to see more information, you can enable the debug
mode by issuing:

#{sfancy('  --debug')}

EOF
  e help_string
end

#sort_the_datasetObject

#

sort_the_dataset

#


147
148
149
150
151
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 147

def sort_the_dataset
  @dataset = @dataset.sort_by {|a, b|
    b[:exam_registration_at].first
  }
end

#this_file_hereObject

#

this_file_here

#


166
167
168
# File 'lib/studium/exams/exam_registration_at/exam_registration_at.rb', line 166

def this_file_here
  THIS_FILE
end