Class: Studium::WeekParser

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

Overview

Studium::WeekParser

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
SKIP_LOW_PRIORITY_LECTURES =
#

SKIP_LOW_PRIORITY_LECTURES

If true then we will skip low priority lectures.

#
true
PAD_TO_THE_RIGHT =
#

PAD_TO_THE_RIGHT

#
99

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

#

initialize

#


36
37
38
39
40
41
42
43
# File 'lib/studium/utility_scripts/week_parser/week_parser.rb', line 36

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_commandline_arguments(i)
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Studium::WeekParser[]

#


369
370
371
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 369

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

Instance Method Details

#colourize_lecture_day(first_date, priority = 1) ⇒ Object

#

colourize_lecture_day

The second argument is the priority of the lecture. Lectures with a higher priority will be brighter in colour (this is the part that will appear on the very left-hand side).

#


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 30

def colourize_lecture_day(
    first_date, priority = 1
  )
  priority = priority.to_i
  case priority
  when 1
    return yellowgreen(first_date)
  when 4,5
    return darkgreen(first_date)
  else
    return darkolivegreen(first_date)
  end
end

#colourized_priority(priority, use_this_colour = :slateblue) ⇒ Object

#

colourized_priority

The priority 1 will be colourized via powderblue. The surrounding '(' and ')' will be in royalblue.

#


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 232

def colourized_priority(
    priority, use_this_colour = :slateblue
  )
  result = royalblue('(Priorität: ').dup
  case use_this_colour
  when :honour_priority_value # <- This denotes special behaviour.
    case priority.to_s
    when '1'
      result << lightseagreen(priority.to_s)
    else
      result << slateblue(priority.to_s)
    end
  when :slateblue
    result << slateblue(priority.to_s)
  when :red, :exam, :warning
    result << crimson(priority.to_s)
  end
  result << royalblue(')')
  return result
end

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


325
326
327
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 325

def dataset?
  @dataset
end

#dataset_lecture_information?Boolean

#

dataset_lecture_information?

#

Returns:

  • (Boolean)


318
319
320
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 318

def dataset_lecture_information?
  @dataset
end

#determine_the_weekday_from(i = 'Mittwoch 14.03.2018') ⇒ Object

#

determine_the_weekday_from

#


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 119

def determine_the_weekday_from(
    i = 'Mittwoch 14.03.2018'
  )
  return i unless i
  if i.include? ' ' # In this case, use only the last part.
    i = i.split(' ').last
  end
  parsed_time = Time.parse(i)
  weekday = parsed_time.wday
  case weekday
  when 1
    :monday
  when 2
    :tuesday
  when 3
    :wednesday
  when 4
    :thursday
  when 5
    :friday
  when 6
    :saturday
  end
end

#exams_on_this_day(i) ⇒ Object

#

exams_on_this_day

#


12
13
14
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 12

def exams_on_this_day(i)
  ::Studium.return_all_exams_on_this_day(i)
end
#

menu (menu 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/studium/utility_scripts/week_parser/menu.rb', line 12

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === week_parser --unrestricted
    # ===================================================================== #
    when /^-?-?unrestricted$/,
         /^-?-?infinity$/
      opnn; e 'Showing many more lectures next.'
      @n_days_into_the_future = 300
    # ===================================================================== #
    # === week_parser --debug
    # ===================================================================== #
    when /-?-?debug$/
      @debug = true
    # ===================================================================== #
    # === week_parser --help
    # ===================================================================== #
    when /-?-?help/
      show_help
      exit
    else # else tag
      if is_a_weekday?(i.delete('-'))
        # ================================================================= #
        # In this case, only use that weekday.
        # ================================================================= #
        this_weekday = i.delete('-')
        if GERMAN_TO_ENGLISH_WEEKDAYS.has_key? this_weekday
          # =============================================================== #
          # In this case we will assume that it is a german name for
          # a weekday, thus we will convert it.
          # =============================================================== #
          this_weekday = GERMAN_TO_ENGLISH_WEEKDAYS[this_weekday]
        end
        this_weekday = this_weekday.downcase.to_sym
        @array_show_these_days = [
          this_weekday
        ]
      end
    end
  end
end

#populate_hash_weekly_lectures_with_these_lectures(hash) ⇒ Object

#

populate_hash_weekly_lectures_with_these_lectures

We may reject entries that are not within the next e. g. 30 coming days.

Additionally, entries that have old lva_dates should be disregarded as well. In these case, we may try to locate a new lva-date entry.

#


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 153

def populate_hash_weekly_lectures_with_these_lectures(hash)
  hash_weekly_lectures = @hash_weekly_lectures
  # ======================================================================= #
  # How many days to peek into the future:
  # ======================================================================= #
  maximum_allowed_time_in_the_future = return_n_days(@n_days_into_the_future) # <- Is usually 30 days.
  hash.each_pair {|name_of_the_lecture, inner_hash|
    # ===================================================================== #
    # First obtain a "pointer" to our main data structure, the lecture
    # at hand with all the associated information.
    # ===================================================================== #
    pointer = { name_of_the_lecture => inner_hash }
    # ===================================================================== #
    # Retrieve the first lva_date.
    # ===================================================================== #
    all_lva_dates = inner_hash['lva_dates']
    if all_lva_dates.nil?
      opnn; e 'No lva-entry found for '+sfancy(name_of_the_lecture)
      next
    end
    first_lva_date = all_lva_dates.first.squeeze(' ')
    splitted = first_lva_date.split(',').map(&:strip)
    this_date = splitted.first
    this_time_on_that_day = splitted.last # And keep a reference to the time on that day.
    # ===================================================================== #
    # Next we must identify where to add it, aka the week-day.
    # ===================================================================== #
    weekday_to_be_used_as_symbol = determine_the_weekday_from(this_date) # <- This must be a symbol.
    this_date = remove_weekdays_from(this_date).strip # <- Clean it up a little.
    # ===================================================================== #
    # And obtain the time representation of that String next.
    # ===================================================================== #
    current_time = Time.now
    begin
      time_of_that_date = Time.parse("#{this_date} #{this_time_on_that_day}")
    rescue Exception => error
      e orange(name_of_the_lecture)
      pp inner_hash
      pp error
      pp error.class
      pp '^^^ TODO: add this exception specifically'
    end
    if time_of_that_date > maximum_allowed_time_in_the_future
      # =================================================================== #
      # In this case the lecture will be too far into the
      # future, so we will skip it.
      # =================================================================== #
      next
    end
    # ===================================================================== #
    # Ok, here we can use that entry in theory. But we will still have
    # to check whether this is an outdated entry nonetheless. This will
    # be the case when the time_of_that_day lags about a full day behind.
    # ===================================================================== #
    if (current_time - (ONE_DAY - 1) ) > time_of_that_date
      if @debug
        opnn; e 'There is an old date entry at '+sfancy(this_date)+
                ' for '+simp(name_of_the_lecture)
      end
    end
    if hash_weekly_lectures.has_key?(weekday_to_be_used_as_symbol)
      # =================================================================== #
      # Add the dataset next to the main Hash.
      # =================================================================== #
      hash_weekly_lectures[weekday_to_be_used_as_symbol].update(pointer)
    else
      opnn; e 'No key ('+orange('weekday-key')+') was found for `'+
               sfancy(name_of_the_lecture)+'`.'
      opnn; e "The date entry was #{sfancy(this_date.to_s)}"
    end
  }
end

#remove_weekdays_from(i) ⇒ Object

#

remove_weekdays_from

#


19
20
21
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 19

def remove_weekdays_from(i)
  remove_leading_weekday_names_from(i)
end

#report_weekly_lecturesObject

#

report_weekly_lectures

#


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
39
40
41
42
43
44
45
46
47
48
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 12

def report_weekly_lectures
  opnn; e "Next showing the #{mediumpurple('weekly lectures')}:"; e
  _ = @hash_weekly_lectures
  monday    = _[:monday]
  tuesday   = _[:tuesday]
  wednesday = _[:wednesday]
  thursday  = _[:thursday]
  friday    = _[:friday]
  # ======================================================================= #
  # Iterate over the days next.
  # ======================================================================= #
  if show_monday?
    unless monday.empty?
      show_this_weekday(monday, 'Monday')
    end
  end
  if show_tuesday?
    unless tuesday.empty?
      show_this_weekday(tuesday, 'Tuesday')
    end
  end
  if show_wednesday?
    unless wednesday.empty?
      show_this_weekday(wednesday, 'Wednesday')
    end
  end
  if show_thursday?
    unless thursday.empty?
      show_this_weekday(thursday, 'Thursday')
    end
  end
  if show_friday?
    unless friday.empty?
      show_this_weekday(friday, 'Friday')
    end
  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
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
# File 'lib/studium/utility_scripts/week_parser/reset.rb', line 12

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @n_days_into_the_future
  # ======================================================================= #
  @n_days_into_the_future = 36
  # ======================================================================= #
  # === @skip_low_priority_lectures
  #
  # This allows us to skip low-priority lectures. Right now this refers
  # to priority 5 or higher.
  # ======================================================================= #
  @skip_low_priority_lectures = SKIP_LOW_PRIORITY_LECTURES
  # ======================================================================= #
  # === @pad_to_the_right
  # ======================================================================= #
  @pad_to_the_right = PAD_TO_THE_RIGHT
  # ======================================================================= #
  # Handle the upcoming exams via a specialized object next.
  # ======================================================================= #
  # @upcoming_exams_dataset = Studium::Exams::UpcomingExamsDataset.new
  # ======================================================================= #
  # === @dataset
  # ======================================================================= #
  @dataset = Studium.return_sanitized_dataset_from_file_lecture_information
  # ======================================================================= #
  # === @hash_weekly_lectures
  # ======================================================================= #
  @hash_weekly_lectures = {}
  # ======================================================================= #
  # === @debug
  # ======================================================================= #
  @debug = false
  # ======================================================================= #
  # Populate the variable @hash_weekly_lectures.
  # ======================================================================= #
  %i{
    monday tuesday wednesday thursday friday saturday
  }.each {|this_day| @hash_weekly_lectures[this_day] = {} }
  # ======================================================================= #
  # === @array_show_these_days
  #
  # @array_show_these_days tells this class which days to show (and
  # thus, also, which ones to NOT show). Typically we omit saturday
  # and sunday here, but on some universities there may be lectures
  # on a saturday. 
  # ======================================================================= #
  @array_show_these_days = %i(
    monday tuesday wednesday thursday friday
  )
end

#return_exams_on_this_day(dd_mm_yyyy = '23.04.2018') ⇒ Object

#

return_exams_on_this_day

#


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 332

def return_exams_on_this_day(
    dd_mm_yyyy = '23.04.2018'
  )
  start_date = Time.parse(dd_mm_yyyy)
  end_date   = start_date + (ONE_DAY - 1)
  range = start_date .. end_date
  # ======================================================================= #
  # First, obtain the registered entries that denote an (upcoming) exam.
  # ======================================================================= #
  selection = @dataset.select {|name, inner_hash|
    if inner_hash.has_key?('registered')
      upcoming_exam = inner_hash['registered'].first
      upcoming_exam = remove_leading_weeknames(upcoming_exam)
      if upcoming_exam.include? ', Ort'
        upcoming_exam = upcoming_exam.split(', Ort').first.delete(',')
      end
      _ = Time.parse(upcoming_exam).to_i
      range.cover? _
    else
      false
    end
  }
  selection # And return the selection here.
end

#return_german_name_from_this_english_name(i) ⇒ Object

#

return_german_name_from_this_english_name

#


47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 47

def return_german_name_from_this_english_name(i)
  case i.downcase
  when 'monday'
    'Montag'
  when 'tuesday'
    'Dienstag'
  when 'wednesday'
    'Mittwoch'
  when 'thursday'
    'Donnerstag'
  when 'friday'
    'Freitag'
  end
end

#return_n_days(i = 30) ⇒ Object

#

return_n_days

Look n days into the future.

#


112
113
114
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 112

def return_n_days(i = 30)
  Time.now + (ONE_DAY * i)
end

#runObject

#

run (run tag)

#


12
13
14
15
16
# File 'lib/studium/utility_scripts/week_parser/run.rb', line 12

def run
  menu
  select_entries_that_contain_lva_dates
  report_weekly_lectures
end

#select_entries_that_contain_lva_datesObject

#

select_entries_that_contain_lva_dates

We will ONLY select entries that contain lva_dates and were NOT already solved.

#


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
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 68

def select_entries_that_contain_lva_dates
  # ======================================================================= #
  # Select the proper entries next.
  # ======================================================================= #
  lva_dates = dataset?.select {|name_of_the_lecture, hash_dataset|
    if hash_dataset.nil?
      opnn; e "Error for the lecture #{sfancy(name_of_the_lecture)}"
    end
    priority = hash_dataset[:priority]
    # ===================================================================== #
    # Make sure that priority is a number.
    # ===================================================================== #
    unless priority.to_s =~ /^\d+$/
      opnn; e 'Not a number for '+orange('priority')+': '+sfancy(priority.to_s)+
              ' (lecture: '+slateblue(name_of_the_lecture.to_s)+')'
    end
    already_solved = hash_dataset[:already_solved]
    not_already_solved = !already_solved
    if priority.nil? and not_already_solved
      opnn; e "The lecture #{sfancy(name_of_the_lecture)} "\
              "has no registered :priority entry."
    end
    # unless hash_dataset.has_key?(:already_solved) and
    #        (hash_dataset[:already_solved] == true)
    #   unless hash_dataset.has_key? 'lva_dates'
    #     opnn; e 'The lecture '+sfancy(name_of_the_lecture)+' has no '\
    #             'key called lva_dates.'
    #   end
    # end
    # ^^^ this is mostly useful only for debugging
    if @skip_low_priority_lectures and priority and (priority > 4)
      false
    else
      hash_dataset.has_key?('lva_dates') and not_already_solved
    end
  }
  populate_hash_weekly_lectures_with_these_lectures(lva_dates)
end

#show_friday?Boolean

#

show_friday?

#

Returns:

  • (Boolean)


81
82
83
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 81

def show_friday?
  @array_show_these_days.include? :friday
end

#show_helpObject

#

show_help (help tag)

To invoke this method, do:

weekparse --help
#


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/studium/utility_scripts/week_parser/help.rb', line 17

def show_help
  result = <<EOF
Presently, the following options are available:

--debug          # show additional (debug) information
--unrestricted   # do not limit showing lectures based on time
                 # date (thus, +300 days into the future)

You can also pass in the weekday such as "Montag", "Monday" or
"--Monday". The default for @n_days_into_the_future is #{steelblue(@n_days_into_the_future)}.

EOF
  opnn; e result
end

#show_monday?Boolean

#

show_monday? (monday tag, montag tag)

#

Returns:

  • (Boolean)


53
54
55
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 53

def show_monday?
  @array_show_these_days.include? :monday
end

#show_this_weekday(hash_for_this_weekday, name_of_the_day = 'Monday') ⇒ Object

#

show_this_weekday

Use this method to display all lectures on a given day.

#


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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 90

def show_this_weekday(
    hash_for_this_weekday,
    name_of_the_day = 'Monday'
  )
  this_is_the_weekday = hash_for_this_weekday.sort_by {|name_of_the_lecture, inner_hash|
    lva_dates  = inner_hash['lva_dates']
    first_date = remove_leading_weekday_names_from(lva_dates.first)
    Time.parse(first_date.delete(','))
  }
  # ======================================================================= #
  # Next, display the name of the day - also in german.
  # ======================================================================= #
  result = sfancy(
    name_of_the_day+
    ' ('+
    return_german_name_from_this_english_name(name_of_the_day)+
    ')'+':' # Add the german name here.
  ).dup
  # ======================================================================= #
  # Add, in red, the day that is today - if it is today.
  # ======================================================================= #
  if this_weekday_is_today?(name_of_the_day)
    result << ' '+swarn("(This is today, the #{day_month_year})")
  else # Just add when this is assumed to be in the future.
    # ===================================================================== #
    # We calculate the difference based on weekdays.
    # ===================================================================== #
    time_now = Time.now
    n_days_difference = n_days_difference_from_today_to_this_day(
      time_now, name_of_the_day
    )
    result = result.ljust(48)
    result << slateblue(" (in +#{n_days_difference} day")
    result << slateblue('s') unless n_days_difference.to_i == 1
    result << slateblue(')')
    # ===================================================================== #
    # Next, add the date when this will be:
    # ===================================================================== #
    future_time = (time_now - 1) + (n_days_difference * ONE_DAY)
    future_time_in_dd_mm_yyyy = "(#{return_day_month_year(future_time)})"
    colourized_future_time = sfancy(future_time_in_dd_mm_yyyy)
    result << " #{colourized_future_time}"
  end
  e result; e # <- Display the weekday here.
  is_a_holiday = false
  if future_time_in_dd_mm_yyyy
    upcoming_exams = exams_on_this_day(
      future_time_in_dd_mm_yyyy.delete('()')
    )
  end
  if upcoming_exams
    # ===================================================================== #
    # In this case, display the exams. However had, since as of June
    # 2018, we will display only those exams for which we are
    # registered.
    # ===================================================================== #
    leading_notifier = swarn('    [REGISTERED FOR THIS EXAM]')
    upcoming_exams = upcoming_exams.select {|name_of_the_lecture, inner_hash|
      inner_hash.has_key? 'registered_for_an_upcoming_exam_at'
    }
    upcoming_exams.each {|name_of_the_lecture, inner_hash|
      exam_time = inner_hash['exams'].first.split(',').last.strip
      this_university = inner_hash[:university]
      colourized_this_university = powderblue(' '+this_university)
      colourized_name_of_the_lecture = slateblue(
        name_of_the_lecture.ljust(69)
      )
      e leading_notifier+' '+
        colourized_name_of_the_lecture+' '+
        mediumslateblue('['+exam_time+']')+
        colourized_this_university
    }
  end
  this_is_the_weekday.each {|name_of_the_lecture, inner_hash|
    lva_dates    = inner_hash['lva_dates']
    priority     = inner_hash[:priority]
    lecture_type = "[#{inner_hash[:type]}]"
    first_date   = lva_dates.first.strip # <- Depends on the variable lva_dates set before.
    if priority.nil?
      opnn; e swarn('No priority entry was found for ')+
              sfancy(name_of_the_lecture)
    end
    # ===================================================================== #
    # First display an exam, if there is one on this day.
    # ===================================================================== #
    dd_mm_yyyy = first_date
    if dd_mm_yyyy.include? ', '
      dd_mm_yyyy = dd_mm_yyyy.split(', ').first.strip
    end
    is_a_holiday = ::Studium.is_this_day_a_holiday? dd_mm_yyyy
    # ===================================================================== #
    # If it is already over then we will not display that lecture at
    # all. The user is assumed to correct entries in the file
    # lecture_information.yml on his/her own.
    # ===================================================================== #
    if (Time.now - (ONE_DAY - 1)) > Time.parse(dd_mm_yyyy)
      next # Skip to the next entry in this case.
    end
    # ===================================================================== #
    # === Handle upcoming exams first
    #
    # Look for upcoming exams from the file exams.yml. If found,
    # process them and then delete that match.
    # ===================================================================== #
    # Currently disabled.
    # orange_block = orange(
    #    (try_to_infer_the_name_of_the_lecture_from_this_line(line)+
    #     swarn(' [EXAM]')).ljust(PAD_TO_THE_RIGHT - 1)
    #  )
    # =================================================================== #
    # We will display that exam-entry additionally.
    # =================================================================== #
    # e '  '+colourize_lecture_day(lecture_date, '1')+' '+
    #  orange_block+' '+colourized_priority('1', :red)
    # ===================================================================== #
    # Next display the entry. The name of the lecture will be
    # colourized in an orange colour. The beginning of that String,
    # that is the very most left side, will be colourized in a
    # greenish colour usually.
    # ===================================================================== #
    expanded_lecture_line = '  '.dup
    if is_a_holiday
      # =================================================================== #
      # Then this is a holiday.
      # =================================================================== #
      official_holiday_string = '  [Official Holiday]'
      expanded_lecture_line << crimson("#{official_holiday_string} ")
    end
    expanded_lecture_line << colourize_lecture_day(first_date, priority)+' '
    # ===================================================================== #
    # Build up the expanded lecture line here, based on priority.
    # ===================================================================== #
    case priority
    when 1 # Only handle priority 1 in a different colour.
      expanded_lecture_line << orange(
        (name_of_the_lecture+' '+chocolate(lecture_type)).ljust(@pad_to_the_right)
      )+' '+colourized_priority(priority, :honour_priority_value) 
    else
      expanded_lecture_line << darkorange(
        (name_of_the_lecture+' '+chocolate(lecture_type)).ljust(@pad_to_the_right)
      )+' '+colourized_priority(priority, :honour_priority_value) # <- Colourize the priority ranking.
    end
    e expanded_lecture_line
  }; e
end

#show_thursday?Boolean

#

show_thursday?

#

Returns:

  • (Boolean)


74
75
76
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 74

def show_thursday?
  @array_show_these_days.include? :thursday
end

#show_tuesday?Boolean

#

show_tuesday?

#

Returns:

  • (Boolean)


60
61
62
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 60

def show_tuesday?
  @array_show_these_days.include? :tuesday
end

#show_wednesday?Boolean

#

show_wednesday?

#

Returns:

  • (Boolean)


67
68
69
# File 'lib/studium/utility_scripts/week_parser/show.rb', line 67

def show_wednesday?
  @array_show_these_days.include? :wednesday
end

#this_weekday_is_today?(name_of_the_day) ⇒ Boolean

#

this_weekday_is_today?

#

Returns:

  • (Boolean)


360
361
362
363
364
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 360

def this_weekday_is_today?(name_of_the_day)
  # time_now = ::Time.now
  weekday_today = english_weekday?
  name_of_the_day.start_with?(weekday_today)
end

#try_to_infer_the_name_of_the_lecture_from_this_line(line) ⇒ Object

#

try_to_infer_the_name_of_the_lecture_from_this_line

This method will attempt to guess the name of the lecture, based on a line that is stored in the file 'exams.yml'.

#


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/studium/utility_scripts/week_parser/misc.rb', line 259

def try_to_infer_the_name_of_the_lecture_from_this_line(line)
  result = ''.dup
  # ======================================================================= #
  # The following rexes also must match towards lines such as:
  #   226.024, Chemie im Bauwesen
  # ======================================================================= #
  regex_for_lva_id = /\d{4}, (\d{1,3}\.?\d{1,3})/
  line =~ regex_for_lva_id
  lva_id = $1.to_s.dup
  # ======================================================================= #
  # Next search on the main dataset for the file lecture information.
  # ======================================================================= #
  scanned = dataset_lecture_information?.select {|name_of_the_lecture, inner_hash|
    name_of_the_lecture.start_with? lva_id
  }
  if scanned.size == 1 # If we have exactly one match, add it.
    result << scanned.keys.first
  else
    most_likely_lecture_name = @upcoming_exams_dataset.return_most_likely_lecture_name_from_this_line(line)
    if lva_id[2,1] == '0' # Assume that this could be a lecture at the university of vienna.
      new_lva_id = lva_id.dup
      new_lva_id[2,1] = '1'
      scanned = dataset_lecture_information?.select {|name_of_the_lecture, inner_hash|
        name_of_the_lecture.start_with? new_lva_id
      }
      unless scanned.empty?
        # ================================================================= #
        # Ok so we found something, probably more than one result. We
        # do another round of selection, against the naem of the lecture.
        # ================================================================= #
        scanned = dataset_lecture_information?.select {|name_of_the_lecture, inner_hash|
          name_of_the_lecture.include? most_likely_lecture_name
        }
        result << scanned.keys.first unless scanned.empty?
      end
    else
      if scanned.size == 0
        e swarn('DEBUG! No results were found. This is not good.')
        e 'The line that was faulty, was: '+sfancy(line)
      else # Else we have at the least one more lecture.
        new_selection = scanned.select {|key, value|
          key.include? most_likely_lecture_name
        }
        if new_selection.empty?
          e swarn('DEBUG! We found ')+sfancy(scanned.size.to_s)+
            swarn(' results. This has to be NARROWED DOWN to '\
                'only one entry. (March 2018)')
        else
          result << new_selection.keys.first unless new_selection.empty?
        end
      end
    end
  end
  return result.strip
end