Class: Studium::Base

Inherits:
Object
  • Object
show all
Includes:
Colours
Defined in:
lib/studium/base/run.rb,
lib/studium/base/misc.rb,
lib/studium/base/mode.rb,
lib/studium/base/opnn.rb,
lib/studium/base/time.rb,
lib/studium/base/reset.rb,
lib/studium/base/cliner.rb,
lib/studium/base/editor.rb,
lib/studium/base/obtain.rb,
lib/studium/base/colours.rb,
lib/studium/base/esystem.rb,
lib/studium/base/replace.rb,
lib/studium/base/unicode.rb,
lib/studium/base/encoding.rb,
lib/studium/base/constants.rb,
lib/studium/base/prototype.rb,
lib/studium/base/readlines.rb,
lib/studium/base/word_wrap.rb,
lib/studium/base/curriculum.rb,
lib/studium/base/src_dir_at_home.rb,
lib/studium/base/minimal_prototype.rb,
lib/studium/base/commandline_arguments.rb,
lib/studium/base/directory_to_the_exam_topics.rb

Overview

Studium

Direct Known Subclasses

Afterburn, AskQuestionFromAlias, AskQuestionFromGroupedThemes, AskQuestionFromLastTopic, AskRandomQuestion, AttributeLecturesToUniversity, AudioStats, AutoStud, AutopurgeThisLectureDate, Studium::BOKU::ShowThreePillarsOfTheseLectures, Studium::BOKU::ThreePillars, BokuBiotechnologyAllMasterLectures, BokuEctsSplitter, Calendar, CheckCurriculumForCorrectSeparationOfBachelorAndMaster, CheckDescriptionOfTheseLectures, CheckForAllExamTopicsBeingRegistered, CheckTheLectureInformationFile, CleanUpLectureDate, Commandline, CreateDatabase, CreatePdfFileForThisExamTopic, CurrentLecturesBelongingToBothBachelorAndMasterCurriculum, CurrentlyParticipatingInTheseLectures, Curricula::CurriculumAsString, Curricula::DetermineElectiveCoursesInThisCurriculum, Curricula::DisplayBachelorCurricula, Curricula::Mitteilungsblätter, Curricula::Modules::DisplayOnTheCommandline, Curriculum, CurriculumComparer, CurriculumModuleDisplayer, DetermineCurricula, DisplayLectureUrl, EctsParser, EctsPerUniversity, EctsScanner, EctsToUniversityParser, Erledigt, Exams::AskExamFromTheUpcomingExamsPool, Exams::AskExamTopicQuestion, Exams::AskQuestionFromAnyOfTheStillMissingLectures, Exams::CreateCsvPassedExamsFile, Exams::Cycle, Exams::DesignateTenRandomExamTopics, Exams::Exam, Exams::ExamQuestion, Exams::ExamRegistrationAt, Exams::ExamStatisticsFromThisFile, Exams::ExamTopics, Exams::LastExams, Exams::LecturesWithoutExamEntry, Exams::MandatoryContinuousAssessment, Exams::NewQuestionsPerYear, Exams::NextExam, Exams::NextExams, Exams::OpenExamAssociatedUrl, Exams::OpenLastExamQuestionAskedFile, Exams::Pruefung, Exams::PublishMyExams, Exams::PushSolvedQuestionsOnTop, Exams::QuestionsSolvedFromDayToDay, Exams::RepeatLastQuestion, Exams::ShowThemes, Exams::Solved, Exams::UpcomingExams, Exams::UpcomingExamsAtTheBoku, Exams::UpcomingExamsDataset, Exams::UploadExamTopics, ExamsPerMonth, ExamsThisWeek, ExpandTimeRange, FindDuplicateLectures, FinishedExamsAtThisUniversity, FixExamDates, ForeignLanguagePercentage, GenerateRegex, GenerateSpreadsheet, Holidays, IndividualResolvePracticalCoursesDateConflicts, LastEntryIsCurriculum, LectureDownloader, LecturesAttributedToUniversities, Log::StoreLastQuestionAskedIntoFile, LvaNummer, MandatoryLecturesInThisMonth, MoveTheLastExamQuestionToTheTopOfTheFile, NEctsInTheseLectures, NExamsInTheseTopics, NameOfThisLvaId, NewStud, NextWeek, NochZuAbsolvieren, OpenLastExamQuestionUrlLinkViaTheBrowser, ParseLvaDates, PassedEctsPerYear, PassedPrüfungsimmanenteCourses, PrepareIndividualCurriculum, Priority, PriorityPoints, RandomCurriculumCreator, ReportOutdatedTimetableEntries, ReportTotalAmountOfQuestionsAndAnswersFor, ReportWhetherThisLectureIsRegisteredInTheFileLectureInformation, ResolvePracticalCoursesDateConflicts, ReturnNEctsFromThisUrl, SanitizeThisStringContainingTheLvaDates, ScrapeRemoteUniversityUrl, SearchFor_nECTS, SemesterContainer, Semesterplaner, SetAliasesBasedOnThisFile, ShowAllLectures, ShowAllPassedExamsOfThisUniversity, ShowAllPassedMasterLectures, ShowAllSteopLectures, ShowBacklogOfExams, ShowCompletedEctsInAllCurricula, ShowConflictingLvaLectures, ShowDescriptionsOfLecturesBelongingToThisModule, ShowLecturers, ShowLectures, ShowLecturesFittingToThisLanguage, ShowLecturesFittingToThisTheme, ShowLecturesOfThisCurriculum, ShowLecturesOfThisCurriculumId, ShowLecturesOnTheCommandline, ShowLecturesOnThisDay, ShowLvaDatesOfThisLecture, ShowNextExamsFor, ShowOutdatedLvaDates, ShowPassedCreditsPerCurriculum, ShowSolvedEnglishLectures, ShowSolvedPercentageAmongTheRegisteredCurricula, ShowTheAssociatedLecturesForTheIndividualCurriculum, ShowUpcomingExams, SimpleTotalEctsPoints, SolveAllQuestionsFromThisTopic, SolvedEcts, SolvedEctsPerUniversity, SortedIndividualCurricula, Statistics::BestExamMonths, Statistics::DetermineExamStatisticsFromThisFile, Statistics::MaxStats, Statistics::ReportHowManyEctsPointsPerCurriculumWereCompleted, Statistics::ReportHowManyExamQuestionsWereAnswered, Statistics::TopStats, SteopLecturesInThisCurriculum, SteopLvaDates, StillMissing, Studienkennzahl, StudiumSkeleton, Stundenplan, SumOfEcts, SyncStudiumRelevantEntriesOneLevelDownwards, Ufind, UnsolveAllQuestionsFromThisTopic, UpcomingMandatoryPresenceCourses, Vorbesprechungen, WeekParser, WeekdayParser, WeeklySchedule, Wochenplanung

Constant Summary collapse

COMMON_YEAR_DAYS_IN_MONTH =
#

COMMON_YEAR_DAYS_IN_MONTH

This constant has the days per month, for the whole year.

It will not honour leap years properly, though.

#
[
  nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
]
GRAY =
#

GRAY

#
::Colours::GRAY
COLOURS =
#

COLOURS

This could go into studium/base/constants.rb, but it seems to fit better here as a “pointer” towards colours.

#
::Colours::AllColourMethods
ARRAY_HTML_COLOURS_IN_USE =
#

ARRAY_HTML_COLOURS_IN_USE

Next, we will define the html-colours.

#
%w(
  aquamarine
  chocolate
  cadetblue
  coral
  cornflowerblue
  crimson
  cyan
  darkblue
  darkgoldenrod
  darkred
  darkgreen
  darkkhaki
  darkolivegreen
  darkorange
  darkseagreen
  darkslateblue
  darkslategray
  darkturquoise
  mediumseagreen
  forestgreen
  brown
  silver
  deepskyblue
  firebrick
  gold
  goldenrod
  indianred
  khaki
  lavender
  lawngreen
  lightcoral
  lightgreen
  lightseagreen
  lightslategrey
  lightred
  lightskyblue
  lime
  mediumpurple
  mediumspringgreen
  mediumvioletred
  mediumturquoise
  mediumslateblue
  mintcream
  orange
  orchid
  palegoldenrod
  peru
  lightslategray
  seagreen
  saddlebrown
  sandybrown
  steelblue
  teal
  turquoise
  skyblue
  tomato
  oldlace
  olivedrab
  mediumblue
  lightblue
  limegreen
  orangered
  palegreen
  plum
  powderblue
  slateblue
  salmon
  red
  sienna
  tan
  yellow
  palevioletred
  thistle
  slategray
  mediumaquamarine
  darkcyan
  springgreen
  violet
  whitesmoke
  olive
  paleturquoise
  rosybrown
  royalblue
  yellowgreen
)
UNICODE_RIGHT_ARROW =
#

UNICODE_RIGHT_ARROW

#
''
NAMESPACE =
#

NAMESPACE

#
inspect
CHECK_FOR_INCORRECT_ENTRIES_IN_THE_QUESTION_ANSWER_FILE_THAT_SHOULD_BE_COMMENTS =
#

CHECK_FOR_INCORRECT_ENTRIES_IN_THE_QUESTION_ANSWER_FILE_THAT_SHOULD_BE_COMMENTS

If the following constant is set to true, then a certain method will check whether lines start with e. g. “t#” rather than “#”. This is an indication that some typo is in that exam-questions file, which we then can auto-correct.

#
true
LEFT_PADDING =
#

Base::LEFT_PADDING

The default padding (for showing the answer to an exam question) is 4 spaces since as of July 2020. In November 2020 2 spaces are now tried.

#
' ' * 2
N_CHARACTERS_PER_LINE =
#

Base::N_CHARACTERS_PER_LINE

If an answer exceeds the following threshold value, then we will chop some bits off of it. The reason why we have defined this here in class Base is because at the least two other classes that are part of the Exam namespace, require this.

#
78

Instance Method Summary collapse

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, sfile, #sfile, simp, slateblue, steelblue, #steelblue, swarn, #teal, turquoise, use_colours?, use_this_colour_for_exam_answers, use_this_colour_for_exam_questions, #yellow

Instance Method Details

#add_proper_year_entry_to_this_line(line) ⇒ Object

#

add_proper_year_entry_to_this_line

This method will add a proper year entry to a line. It will either append a year entry - or, which may be more useful, try to insert the year-entry into a position that fits. The latter will make use of a regex.

A test string for the latter is the following:

"Dienstag   02.10. 11:30-13:00 UZA2 Hörsaal 5 Raum 2Z202 2.OG"
#


235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/studium/base/time.rb', line 235

def add_proper_year_entry_to_this_line(line)
  result = line.dup
  current_year = Time.now.year
  use_this_regex = # See: http://rubular.com/r/xV0yNSYhWW
    /^(.+)(\d{2}\.\d{1,2}\.) (\d{1,2}:\d{1,2}(-| )?\d{1,2}:\d{1,2})(.+)$/
  if result =~ use_this_regex
    result.sub!(use_this_regex, '\1\2'+current_year.to_s+', \3\5')
  else # this here is the simpler case
    result << current_year # This is the variant that will simply append.
  end
  result
end

#already_solved_this_lva_number?(i) ⇒ Boolean

#

already_solved_this_lva_number?

#

Returns:

  • (Boolean)


672
673
674
# File 'lib/studium/base/misc.rb', line 672

def already_solved_this_lva_number?(i)
  Studium.already_solved_this_lva_number?(i)
end

#append_what_into(what, into) ⇒ Object

#

append_what_into (append tag)

Use this method to save data into a specific file.

#


623
624
625
# File 'lib/studium/base/misc.rb', line 623

def append_what_into(what, into)
  Studium.append_what_into(what, into)
end

#available_topics_as_short_nameObject Also known as: available_topics?, return_all_exam_topics

#

available_topics_as_short_name

#


136
137
138
# File 'lib/studium/base/misc.rb', line 136

def available_topics_as_short_name
  ::Studium::Exams.all_topics_as_short_name.sort
end

#average_grade(i = :default, round_to = 2) ⇒ Object

#

average_grade

#


759
760
761
762
763
764
# File 'lib/studium/base/misc.rb', line 759

def average_grade(
    i        = :default,
    round_to = 2 # ← Round to two numbers.
  )
  Studium.average_grade(i, round_to)
end

#bachelor_master_or_diploma(this_lecture, dataset = nil) ⇒ Object

#

bachelor_master_or_diploma

For a given solved lecture, we will determine whether it belongs to a Bachelor (B), Master (M) or Diploma (D) curriculum.

For the line:

13.05.2020 | 1.0 |  1.0 | 1 |   BOKU  |   M  |   SE  |   940003   | 2020S | Emerging Topics in RNA Biology (in Eng.)
      0       1      2    3      4        5

It would be at 5.

#


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/studium/base/curriculum.rb', line 97

def bachelor_master_or_diploma(
    this_lecture, dataset = nil
  )
  if dataset.nil? and File.exist? FILE_PASSED_EXAMS_PER_MONTH
    dataset = File.readlines(FILE_PASSED_EXAMS_PER_MONTH).reject {|line|
      line.strip.empty? or
      line.strip.start_with?('#')
    }
  end
  selection = dataset.select {|line|
    splitted = this_lecture.split(' ')
    lecture_id = splitted.first
    course_name = splitted[1..-1].join(' ').strip
    line.include?(lecture_id) and
    line.include?(course_name)
  }
  if selection.empty?
    '(unknown)'
  else
    selection = selection.first
    return selection.split('|')[5].strip 
  end
end

#base_dir?Boolean Also known as: log_dir?

#

base_dir?

This is the log dir - where we “operate on”.

#

Returns:

  • (Boolean)


665
666
667
# File 'lib/studium/base/misc.rb', line 665

def base_dir?
  Studium.log_dir?
end

#be_silentObject Also known as: be_quiet

#

be_silent

#


209
210
211
# File 'lib/studium/base/misc.rb', line 209

def be_silent
  @be_verbose = false
end

#be_verbose?Boolean

#

be_verbose?

#

Returns:

  • (Boolean)


805
806
807
# File 'lib/studium/base/misc.rb', line 805

def be_verbose?
  @be_verbose
end

#beautiful_url(i) ⇒ Object

#

beautiful_url

Until 10.12.2019 this exclusively used BeautifulUrl.

Since as of 10.12.2019, this method will actually tap into Studium.return_url_from if it is registered.

#


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/studium/base/misc.rb', line 45

def beautiful_url(i)
  unless Studium.respond_to? :is_this_url_registered?
    require 'studium/utility_scripts/return_remote_homepage_of_this_lecture.rb'
  end
  if Studium.is_this_url_registered?(i)
    i = Studium.return_url_from(i)
  else
    i = BeautifulUrl[i]
  end
  if i.is_a? Array
    i = i.first
  end
  return i
end

#change_directory(i = Dir.pwd) ⇒ Object Also known as: cd

#

change_directory

#


445
446
447
448
449
# File 'lib/studium/base/misc.rb', line 445

def change_directory(
    i = Dir.pwd
  )
  FileUtils.chdir(i)
end

#cheering_personObject Also known as: cheering_person?, cheering_dude?

#

cheering_person

#


573
574
575
# File 'lib/studium/base/misc.rb', line 573

def cheering_person
  '\o/'
end

#cliner(which_token_to_use = :default_token, use_this_colour = nil) ⇒ Object

#

cliner (cliner tag)

This method can be used such as in the following example, if a specific colour is wanted:

cliner('*', :mediumaquamarine)
#


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/base/cliner.rb', line 20

def cliner(
    which_token_to_use = :default_token,
    use_this_colour    = nil
  )
  if which_token_to_use.is_a? Hash # Treat Hashes specially.
    if which_token_to_use.has_key? :colours
      use_this_colour = which_token_to_use.delete(:colours)
      which_token_to_use = :default_token
    end
  end
  case which_token_to_use
  when :default_token
    which_token_to_use = '='
  end
  if block_given?
    yielded = yield
    case yielded
    # === :unicode
    when :unicode
      begin
        require 'roebe/toplevel_methods/unicode/unicode_block_elements.rb'
        which_token_to_use = Roebe.horizontal_double_bar.dup
      rescue LoadError; end
    end
  end
  result = (which_token_to_use * 80)
  if use_this_colour.is_a? Symbol
    if use_this_colour.to_s.include?('konsole_') or
       is_this_colour_a_html_colour?(use_this_colour)
      unless use_this_colour.to_s.include? '_colour_'
        use_this_colour = use_this_colour.to_s
        use_this_colour.sub!(/_/,'_colour_')
      end
      result = COLOURS.send(use_this_colour, result)
    end
  end
  e result
end

#colour_for_ects_points(i = '') ⇒ Object Also known as: colourize_ects, colour_ects

#

colour_for_ects_points

#


235
236
237
# File 'lib/studium/base/colours.rb', line 235

def colour_for_ects_points(i = '')
  ::Studium.colour_for_ects_points(i)
end

#colourize_percentage(i) ⇒ Object

#

colourize_percentage

This method should be used when we wish to display percentage values on the commandline.

#


212
213
214
215
# File 'lib/studium/base/colours.rb', line 212

def colourize_percentage(i)
  return seagreen(i) if use_colours? # Used to be cadetblue.
  return i
end

#commandline_arguments?Boolean Also known as: commandline?

#

commandline_arguments?

#

Returns:

  • (Boolean)


26
27
28
# File 'lib/studium/base/commandline_arguments.rb', line 26

def commandline_arguments?
  @commandline_arguments
end

#commandline_arguments_joinedObject Also known as: return_commandline_arguments_as_string, commandline_arguments_as_string, commandline_arguments_as_string?, commandline_string?, commandline_as_string, return_original_input_as_string

#

commandline_arguments_joined

This method will, essentially, return all commandline-arguments as a String.

#


46
47
48
# File 'lib/studium/base/commandline_arguments.rb', line 46

def commandline_arguments_joined
  @commandline_arguments.join(' ').strip
end

#commandline_arguments_with_hyphens?Boolean Also known as: return_commandline_arguments_with_leading_hyphens, return_hyphened_commandline_arguments

#

commandline_arguments_with_hyphens?

This method will select all the commandline arguments that begin with '–' hyphens.

#

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/studium/base/commandline_arguments.rb', line 61

def commandline_arguments_with_hyphens?
  @commandline_arguments.select {|entry|
    entry.start_with?('--')
  }
end

#convert_this_array_of_lectures_into_the_full_dataset(i) ⇒ Object

#

convert_this_array_of_lectures_into_the_full_dataset

The purpose of this method is to turn an Array that holds Strings such as “941111 Genetische Ressourcen von Nutzpflanzen” into the corresponding dataset.

This method will return a Hash if everything went fine.

#


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

def convert_this_array_of_lectures_into_the_full_dataset(i)
  if i.is_a? Array
    if Studium.main_dataset?.nil?
      Studium.initialize_main_dataset
    end
    _ = Studium.main_dataset?
    hash = {}
    i.map {|course_id_and_course_name|
      if _.has_key?(course_id_and_course_name)
        hash[course_id_and_course_name] = _[course_id_and_course_name]
      end
    }
    hash
  else
    raise 'This method only accepts an Array as input.'
  end
end

#copy(from, to) ⇒ Object Also known as: copy_file

#

copy (copy tag)

#


908
909
910
911
912
913
914
915
916
# File 'lib/studium/base/misc.rb', line 908

def copy(from, to)
  if from.is_a? Array
    from.each {|entry|
      copy(entry, to)
    }
  else
    FileUtils.copy(from, to)
  end
end

#cprubyObject

#

cpruby

#


840
841
842
843
844
845
846
# File 'lib/studium/base/misc.rb', line 840

def cpruby
  base_dir = ENV['USERS']
  base_dir = '/home' if base_dir.nil?
  path_to_setup_rb_file =
    "#{RUBY_SRC_DIR}roebe/lib/roebe/setup/setup.rb"
  copy(path_to_setup_rb_file, '.')
end

#create_directory(i) ⇒ Object Also known as: mkdir

#

create_directory

#


438
439
440
# File 'lib/studium/base/misc.rb', line 438

def create_directory(i)
  FileUtils.mkdir_p(i)
end

#create_file(i) ⇒ Object Also known as: touch

#

create_file

#


379
380
381
# File 'lib/studium/base/misc.rb', line 379

def create_file(i)
  FileUtils.touch(i)
end

#csv_file?Boolean

#

csv_file?

#

Returns:

  • (Boolean)


419
420
421
# File 'lib/studium/base/misc.rb', line 419

def csv_file?
  PASSED_EXAMS_PER_MONTH
end

#current_month?Boolean Also known as: month?, return_current_month_as_a_number

#

current_month?

Show us the current month, as Integer. For example, for April, this method would return the number 4.

#

Returns:

  • (Boolean)


549
550
551
# File 'lib/studium/base/time.rb', line 549

def current_month?
  Time.now.strftime('%m').to_i
end

#datum?Boolean

#

datum?

#

Returns:

  • (Boolean)


27
28
29
# File 'lib/studium/base/time.rb', line 27

def datum?
  Studium.datum? # ← Available in "studium/toplevel_methods/time.rb".
end

#day_month_year(use_this_time = Time.now) ⇒ Object Also known as: today?, return_day_month_year, dd_mm_yyyy, return_dd_mm_yyyy

#

day_month_year

This method will return a dd.mm.yyyy notation.

If you need to find out whether the given input-day is today, then use the method called .is_this_day_today?, defined in this file.

An example for this will be:

03.04.2020
#


370
371
372
373
374
375
376
377
378
# File 'lib/studium/base/time.rb', line 370

def day_month_year(
    use_this_time = Time.now
  )
  if use_this_time.is_a? Time
    use_this_time.strftime('%d.%m.%Y')
  else
    use_this_time
  end
end

#debug?Boolean

#

debug?

#

Returns:

  • (Boolean)


202
203
204
# File 'lib/studium/base/misc.rb', line 202

def debug?
  @debug
end

#delete_file(i) ⇒ Object

#

delete_file

#


864
865
866
# File 'lib/studium/base/misc.rb', line 864

def delete_file(i)
  File.delete(i) if File.exist? i
end

#directory_of_the_exam_topics?Boolean

#

directory_to_the_exam_topics?

#

directory_of_the_exam_topics?

Returns:

  • (Boolean)


800
801
802
# File 'lib/studium/base/misc.rb', line 800

def directory_to_the_exam_topics?
  Studium.directory_to_the_exam_topics?
end

#directory_to_my_exam_topicsObject

#

directory_to_my_exam_topics

#


790
791
792
# File 'lib/studium/base/misc.rb', line 790

def directory_to_my_exam_topics
  Studium.directory_to_my_exam_topics
end

#directory_to_the_exam_topics?Boolean Also known as: exam_topics_directory?, exam_topic_directory?

#

directory_to_the_exam_topics?

This method will point to the directory where all exam topics are normally kept; it is simply a “wrapper-method”.

#

Returns:

  • (Boolean)


797
798
799
# File 'lib/studium/base/misc.rb', line 797

def directory_to_the_exam_topics?
  Studium.directory_to_the_exam_topics?
end

#disable_coloursObject Also known as: no_colours

#

disable_colours

#


190
191
192
# File 'lib/studium/base/colours.rb', line 190

def disable_colours
  @use_colours = false
end

#disable_colours_globallyObject

#

disable_colours_globally

Disable the colours globally, that is, on a per-project basis.

#


153
154
155
# File 'lib/studium/base/colours.rb', line 153

def disable_colours_globally
  ::Studium.disable_colours # Delegate to the module-method here.
end

#do_not_be_verboseObject

#

do_not_be_verbose

#


234
235
236
# File 'lib/studium/base/misc.rb', line 234

def do_not_be_verbose
  @be_verbose = false
end

#do_not_use_opnObject

#

do_not_use_opn

#


42
43
44
# File 'lib/studium/base/opnn.rb', line 42

def do_not_use_opn
  @use_opn = false
end

#do_these_curricula_include_both_a_bachelor_and_a_master_curriculum?(i) ⇒ Boolean

#

do_these_curricula_include_both_a_bachelor_and_a_master_curriculum?(i)

The input to this method should be an Array.

#

Returns:

  • (Boolean)


219
220
221
222
223
224
225
226
# File 'lib/studium/base/curriculum.rb', line 219

def do_these_curricula_include_both_a_bachelor_and_a_master_curriculum?(i)
  result = false
  if i.any? {|entry| entry.start_with?('033')} and
     i.any? {|entry| entry.start_with?('066')}
    result = true
  end
  return result
end

#does_this_line_include_a_german_weekday?(i) ⇒ Boolean

#

does_this_line_include_a_german_weekday?

#

Returns:

  • (Boolean)


437
438
439
440
441
# File 'lib/studium/base/time.rb', line 437

def does_this_line_include_a_german_weekday?(i)
  ARRAY_GERMAN_WEEKDAYS.any? {|this_german_weekday|
    i.include? this_german_weekday
  }
end

#does_this_line_include_a_html_colour?(i) ⇒ Boolean

#

does_this_line_include_a_html_colour?

#

Returns:

  • (Boolean)


48
49
50
# File 'lib/studium/base/word_wrap.rb', line 48

def does_this_line_include_a_html_colour?(i)
  ::Colours.does_this_line_include_a_html_colour?(i)
end

#e(i = '') ⇒ Object

#

e (e tag)

#


26
27
28
# File 'lib/studium/base/minimal_prototype.rb', line 26

def e(i = '')
  puts i
end

#ecomment(i = '') ⇒ Object

#

ecomment

#


160
161
162
# File 'lib/studium/base/colours.rb', line 160

def ecomment(i = '')
  ::Colours.ecomment(i)
end

#editor?Boolean

#

editor?

#

Returns:

  • (Boolean)


24
25
26
# File 'lib/studium/base/editor.rb', line 24

def editor?
  Studium.editor?
end

#ee(i = '') ⇒ Object

#

ee (ee tag)

This is just a wrapper over print, essentially.

#


35
36
37
# File 'lib/studium/base/minimal_prototype.rb', line 35

def ee(i = '')
  print i
end

#enable_coloursObject

#

enable_colours

#


183
184
185
# File 'lib/studium/base/colours.rb', line 183

def enable_colours
  @use_colours = true
end

#enable_colours_globallyObject

#

enable_colours_globally

#


144
145
146
# File 'lib/studium/base/colours.rb', line 144

def enable_colours_globally
  ::Studium.enable_colours
end

#enable_debugObject Also known as: do_debug

#

enable_debug

#


195
196
197
# File 'lib/studium/base/misc.rb', line 195

def enable_debug
  @debug = true
end

#encoding?Boolean Also known as: main_encoding?, main_encoding_to_use?, use_this_encoding?, encoding_to_use?

#

encoding?

This method will return the main encoding in use, by “pointing” towards the constant that keeps track of this.

#

Returns:

  • (Boolean)


19
20
21
# File 'lib/studium/base/encoding.rb', line 19

def encoding?
  ::Studium.main_encoding?
end

#english_to_german_weekday(english_day) ⇒ Object

#

english_to_german_weekday

This method will simply convert e. g. “Monday” into “Montag”. In other words: it will convert from the english name for a day into the german name of that day.

#


410
411
412
# File 'lib/studium/base/time.rb', line 410

def english_to_german_weekday(english_day)
  ENGLISH_TO_GERMAN_WEEKDAYS[english_day]
end

#ensure_main_encoding(i) ⇒ Object Also known as: use_correct_encoding, sanitize_encoding

#

ensure_main_encoding

This method will ensure that we will have the right encoding set.

#


31
32
33
# File 'lib/studium/base/encoding.rb', line 31

def ensure_main_encoding(i)
 ::Studium.ensure_main_encoding(i)
end

#ensure_that_the_log_directory_existsObject

#

ensure_that_the_log_directory_exists

This method will try to make sure that the log directory exists.

#


428
429
430
431
432
433
# File 'lib/studium/base/misc.rb', line 428

def ensure_that_the_log_directory_exists
  _ = log_dir?
  unless File.directory? _
    mkdir(_)
  end
end

#eparse(i) ⇒ Object

#

eparse

The colours for this method are defined within the method body.

We could also delegate to ::Colours.eparse() instead.

#


265
266
267
268
269
270
271
272
273
274
275
# File 'lib/studium/base/colours.rb', line 265

def eparse(i)
  if use_colours?
    token = '#'
    if i.include? token
      splitted = i.split(token)
      splitted[-1] = olive(splitted[-1])
      i = splitted.join(royalblue(token))
    end
  end
  e i
end

#erev(i) ⇒ Object

#

erev

#


310
311
312
# File 'lib/studium/base/colours.rb', line 310

def erev(i)
  e "#{rev}#{i}"
end

#esystem(i) ⇒ Object

#

esystem

#


15
16
17
18
19
20
21
# File 'lib/studium/base/esystem.rb', line 15

def esystem(i)
  if i.is_a? Array
    i.each {|entry| esystem(entry) }
  else
    Studium.esystem(i)
  end
end

#etomato(i) ⇒ Object

#

etomato

#


243
244
245
# File 'lib/studium/base/colours.rb', line 243

def etomato(i)
  e tomato(i)
end

#exit_program(make_newline = :no_newline) ⇒ Object

#

exit_program (exit tag)

Use this method to exit from the program. It is a general “exit-operation” for classes in the Studium project. The reason as to why we don't just simply use exit() is so that we

#


53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/studium/base/minimal_prototype.rb', line 53

def exit_program(
    make_newline = :no_newline
  )
  case make_newline
  # ======================================================================= #
  # === :no_newline
  # ======================================================================= #
  when :no_newline
    make_newline = false
  end
  e(N) if make_newline
  exit # Exit here.
end

#expand_topic(i) ⇒ Object Also known as: find_corresponding_exam_title

#

expand_topic

This will expand e. g. 'allgemeine_genetik' to 'Allgemeine Genetik'.

#


92
93
94
# File 'lib/studium/base/misc.rb', line 92

def expand_topic(i)
  Studium.find_corresponding_exam_title(i)
end

#extract_dd_mm_yyyy(i) ⇒ Object Also known as: extract_ddmmyyyy

#

extract_dd_mm_yyyy

This method can be used to extract the dd.mm.yyyy format from the given input at hand. It will discard everything else.

So, for instance, if the input is “15.10.2018, 09:00-18:00” then this method will return only “15.10.2018”.

#


205
206
207
208
# File 'lib/studium/base/time.rb', line 205

def extract_dd_mm_yyyy(i)
  i =~ /(\d{1,2}\.\d{1,2}\.\d{4})/ # This will also generate a match.
  $1.to_s.dup
end

#file_lecture_information?Boolean

#

file_lecture_information?

#

Returns:

  • (Boolean)


581
582
583
# File 'lib/studium/base/misc.rb', line 581

def file_lecture_information?
  ::Studium.file_lecture_information?
end

#file_read_with_proper_encoding(this_file) ⇒ Object

#

file_read_with_proper_encoding

#


372
373
374
# File 'lib/studium/base/misc.rb', line 372

def file_read_with_proper_encoding(this_file)
  Studium.file_read_with_proper_encoding(this_file)
end

#filter_away_invalid_questions(i) ⇒ Object

#

filter_away_invalid_questions

This method will remove entries that begin with '#' and empty entries.

#


873
874
875
# File 'lib/studium/base/misc.rb', line 873

def filter_away_invalid_questions(i)
  Studium.filter_away_invalid_questions(i)
end

#find_corresponding_exam_topic(i) ⇒ Object Also known as: return_file_associated_with_this_exam_topic

#

find_corresponding_exam_topic

This method will find the corresponding exam topic, based on a short input. For example, “bem1” will be short for basic biochemistry.

#


604
605
606
# File 'lib/studium/base/misc.rb', line 604

def find_corresponding_exam_topic(i)
  Studium.find_corresponding_exam_topic(i)
end

#first_argument?Boolean Also known as: first?

#

first_argument?

This method will attempt to return the first commandline argument given.

#

Returns:

  • (Boolean)


36
37
38
# File 'lib/studium/base/commandline_arguments.rb', line 36

def first_argument?
  @commandline_arguments and @commandline_arguments.first
end

#first_non_hyphen_argument?Boolean

#

first_non_hyphen_argument?

#

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/studium/base/commandline_arguments.rb', line 71

def first_non_hyphen_argument?
  @commandline_arguments.select {|entry|
    !entry.start_with?('--')
  }.first
end

#from_curriculum_id_to_university(id) ⇒ Object Also known as: from_curriculum_number_to_university, which_university?

#

from_curriculum_id_to_university

This method will translate from the curriculum-ID to the university. So it will return a String such as “BOKU”.

#


234
235
236
# File 'lib/studium/base/curriculum.rb', line 234

def from_curriculum_id_to_university(id)
  ::Studium.from_curriculum_id_to_university(id)
end

#german_date_notation(i, use_this_token_as_separator = '-') ⇒ Object Also known as: german_notation, to_german_date, german_formatting_for_the_date

#

german_date_notation

Give a Range as input, and it will give us back a String that shows german date notation, aka DD.MM.YYYY.

#


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/studium/base/time.rb', line 317

def german_date_notation(
    i, use_this_token_as_separator = '-'
  )
  # ======================================================================= #
  # === Handle Range objects next
  # ======================================================================= #
  if i.is_a? Range
    start_date  = i.begin
    end_date    = i.end
    start_day   = start_date.day.to_s.rjust(2, '0')
    start_month = start_date.month.to_s.rjust(2, '0')
    start_year  = start_date.year.to_s
    end_day     = end_date.day.to_s.rjust(2, '0')
    end_month   = end_date.month.to_s.rjust(2, '0')
    end_year    = end_date.year.to_s
    i = start_day+'.'+start_month+'.'+start_year+' '+
        use_this_token_as_separator+' '+
        end_day+'.'+end_month+'.'+end_year
  # ======================================================================= #
  # === Handle Time objects next
  #
  # This requires no token.
  # ======================================================================= #
  elsif i.is_a? Time
    i = "#{i.day.to_s.rjust(2, '0')}."\
        "#{i.month.to_s.rjust(2, '0')}."\
        "#{i.year.to_s}"
  end
  return i
end

#german_weekday?(i = Date.today.wday) ⇒ Boolean Also known as: weekday_at, german_weekday

#

german_weekday?

This method will return a german weekday, for the given input. The input should be the specific wday at hand.

#

Returns:

  • (Boolean)


560
561
562
563
564
# File 'lib/studium/base/time.rb', line 560

def german_weekday?(
    i = Date.today.wday
  )
  weekday?(i, :german)
end

#german_weekdays?Boolean

#

german_weekdays?

#

Returns:

  • (Boolean)


430
431
432
# File 'lib/studium/base/time.rb', line 430

def german_weekdays?
  ARRAY_GERMAN_WEEKDAYS
end

#has_a_bachelor_curriculum?(array) ⇒ Boolean Also known as: is_a_bachelor_lecture?, has_a_bachelor_curriculum_entry?, is_a_bachelor_curriculum?

#

has_a_bachelor_curriculum?

This method will return true if the given Array has any bachelor curriculum; and it will return false otherwise.

#

Returns:

  • (Boolean)


261
262
263
# File 'lib/studium/base/curriculum.rb', line 261

def has_a_bachelor_curriculum?(array)
  Studium.has_a_bachelor_curriculum?(array)
end

#has_a_master_curriculum?(array) ⇒ Boolean Also known as: is_a_master_curriculum?, has_a_master_lecture?, has_a_master_curriculum_entry?, is_this_lecture_registered_in_a_master_curriculum?

#

has_a_master_curriculum?

This method will return true if the given Array has any master curriculum; and it will return false otherwise.

Note that there is an alias called “is_this_lecture_registered_in_a_master_curriculum?”. The name is a of a misnomer, since the input to this method should be an Array containing the IDs of the Curricula for which that lecture is registered. This may be subject for change one day, but for now (Sep 2018) we will keep it that way.

#

Returns:

  • (Boolean)


141
142
143
# File 'lib/studium/base/curriculum.rb', line 141

def has_a_master_curriculum?(array)
  Studium.has_a_master_curriculum?(array)
end

#has_this_exam_topic_been_solved?(i) ⇒ Boolean

#

has_this_exam_topic_been_solved?

#

Returns:

  • (Boolean)


833
834
835
# File 'lib/studium/base/misc.rb', line 833

def has_this_exam_topic_been_solved?(i)
  (Studium.return_n_percent_solved_from_this_topic(i).to_i == 100)
end

#has_year_entry?(this_line) ⇒ Boolean Also known as: this_line_has_a_year_entry?

#

has_year_entry?

This method will return a Boolean.

It will return true if the line has a year entry such as '2018'; and it will return false, otherwise.

#

Returns:

  • (Boolean)


218
219
220
# File 'lib/studium/base/time.rb', line 218

def has_year_entry?(this_line)
  this_line =~ /\d{4}/ # If this line has at the least one entry with 4 numbers.
end

#hh_mm_ss_dd_mm_yyyy(i) ⇒ Object

#

hh_mm_ss_dd_mm_yyyy

#


493
494
495
# File 'lib/studium/base/time.rb', line 493

def hh_mm_ss_dd_mm_yyyy(i)
  hh_mm_ss(i)+'-'+dd_mm_yyyy(i)
end

#horizontal_bar?Boolean

#

horizontal_bar?

#

Returns:

  • (Boolean)


84
85
86
# File 'lib/studium/base/unicode.rb', line 84

def horizontal_bar?
  return ''
end

#html_log_directory?Boolean Also known as: html_log_dir?

#

html_log_dir?

#

Returns:

  • (Boolean)


769
770
771
# File 'lib/studium/base/misc.rb', line 769

def html_log_directory?
  Studium.html_log_directory?
end

#is_a_master_lecture?(i) ⇒ Boolean

#

is_a_master_lecture?

#

Returns:

  • (Boolean)


124
125
126
# File 'lib/studium/base/curriculum.rb', line 124

def is_a_master_lecture?(i)
  Studium.is_a_master_lecture?(i)
end

#is_a_weekday?(i = 'Montag') ⇒ Boolean

#

is_a_weekday?

This method will return true if the input is a String that represents a weekday, such as “Monday”. Otherwise, false will be returned.

Both german and english variants are allowed here.

#

Returns:

  • (Boolean)


221
222
223
224
225
226
227
228
229
# File 'lib/studium/base/misc.rb', line 221

def is_a_weekday?(i = 'Montag')
  result = false
  if ARRAY_GERMAN_WEEKDAYS.include? i
    result = true
  elsif ARRAY_ENGLISH_WEEKDAYS.include? i
    result = true
  end
  return result
end

#is_connected_to_the_www?Boolean

#

is_connected_to_the_www?

#

Returns:

  • (Boolean)


639
640
641
# File 'lib/studium/base/misc.rb', line 639

def is_connected_to_the_www?
  !@no_connection_to_the_www
end

#is_on_roebe?Boolean Also known as: is_roebe?, on_roebe?

#

is_on_roebe?

#

Returns:

  • (Boolean)


695
696
697
# File 'lib/studium/base/misc.rb', line 695

def is_on_roebe?
  Studium.is_on_roebe?
end

#is_prüfungsimmanent?(i, ignore_these_types = nil) ⇒ Boolean Also known as: is_a_prüfungsimmanent_course?, is_this_a_prüfungsimment_course?

#

is_prüfungsimmanent?

This method can determine whether a course is “prüfungsimmanent”, aka whether this course requires continuous, mandatory presence (of the student).

The argument to this method should be the type of the lecture at hand, such as “VO” or “VU” or “SE” or “PR”, as a String.

The method will always return a boolean value, aka true or false. If true is the return value then this means that “yes, this course requires mandatory presence”.

#

Returns:

  • (Boolean)


714
715
716
717
718
# File 'lib/studium/base/misc.rb', line 714

def is_prüfungsimmanent?(
    i, ignore_these_types = nil
  )
  Studium.is_prüfungsimmanent?(i, ignore_these_types)
end

#is_this_a_valid_html_colour?(i) ⇒ Boolean Also known as: is_this_colour_a_html_colour?

#

is_this_a_valid_html_colour?

This method will let us know whether the given input is a valid (aka registered) “html colour”. An example for this would be the String 'slateblue'.

#

Returns:

  • (Boolean)


254
255
256
# File 'lib/studium/base/colours.rb', line 254

def is_this_a_valid_html_colour?(i)
  ::Studium.is_this_a_valid_html_colour?(i)
end

#is_this_day_today?(i = '18.02.2022') ⇒ Boolean

#

is_this_day_today?

This method will return true or false, depending on whether the given input is assumed to be the present day or not.

The method assumes that the input will be a Time object normally.

#

Returns:

  • (Boolean)


391
392
393
# File 'lib/studium/base/time.rb', line 391

def is_this_day_today?(i = '18.02.2022')
  dd_mm_yyyy(Time.now) == dd_mm_yyyy(i)
end

#konsole_support?Boolean

#

konsole_support?

#

Returns:

  • (Boolean)


519
520
521
# File 'lib/studium/base/misc.rb', line 519

def konsole_support?
  true
end

#last_file?Boolean

#

last_file?

#

Returns:

  • (Boolean)


558
559
560
561
562
563
564
565
566
567
568
# File 'lib/studium/base/misc.rb', line 558

def last_file?
  _ = Studium.file_for_exam_questions
  _ = load_yaml_dataset(_).chomp
  # ======================================================================= #
  # If we are on roebe then we will use another path.
  # ======================================================================= #
  if is_on_roebe?
    _ = Studium::MY_EXAM_TOPICS+File.basename(_)
  end
  return _
end

#lectures_from_indi1Object

#

lectures_from_indi1

#


301
302
303
# File 'lib/studium/base/curriculum.rb', line 301

def lectures_from_indi1
  obtain_lectures_from_this_curriculum(:indi1)
end

#lectures_from_indi2Object

#

lectures_from_indi2

#


308
309
310
# File 'lib/studium/base/curriculum.rb', line 308

def lectures_from_indi2
  obtain_lectures_from_this_curriculum(:indi2)
end

#lectures_from_indi3Object

#

lectures_from_indi3

#


315
316
317
# File 'lib/studium/base/curriculum.rb', line 315

def lectures_from_indi3
  obtain_lectures_from_this_curriculum(:indi3)
end

#lectures_from_indi4Object

#

lectures_from_indi4

#


322
323
324
# File 'lib/studium/base/curriculum.rb', line 322

def lectures_from_indi4
  obtain_lectures_from_this_curriculum(:indi4)
end

#lectures_from_the_bachelor_genetik_curriculumObject

#

lectures_from_the_bachelor_genetik_curriculum

#


46
47
48
# File 'lib/studium/base/curriculum.rb', line 46

def lectures_from_the_bachelor_genetik_curriculum
  obtain_lectures_from_this_curriculum(:bachelor_genetik_curriculum)
end

#lectures_from_the_individual_vektor_curriculaObject

#

lectures_from_the_individual_vektor_curricula

This method is a convenience method, returning all the lectures that belong to the individual bachelor+master vektor-curriculum

#


291
292
293
294
295
296
# File 'lib/studium/base/curriculum.rb', line 291

def lectures_from_the_individual_vektor_curricula
  (
    obtain_lectures_from_this_curriculum(:bachelor_vektor)+
    obtain_lectures_from_this_curriculum(:master_vektor)
  ).flatten
end

#load_yaml_dataset(i, do_rescue = false) ⇒ Object

#

load_yaml_dataset

This method should ideally be used whenever a .yml file is to be loaded.

The second argument can be used to rescue missing or erroneous yaml files.

Invocation example for this is:

load_yaml_dataset(:rescue)
#


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/studium/base/misc.rb', line 110

def load_yaml_dataset(
    i, do_rescue = false
  )
  case do_rescue
  when :rescue
    do_rescue = true
  end
  if do_rescue
    begin
      YAML.load_file(i)
    rescue LoadError, ArgumentError; end
  else
    YAML.load_file(i)
  end
end

#move_file(this_file, target) ⇒ Object

#

move_file

#


826
827
828
# File 'lib/studium/base/misc.rb', line 826

def move_file(this_file, target)
  FileUtils.mv(this_file, target)
end

#n_days_difference_from_today_to_this_day(time_now = Time.now, name_of_the_future_day) ⇒ Object

#

n_days_difference_from_today_to_this_day

This method will return a number, which is the amount of days between weekdays.

The days are numbered like this:

Monday:    1
Tuesday:   2
Wednesday: 3
Thursday:  4
Friday:    5
Saturday:  6
Sunday:    0

So, how to calculate the time difference to the next day?

Well, say we have the current day be a Wednesday, and the day that is to be compared, a Friday. The difference is thus (5 - 3 = 2). If the current day is a Saturday, and the input-day is a Friday, then the difference must be 5.

If we have, for example, “Friday” to “Tuesday”, the this method should return the number 4, because the distance is that: Friday, Saturday, Sunday and Monday (the start day has to be included, as lectures can happen on that day still, e. g. if you check early in the morning, you could still have courses in the evening slots scheduled).

#


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
# File 'lib/studium/base/time.rb', line 77

def n_days_difference_from_today_to_this_day(
    time_now = Time.now,
    name_of_the_future_day # ← This ought to be a String, such as "Monday".
  )
  n_days_difference = 0
  weekday_as_number = time_now.wday
  name_of_the_future_day = name_of_the_future_day.dup if name_of_the_future_day.frozen?
  name_of_the_future_day.strip! # We better strip that input.
  start_day = Date::DAYNAMES[weekday_as_number]
  # ======================================================================= #
  # The next is simply a hardcoded table. We will begin with the
  # future day.
  # ======================================================================= #
  n_days_difference =
  case start_day
  when 'Monday'
    case name_of_the_future_day
    when 'Tuesday'   then 1
    when 'Wednesday' then 2
    when 'Thursday'  then 3
    when 'Friday'    then 4
    when 'Saturday'  then 5
    when 'Sunday'    then 6
    end
  when 'Tuesday'
    case name_of_the_future_day
    when 'Wednesday' then 1
    when 'Thursday'  then 2
    when 'Friday'    then 3
    when 'Saturday'  then 4
    when 'Sunday'    then 5
    when 'Monday'    then 6
    end
  when 'Wednesday'
    case name_of_the_future_day
    when 'Thursday'  then 1
    when 'Friday'    then 2
    when 'Saturday'  then 3
    when 'Sunday'    then 4
    when 'Monday'    then 5
    when 'Tuesday'   then 6
    end
  when 'Thursday'
    case name_of_the_future_day
    when 'Friday'    then 1
    when 'Saturday'  then 2
    when 'Sunday'    then 3
    when 'Monday'    then 4
    when 'Tuesday'   then 5
    when 'Wednesday' then 6
    end
  when 'Friday'
    case name_of_the_future_day
    when 'Saturday'  then 1
    when 'Sunday'    then 2
    when 'Monday'    then 3
    when 'Tuesday'   then 4
    when 'Wednesday' then 5
    when 'Thursday'  then 6
    end
  when 'Saturday'
    case name_of_the_future_day
    when 'Sunday'    then 1
    when 'Monday'    then 2
    when 'Tuesday'   then 3
    when 'Wednesday' then 4
    when 'Thursday'  then 5
    when 'Friday'    then 6
    end
  when 'Sunday'
    case name_of_the_future_day
    when 'Monday'    then 1
    when 'Tuesday'   then 2
    when 'Wednesday' then 3
    when 'Thursday'  then 4
    when 'Friday'    then 5
    when 'Saturday'  then 6
    end
  end
  return n_days_difference
end

#no_ext_name(i) ⇒ Object

#

no_ext_name

This method will return the name of the file (or rather the input given to this method) without extension.

#


83
84
85
# File 'lib/studium/base/misc.rb', line 83

def no_ext_name(i)
  i.sub(/#{File.extname(i)}$/,'')
end

#no_file_at(i) ⇒ Object Also known as: no_file_exists_at

#

no_file_at

#


42
43
44
# File 'lib/studium/base/minimal_prototype.rb', line 42

def no_file_at(i)
  e "#{rev}No file exists at #{sfile(i)}."
end

#number_to_month(i) ⇒ Object

#

number_to_month

This method will convert a number, such as 6, to the corresponding month entry.

#


254
255
256
257
258
# File 'lib/studium/base/time.rb', line 254

def number_to_month(i)
  array = Date::MONTHNAMES
  i = i.to_i
  return array[i]
end

#obtain(this_key, hash, be_verbose = true) ⇒ Object Also known as: obtain_this_value_from_hash, obtain_from

#

obtain (obtain tag)

This method will attempt to return the entry point of our main hash.

It is optimized towards the dataset stored in the file 'lecture_information.yml'.

Typical usage example:

curricula = obtain(:curricula, pointer_to_the_lecture_dataset)
#


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
# File 'lib/studium/base/obtain.rb', line 24

def obtain(
    this_key, hash, be_verbose = true
  )
  if block_given?
    yielded = yield
    case yielded
    # === :be_quiet
    when :be_quiet
      be_verbose = false
    end
  end
  case be_verbose
  when :be_quiet, :be_silent
    be_verbose = false
  end
  # ======================================================================= #
  # The following case menu will make use of some common popular aliases
  # or typos.
  # ======================================================================= #
  case this_key
  # ======================================================================= #
  # === :passed_when
  # ======================================================================= #
  when :passed_when,
       :solved_at
    this_key = :already_solved_at
  # ======================================================================= #
  # === :passed_successfully
  # ======================================================================= #
  when :passed_successfully
    this_key = :already_solved
  # ======================================================================= #
  # === :steop
  # ======================================================================= #
  when :steop,
       'steop'
    this_key = :is_a_steop_lecture
  # ======================================================================= #
  # === :curricula_entries
  # ======================================================================= #
  when :curricula_entries,
       :curricula,
       'curricula'
    this_key = 'curricula'
  # ======================================================================= #
  # === :english_description
  # ======================================================================= #
  when :english_description
    this_key = :description_in_english
  # ======================================================================= #
  # === :german_description
  # ======================================================================= #
  when :german_description
    this_key = :description_in_german
  # ======================================================================= #
  # === :this_university
  # ======================================================================= #
  when :this_university,
       :university
    this_key = :university
  # ======================================================================= #
  # === :n_ects
  # ======================================================================= #
  when :n_ects, :n_ects_points
    this_key = :ects
  # ======================================================================= #
  # === :curricula_ids
  # ======================================================================= #
  when :curricula_ids,
       :curriculum_id
    this_key = 'curricula'
  # ======================================================================= #
  # === :lecturers
  # ======================================================================= #
  when :lecturers
    this_key = 'lecturers'
  # ======================================================================= #
  # === :semester
  # ======================================================================= #
  when 'homepage',
       :remote_url
    this_key = :homepage
  # ======================================================================= #
  # === :semester
  # ======================================================================= #
  when :semester, 'semester'
    this_key = :semester
  end
  # ======================================================================= #
  # Work on any other symbols given to us next.
  # ======================================================================= #
  if this_key.is_a? Symbol
    if hash.has_key? this_key
      # All is fine.
    elsif hash.has_key? this_key.to_s
      # Else use that String as key instead.
      this_key = this_key.to_s
    end
  end
  if hash.is_a? Symbol
    e "Symbol called :#{slateblue(hash.to_s)}"
    e swarn('This is not allowed - please correct this. '\
      '(Read the next line in how to do so.)')
    e swarn('This method requires (1) first the key, (2) then the Hash.')
    exit
  elsif hash.is_a?(Hash) and hash.has_key?(this_key)
    hash[this_key] # Return this.
  else
    if be_verbose
      case this_key
      when :is_a_steop_lecture
        # Exceptions - these keys ^^^ will NOT be shown.
      else
        e "In file base.rb, method: obtain() → No key found, "\
          "called `#{this_key.to_s}` (class '#{this_key.class.to_s})"
      end
    end
    nil
  end
end

#obtain_lectures_from_this_curriculum(i = :default, do_flatten_the_result = true) ⇒ Object Also known as: return_lectures_from_this_curriculum, return_lectures_of_this_curriculum, return_lectures_from_this_curriculu, return_lectures_from_this_curriculum_file

#

obtain_lectures_from_this_curriculum

This method should be used whenever you wish to obtain all lectures that belong to a specific curriculum, without any comments.

An Array will be returned by this method.

#


336
337
338
339
340
341
342
343
# File 'lib/studium/base/curriculum.rb', line 336

def obtain_lectures_from_this_curriculum(
    i                     = :default,
    do_flatten_the_result = true
  )
  Studium.read_dataset_from_a_curriculum_file(i, :remove_comments, do_flatten_the_result).map {|entry|
    entry.squeeze(' ') # ← We don't want multiple ' ' in succession here.
  }
end

#open_in_editor(i) ⇒ Object

#

open_in_editor

#


17
18
19
# File 'lib/studium/base/editor.rb', line 17

def open_in_editor(i)
  Studium.open_in_editor(i)
end

#opnn(i = @namespace, &block) ⇒ Object

#

opnn

The method also handles blocks.

#


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/studium/base/opnn.rb', line 20

def opnn(
    i = @namespace,
    &block
  )
  if use_opn?
    if i.is_a? String # "Turn" it into a Hash here.
      i = { namespace: i }
    end
    Opn.opn(i, &block)
  end
end

#path_to_exam_topic?Boolean

#

directory_to_the_exam_topics?

#

path_to_exam_topic?

Returns:

  • (Boolean)


799
800
801
# File 'lib/studium/base/misc.rb', line 799

def directory_to_the_exam_topics?
  Studium.directory_to_the_exam_topics?
end

#read_dataset_from_a_curriculum_file(i, optional_commands = :remove_comments) ⇒ Object

#

read_dataset_from_a_curriculum_file

#


175
176
177
178
179
180
# File 'lib/studium/base/curriculum.rb', line 175

def read_dataset_from_a_curriculum_file(
    i,
    optional_commands = :remove_comments
  )
  Studium.read_dataset_from_a_curriculum_file(i, optional_commands)
end

#read_in_exam_dataset_from_this_file(this_file) ⇒ Object

#

read_in_exam_dataset_from_this_file

This is the method that will read from an existing file. If a symbol is given then we will expand this to the default exam-topic directory.

#


883
884
885
886
887
888
889
890
891
892
893
894
# File 'lib/studium/base/misc.rb', line 883

def read_in_exam_dataset_from_this_file(
    this_file
  )
  if this_file.is_a? Symbol
    this_file = "#{exam_topic_directory?}#{this_file}"
  end
  if File.exist? this_file
    dataset = readlines_via_default_encoding(this_file)
    dataset = filter_away_invalid_questions(dataset)
    return dataset
  end
end

#read_this_file_with_default_encoding(this_file) ⇒ Object Also known as: read_as_string_with_default_encoding, read_file, read_this_file, read_file_with_default_encoding, read_in_with_default_encoding

#

read_this_file_with_default_encoding

This method will read in a file, that should ideally exist, in the default project-wide encoding.

A few aliases exist to this method, such as “read_this_file()”.

#


359
360
361
362
363
# File 'lib/studium/base/misc.rb', line 359

def read_this_file_with_default_encoding(
    this_file
  )
  File.read(this_file, encoding: ::Studium.main_encoding?)
end

#readlines_from_this_input_file(this_file, use_this_encoding = :default_encoding) ⇒ Object Also known as: readlines_via_default_encoding, readlines_with_default_encoding, readlines_with_the_default_encoding, readlines_with_iso_encoding, file_readlines_of_this_file, file_readlines, readlines_with_proper_encoding, proper_readlines

#

readlines_from_this_input_file

This method is essentially File.readlines(), but we also use the :encoding symbol to denote which Encoding to use.

As first argument pass in the file path to the target input file.

You should ideally use this method in a unified way, that is, whenever you want to read the content of a file make use of this method here. This makes it easier to have the functionality all in one place.

Keep in mind that the file in question has to exist locally; the file here will NOT check whether the given input file exists.

#


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/base/readlines.rb', line 28

def readlines_from_this_input_file(
    this_file,
    use_this_encoding = :default_encoding
  )
  case use_this_encoding
  # ======================================================================= #
  # === :default
  #
  # This refers to the default encoding, which is usually UTF-8 (Unicode).
  # ======================================================================= #
  when :default,
       :default_encoding
    use_this_encoding = ::Studium.main_encoding?
  end
  if use_this_encoding.is_a? Hash
    if use_this_encoding.has_key? :encoding
      use_this_encoding = use_this_encoding[:encoding]
    end
  end
  File.readlines(
    this_file,
    encoding: use_this_encoding
  )
end

#register_sigintObject

#

register_sigint

#


188
189
190
# File 'lib/studium/base/misc.rb', line 188

def register_sigint
  Signal.trap('SIGINT') { exit }
end

#remove_empty_strings(i) ⇒ Object

#

remove_empty_strings

This method presently only works on Arrays. We will reject empty Strings from the Array at hand.

#


320
321
322
323
324
# File 'lib/studium/base/misc.rb', line 320

def remove_empty_strings(i)
  if i.is_a? Array
    i.reject {|line| line.empty? }
  end
end

#remove_escape_sequences(i) ⇒ Object

#

remove_escape_sequences

#


228
229
230
# File 'lib/studium/base/colours.rb', line 228

def remove_escape_sequences(i)
  ::Colours.remove_escape_sequences(i)
end

#remove_internal_comments(i) ⇒ Object

#

remove_internal_comments

#


294
295
296
297
298
299
300
301
302
303
# File 'lib/studium/base/misc.rb', line 294

def remove_internal_comments(i)
  if i.is_a? Array
    i.map {|line|
      if line.include? '#'
        line = line[0 .. (line.index('#')-1)]
      end
      line.strip
    }
  end
end

#remove_leading_comments(i) ⇒ Object

#

remove_leading_comments

#


308
309
310
311
312
# File 'lib/studium/base/misc.rb', line 308

def remove_leading_comments(i)
  if i.is_a? Array
    i.reject {|line| line.start_with? '#' }
  end
end

#remove_leading_weekday_names_from(i) ⇒ Object Also known as: remove_german_weekdays, remove_german_weekdays_from, remove_leading_weeknames, remove_leading_weekdays, remove_workday_from_this_input

#

remove_leading_weekday_names_from

Chop away the leading weekday, e. g. “Monday”, from the String at hand.

#


448
449
450
# File 'lib/studium/base/time.rb', line 448

def remove_leading_weekday_names_from(i)
  Studium.remove_leading_weekday_names_from(i)
end

#remove_newlines(i) ⇒ Object

#

remove_newlines

This method will remove newlines, aka “n”, from Strings and Arrays.

#


283
284
285
286
287
288
289
# File 'lib/studium/base/misc.rb', line 283

def remove_newlines(i)
  if i.is_a? Array
    i.map {|entry| remove_newlines(entry) }
  else
    i.delete(N)
  end
end

#remove_tags_from_this_input(i) ⇒ Object Also known as: remove_tags

#

remove_tags_from_this_input

This method will return all HTML-like tags from the given input String.

#


87
88
89
# File 'lib/studium/base/prototype.rb', line 87

def remove_tags_from_this_input(i)
  return Studium.remove_tags(i)
end

#rename_kde_konsole_tab(title = '.') ⇒ Object

#

rename_kde_konsole_tab

#


546
547
548
549
550
551
552
553
# File 'lib/studium/base/misc.rb', line 546

def rename_kde_konsole_tab(
    title = '.'
  )
  if Object.const_defined?(:Roebe) and
     Roebe.respond_to?(:rename_konsole_title_to)
    Roebe.rename_konsole_title_to(title, :be_quiet)
  end
end

#rename_konsole_tab?(i = FILE_RENAME_KONSOLE_TAB) ⇒ Boolean

#

rename_konsole_tab?

#

Returns:

  • (Boolean)


526
527
528
529
530
531
532
533
534
# File 'lib/studium/base/misc.rb', line 526

def rename_konsole_tab?(
    i = FILE_RENAME_KONSOLE_TAB
  )
  if File.exist? i
    YAML.load_file(i)
  else
    false
  end
end

#replace_all_html_colours_in_this(i, use_this_colour_for_the_default_colour = colour_for_questions? ) ⇒ Object

#

replace_all_html_colours_in_this

This method will replace all HTML colours, such as <slateblue>, with the corresponding RGB colour variant for the commandline. Typically this refers to a terminal such as the KDE konsole, and a shell such as bash (although other shells are fine too, and many other terminals, such as the gnome-terminal, most likely will work fine as well - but it is optimized for the KDE konsole).

This method should only be called after a prior check was done, to determine whether the given input String at hand does indeed include a valid HTML colour. This can be done via a call to the method called line_contains_a_valid_html_colour?().

#


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/studium/base/replace.rb', line 43

def replace_all_html_colours_in_this(
    i,
    use_this_colour_for_the_default_colour = colour_for_questions?
  )
  # ======================================================================= #
  # bl $RUBY_COLOURS/toplevel_methods/replace_all_html_colours_in_this_line.rb
  # ======================================================================= #
  ::Colours.replace_all_html_colours_in_this_line(
    i, use_this_colour_for_the_default_colour
  )
end

#replace_bold_token_with_default_colour(i, use_this_colour = :mediumseagreen) ⇒ Object

#

replace_bold_token_with_default_colour

This method can be used to replace with the corresponding colour code on the terminal.

#


19
20
21
22
23
24
25
26
# File 'lib/studium/base/replace.rb', line 19

def replace_bold_token_with_default_colour(
    i, use_this_colour = :mediumseagreen
  )
  i.gsub(
    /<b>(.+)<\/b>/,
    ::Colours.bold('\1')
  )
end

#replace_italic_token_with_default_colour(i, colour_to_use = :royalblue) ⇒ Object

#

replace_italic_token_with_default_colour

#


58
59
60
# File 'lib/studium/base/replace.rb', line 58

def replace_italic_token_with_default_colour(i, colour_to_use = :royalblue)
  replace_italic_token_with_this_colour(i, colour_to_use)
end

#replace_italic_token_with_this_colour(i, use_this_colour = :mediumseagreen) ⇒ Object

#

replace_italic_token_with_this_colour

This method can be used to replace with the corresponding colour code on the terminal.

#


104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/studium/base/replace.rb', line 104

def replace_italic_token_with_this_colour(
    i, use_this_colour = :mediumseagreen
  )
  use_this_regex = /<it?>([A-Za-zöäüÖÄÜ\s]+)<\/it?>/ # See: https://rubular.com/r/mZb1ZtGHCLhg2U
  i.gsub(
    use_this_regex,
    ::Colours.string_italic('\1')+
    ::Colours.remove_trailing_escape_code(
      ::Colours.send(use_this_colour.to_sym, '')
    )
  )+
  ::Colours.send(use_this_colour,'')
end

#replace_regular_numbers_with_unicode_numbers(i) ⇒ Object

#

replace_regular_numbers_with_unicode_numbers

This method will replace numbers such as 1 with ¹.

#


181
182
183
# File 'lib/studium/base/misc.rb', line 181

def replace_regular_numbers_with_unicode_numbers(i)
  ::Studium.replace_regular_numbers_with_unicode_numbers(i)
end

#replace_underline_token_with_default_colour(i, colour_to_use = :royalblue) ⇒ Object

#

replace_underline_token_with_default_colour

#


65
66
67
# File 'lib/studium/base/replace.rb', line 65

def replace_underline_token_with_default_colour(i, colour_to_use = :royalblue)
  replace_underline_token_with_this_colour(i, colour_to_use)
end

#replace_underline_token_with_this_colour(i, use_this_colour = :royalblue) ⇒ Object

#

replace_underline_token_with_this_colour

We can use either <ud> or <u>, so we have to check for both variants.

#


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/studium/base/replace.rb', line 74

def replace_underline_token_with_this_colour(
    i, use_this_colour = :royalblue # This default colour is rarely in use.
  )
  if (i.include?('<ud>') and i.include?('</ud>')) or
     (i.include?('<u>')  and i.include?('</u>'))
    # ===================================================================== #
    # Next, set up a non-greedy explicit regex:
    #
    #   https://rubular.com/r/uNnBwWc35LKjXX
    #
    # ===================================================================== #
    use_this_regex = /<ud?>([-a-züöäA-ZÜÖÄ0-9\/%, \n\.]+?)<\/ud?>/
    i = i.dup if i.frozen?
    i.gsub!(
      use_this_regex,
      ::Colours.string_underline('\1')+
      ::Colours.remove_trailing_escape_code(
        ::Colours.send(use_this_colour.to_sym, '')
      )
    )
  end
  return i
end

#resetObject

#

reset (reset tag)

The @runmode variable can be any of these three values:

:www
:gui
:commandline

If :commandline is used as its value, then this class may colourize via the Colours module - otherwise, it may colourize via “websafe” colours instead (such as the HTML colours).

Note that :gui means GUI, that is, graphical user interface. These are traditional “oldschool” desktop applications.

#


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/base/reset.rb', line 31

def reset
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
  # ======================================================================= #
  # === @use_opn
  #
  # By default we will use opn in the project. The name "opn" stands
  # short for "output program name".
  # ======================================================================= #
  @use_opn = true
  # ======================================================================= #
  # === @debug
  #
  # The next variable determines whether we will debug or whether we
  # will not. If @debug is set to true, then we won't make modifications -
  # instead, we will give debug information to the user.
  # ======================================================================= #
  @debug = false
  # ======================================================================= #
  # === @use_colours
  #
  # The next variable determines whether instances of this class will
  # make use of colours. By default the value from a toplevel-variable
  # will be used as default start value. Thus, initially, they have
  # the same value.
  # ======================================================================= #
  @use_colours = ::Studium.use_colours?
  # ======================================================================= #
  # === @no_connection_to_the_www
  #
  # If true then we have no connection to the WWW.
  # ======================================================================= #
  @no_connection_to_the_www = false
  # ======================================================================= #
  # Next, determine which "mode" is used, such as www-mode, commandline
  # mode or similar.
  # ======================================================================= #
  set_mode :commandline  # The default mode is commandline.
end

#return_all_bachelor_lectures(from_this_dataset = ::Studium.main_dataset?) ⇒ Object

#

return_all_bachelor_lectures

This method will simply return all bachelor-lectures.

#


272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/studium/base/curriculum.rb', line 272

def return_all_bachelor_lectures(
    from_this_dataset = ::Studium.main_dataset?
  )
  if from_this_dataset.nil?
    ::Studium.initialize_main_dataset
    from_this_dataset = ::Studium.main_dataset?
  end
  from_this_dataset.select {|name_of_the_lecture, inner_hash|
    array = inner_hash['curricula']
    is_a_bachelor_lecture?(array)
  }
end

#return_all_exams_on_this_day(i) ⇒ Object

#

return_all_exams_on_this_day

#


752
753
754
# File 'lib/studium/base/misc.rb', line 752

def return_all_exams_on_this_day(i)
  Studium.return_all_exams_on_this_day(i)
end

#return_all_numbers_from(i) ⇒ Object

#

return_all_numbers_from

This method will return all numbers from the given input.

#


331
332
333
334
335
336
337
338
339
# File 'lib/studium/base/misc.rb', line 331

def return_all_numbers_from(i)
  return_this = nil
  if i.is_a? Array
    return_this = i.select {|line|
      line =~ /\d+/ # Any entry with a number will be returned.
    }
  end
  return_this
end

#return_all_registered_curriculaObject

#

return_all_registered_curricula

#


210
211
212
# File 'lib/studium/base/curriculum.rb', line 210

def return_all_registered_curricula
  Studium.return_registered_standalone_curricula
end

#return_all_steop_lecturesObject

#

return_all_steop_lectures

#


344
345
346
347
348
349
# File 'lib/studium/base/misc.rb', line 344

def return_all_steop_lectures
  return_sanitized_dataset_from_the_file_lecture_information.select {|a, b|
    is_a_steop_lecture = obtain(:steop, b)
    is_a_steop_lecture
  }
end

#return_current_yearObject Also known as: current_year?

#

return_current_year

This method will simply return the current year, as String.

#


164
165
166
# File 'lib/studium/base/time.rb', line 164

def return_current_year
  Time.now.year.to_s
end

#return_dataset_for_this_topic(i) ⇒ Object

#

return_dataset_for_this_topic

#


539
540
541
# File 'lib/studium/base/misc.rb', line 539

def return_dataset_for_this_topic(i)
  Studium.return_dataset_for_this_topic(i)
end

#return_dataset_from_this_curriculum_file(i) ⇒ Object Also known as: return_dataset_for_this_curriculum_file, return_dataset_from_this_curriculum, return_this_curriculum

#

return_dataset_from_this_curriculum_file

#


351
352
353
# File 'lib/studium/base/curriculum.rb', line 351

def return_dataset_from_this_curriculum_file(i)
  return Studium.return_dataset_from_this_curriculum_file(i)
end

#return_dd_mm_yy_and_time_from(i) ⇒ Object

#

return_dd_mm_yy_and_time_from

This method will return the day, in dd.mm.yyyy format, and the time on that date. You have to pass in a special object to this method, such as an instance of class Time - see methods used such as .day() or .month() and so forth.

#


464
465
466
# File 'lib/studium/base/time.rb', line 464

def return_dd_mm_yy_and_time_from(i)
  Studium.return_dd_mm_yy_and_time_from(i)
end

#return_directory_for(name_of_the_lecture, university) ⇒ Object

#

return_directory_for

This method will try to build up the most plausible, local path to an existing directory.

#


244
245
246
247
248
# File 'lib/studium/base/misc.rb', line 244

def return_directory_for(
    name_of_the_lecture, university
  )
  Studium.return_directory_for(name_of_the_lecture, university)
end

#return_ects_points_from_these_lectures(hash) ⇒ Object

#

return_ects_points_from_these_lectures

Input to this method should be a Hash containing our lectures.

An example for this is shown next:

{"051010"=>"Programmierung 1",
 "051110"=>"Mathematische Grundlagen der Informatik 1"}
#


474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/studium/base/misc.rb', line 474

def return_ects_points_from_these_lectures(hash)
  n_ects_points = 0 # Keep track of the amount of ECTS points here.
  hash.each_pair {|lecture_id, name_of_the_lecture|
    # lecture_id = ensure_main_encoding(lecture_id)
    # name_of_the_lecture = ensure_main_encoding(name_of_the_lecture)
    name_of_the_lecture.squeeze!(' ')
    points = Studium.return_ects_from_this_lecture_stored_in_the_file_lecture_information(
      name_of_the_lecture, lecture_id
    )
    n_ects_points += points
  }
  return n_ects_points
end

#return_either_grey_or_the_custom_colour_for_answersObject

#

return_either_grey_or_the_custom_colour_for_answers

#


197
198
199
200
201
202
203
204
# File 'lib/studium/base/colours.rb', line 197

def return_either_grey_or_the_custom_colour_for_answers
  _ = grey('').strip
  if @custom_colours and
     @custom_colours.has_key?('colour_for_answers')
    _ = COLOURS.send(@custom_colours['colour_for_answers']) { :omit_end }
  end
  _
end

#return_either_grey_or_the_custom_colour_for_questionsObject

#

return_either_grey_or_the_custom_colour_for_questions

#


298
299
300
301
302
303
304
305
# File 'lib/studium/base/colours.rb', line 298

def return_either_grey_or_the_custom_colour_for_questions
  _ = grey('').strip
  if @custom_colours and
     @custom_colours.has_key?('colour_for_questions')
    _ = COLOURS.send(@custom_colours['colour_for_questions']) { :omit_end }
  end
  _
end

#return_file_for_this_curriculum(i = :bachelor_basisblock_biologie) ⇒ Object Also known as: return_curriculum_file_based_on_this_input, curriculum_location_of, return_path_of_this_curriculum, return_file_associated_with_this_curriculum, location_of_this_curriculum_file?

#

return_file_for_this_curriculum

#


151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/studium/base/curriculum.rb', line 151

def return_file_for_this_curriculum(
    i = :bachelor_basisblock_biologie
  )
  if i.is_a? Array
    i.map {|line|
      return_file_for_this_curriculum(line)
    }
  else
    # ===================================================================== #
    #
    #   bl $RUBY_STUDIUM/constants/return_file_for_this_curriculum.rb
    #
    # ===================================================================== #
    Studium.return_file_for_this_curriculum(i)
  end
end

#return_german_name_for_this_english_month(i) ⇒ Object

#

return_german_name_for_this_english_month

#


398
399
400
401
# File 'lib/studium/base/time.rb', line 398

def return_german_name_for_this_english_month(i)
  array = MONTH_NAME_ALIASES_GERMAN_TO_ENGLISH.invert
  array[i]
end

#return_german_weekday_of?(i) ⇒ Boolean

#

return_german_weekday_of?

#

Returns:

  • (Boolean)


307
308
309
# File 'lib/studium/base/time.rb', line 307

def return_german_weekday_of?(i)
  weekday?(i, :german)
end

#return_hh_mm_ss_from(i) ⇒ Object Also known as: hh_mm_ss

#

return_hh_mm_ss_from

Input to this method may be like this:

2020-03-04 00:00:00 +0000

It will then return the ss:mm:hh notation.

#


477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/studium/base/time.rb', line 477

def return_hh_mm_ss_from(i)
  if i.is_a? String
    i = Time.parse(i)
  end
  if i.is_a? Time
    "#{i.hour.to_s.rjust(2,'0')}:"\
    "#{i.min.to_s.rjust(2,'0')}:"\
    "#{i.sec.to_s.rjust(2,'0')}"
  else
    e 'Unknown time format.'
  end
end

#return_hour_from_this(i) ⇒ Object Also known as: extract_the_time_from

#

return_hour_from_this

This method will extract the time-format from a String, such as:

"18.02.2020, 17:00-18:00"
"Dienstag 13.10.2020, 14:30-17:45"

A String will be returned in this event, holding the start and stop time - for instance, in the first example it would return the String “17:00-18:00”.

A String should be given as argument to this method.

#


512
513
514
515
516
# File 'lib/studium/base/time.rb', line 512

def return_hour_from_this(i)
  i.scan(
    /\d{2}:\d{2}-\d{2}:\d{2}/
  ).flatten.first.to_s.strip
end

#return_lectures_from_bachelor_vektor_curriculumObject

#

return_lectures_from_bachelor_vektor_curriculum

#


53
54
55
# File 'lib/studium/base/curriculum.rb', line 53

def return_lectures_from_bachelor_vektor_curriculum
  obtain_lectures_from_this_curriculum(:bachelor_vektor)
end

#return_lectures_with_at_the_least_one_upcoming_examObject

#

return_lectures_with_at_the_least_one_upcoming_exam

This method will return all lectures that have at the least one upcoming exam entry. In this context “upcoming” refers to an exam date that comes after today (or any day before today).

#


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/studium/base/misc.rb', line 391

def return_lectures_with_at_the_least_one_upcoming_exam
  today = Time.now
  return_sanitized_dataset_from_the_file_lecture_information.select {|name_of_the_course, hash_dataset|
    if hash_dataset.has_key? 'exams'
      exams = hash_dataset['exams']
      if exams.is_a? Array
        exams = exams.first
      end
      exams = remove_german_weekdays(exams)
      exams.delete!(',')
      time_parsed = Time.parse(exams)
      today < time_parsed # Check that the courses are not too old.
    else
      false
    end
  }
end

#return_local_path_of_this_pwdstud(i = 1) ⇒ Object

#

return_local_path_of_this_pwdstud

#


776
777
778
# File 'lib/studium/base/misc.rb', line 776

def return_local_path_of_this_pwdstud(i = 1)
  Studium.return_local_path_of_this_pwdstud(i)
end

#return_lva_number_of_this_lecture(this_lecture) ⇒ Object

#

return_lva_number_of_this_lecture

#


412
413
414
# File 'lib/studium/base/misc.rb', line 412

def return_lva_number_of_this_lecture(this_lecture)
  ::Studium.return_lva_number_of_this_lecture(this_lecture)
end

#return_month_fitting_to_this_input(i) ⇒ Object

#

return_month_fitting_to_this_input

This method will return a number.

#


188
189
190
191
192
193
194
# File 'lib/studium/base/time.rb', line 188

def return_month_fitting_to_this_input(i)
  i = i.capitalize
  if MONTH_NAME_TO_MONTH_NUMBER.has_key? i
    i = MONTH_NAME_TO_MONTH_NUMBER[i]
  end
  return i.to_i
end

#return_n_days_until_monday(time_now = Time.now) ⇒ Object

#

return_n_days_until_monday

#


41
42
43
44
45
# File 'lib/studium/base/time.rb', line 41

def return_n_days_until_monday(
    time_now = Time.now
  )
  n_days_difference_from_today_to_this_day(time_now, 'Monday')
end

#return_n_days_until_sunday(time_now = Time.now) ⇒ Object

#

return_n_days_until_sunday

#


34
35
36
# File 'lib/studium/base/time.rb', line 34

def return_n_days_until_sunday(time_now = Time.now)
  n_days_difference_from_today_to_this_day(time_now, 'Sunday')
end

#return_n_exam_questions_in(this_topic) ⇒ Object

#

return_n_exam_questions_in

This method will return how many exam questions are in the given topic xyz.

#


614
615
616
# File 'lib/studium/base/misc.rb', line 614

def return_n_exam_questions_in(this_topic)
  Studium::Exams.return_n_questions_in_this_topic(this_topic)
end

#return_n_questions_were_answered_for_this_topic(i) ⇒ Object

require 'studium/toplevel_methods/return_n_questions_were_answered_for_this_topic.rb' ^^^ this is already required elsewhere.

#

return_n_questions_were_answered_for_this_topic

#


688
689
690
# File 'lib/studium/base/misc.rb', line 688

def return_n_questions_were_answered_for_this_topic(i)
  Studium::Exams.return_n_questions_were_answered_for_this_topic(i)
end

#return_name_of_the_weekday(i = :today) ⇒ Object Also known as: return_weekday

#

return_name_of_the_weekday

This method can be used to return an associated weekday to a specific date, such as '22.02.2018'. The format has to be in dd.mm.yyyy.

#


280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/studium/base/time.rb', line 280

def return_name_of_the_weekday(
    i = :today
  )
  begin
    require 'roebe/constants/time.rb'
  rescue LoadError; end
  case i
  # ======================================================================= #
  # === :today
  # ======================================================================= #
  when :today
    i = Roebe.return_german_weekday(i) if Object.const_defined? :Roebe
  end
  if i.include? ','
    splitted = i.split(',')
    first = splitted.first
    if first.count('.') > 1
      return Roebe.return_german_weekday(first) if Object.const_defined? :Roebe
    end
  else
    return i
  end
end

#return_name_of_this_curriculum(i) ⇒ Object Also known as: return_long_name_of_this_curriculum

#

return_name_of_this_curriculum

This method will return the official name of a curriculum. In order to achieve this, the method will read the file, and grab the second line, which should contain the name of the curriculum at hand.

This method will NOT remove strings such as “Bachelorcurriculum” or “Mastercurriculum”, due to the individual vector-curriculum having the very same name (Bachelor + Master).

#


193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/studium/base/curriculum.rb', line 193

def return_name_of_this_curriculum(i)
  file = return_file_for_this_curriculum(i)
  if file.nil?
    e 'Something went wrong for the input '+steelblue(i)+'.'
    e 'No match could be found for it. Are you sure that it must exist?'
    exit
  elsif File.exist? file
    dataset = readlines_with_proper_encoding(file)
    name = dataset[1].delete('#=').strip
    return name
  end
end

#return_name_of_this_curriculum_based_on_its_id_number(i) ⇒ Object Also known as: from_curriculum_id_to_curriculum_name, return_curriculum_name_of_this_curriculum_number, curriculum_number_to_curriculum_name, name_of_this_curriculum?, return_name_of_the_curriculum_based_on_this_curriculum_id, return_name_of_the_curriculum, turn_id_to_curriculum_name

#

return_name_of_this_curriculum_based_on_its_id_number

The input to this method should be the ID of a curriculum number, ideally as a String, such as '033290'.

#


245
246
247
# File 'lib/studium/base/curriculum.rb', line 245

def return_name_of_this_curriculum_based_on_its_id_number(i)
  ::Studium.map_curriculum_number_to_curriculum_name(i)
end

#return_opnn(use_this_namespace = NAMESPACE) ⇒ Object Also known as: ropnn

#

return_opnn

#


724
725
726
727
728
729
730
731
# File 'lib/studium/base/misc.rb', line 724

def return_opnn(
    use_this_namespace = NAMESPACE
  )
  ::Colours::GREY+
  use_this_namespace+
  ': '+
  ::Colours::REVERT
end

#return_passed_coursesObject

#

return_passed_courses

This method will quickly return all passed courses.

#


456
457
458
459
460
461
# File 'lib/studium/base/misc.rb', line 456

def return_passed_courses
  return_dataset_from_file_lecture_information.select {|key, hash|
    hash.has_key?(:already_solved) and
    (hash[:already_solved] == true)
  }
end

#return_pwdObject Also known as: pwd?

#

return_pwd

#


129
130
131
# File 'lib/studium/base/misc.rb', line 129

def return_pwd
  "#{Dir.pwd}/".squeeze('/')
end

#return_random_curriculumObject

#

return_random_curriculum

#


21
22
23
# File 'lib/studium/base/curriculum.rb', line 21

def return_random_curriculum
  ::Studium.return_random_curriculum
end

#return_sanitized_dataset_from_the_file_lecture_informationObject Also known as: return_dataset_from_the_file_lecture_information, return_dataset_from_file_lecture_information, lecture_information_dataset, lecture_information, dataset_from_file_lecture_information, dataset_from_lecture_information, dataset_lecture_information, return_lecture_information, return_data_from_the_file_lecture_information, return_all_lectures, return_lectures_from_file_lecture_information, dataset_from_the_file_lecture_information, return_sanitized_dataset_from_file_lecture_information, return_dataset_from_the_lectures, return_sanitized_dataset, return_all_lectures_from_the_file_lecture_information

#

return_sanitized_dataset_from_the_file_lecture_information

This method will return the dataset stored in the file 'lecture_information.yml'.

#


157
158
159
# File 'lib/studium/base/misc.rb', line 157

def return_sanitized_dataset_from_the_file_lecture_information
  Studium.return_sanitized_dataset_from_the_file_lecture_information
end

#return_solved_lecturesObject

#

return_solved_lectures

This method will return only those entries that have the key :already_solved set to true.

#


591
592
593
594
595
596
# File 'lib/studium/base/misc.rb', line 591

def return_solved_lectures
  already_solved = select_lectures_with_this_key(:already_solved).select {|a,b|
    obtain(:already_solved, b) == true
  }
  already_solved
end

#return_steop_lectures(optional_ignore_already_completed_steop_lectures = true) ⇒ Object

#

return_steop_lectures (steop tag)

This method will return all registered STEOP lectures.

The optional argument will determine whether solved STEOP lectures will also be returned. By default this is not the case, meaning that we will ignore STEOP lectures that have already been solved.

#


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/studium/base/misc.rb', line 259

def return_steop_lectures(
    optional_ignore_already_completed_steop_lectures = true
  )
  if ::Studium.main_dataset?
    dataset = ::Studium.main_dataset?
  else
    dataset = return_dataset_from_the_file_lecture_information
  end
  selection = dataset.select {|a, b|
    b.has_key?(:is_a_steop_lecture) and (b[:is_a_steop_lecture] == true)
  }
  if optional_ignore_already_completed_steop_lectures
    selection = selection.reject {|a, b|
      b.has_key?(:already_solved) and (b[:already_solved] == true)
    }
  end
  return selection
end

#return_the_remote_homepage_url(of_this_lecture, dataset_to_use) ⇒ Object

#

return_the_remote_homepage_url

The first parameter denotes which particular lecture is to be investigated, in regards to its homepage-URL.

The second parameter should contain the hash-dataset that is to be used.

#


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/studium/base/prototype.rb', line 61

def return_the_remote_homepage_url(
    of_this_lecture, dataset_to_use
  )
  of_this_lecture.strip!
  _ = dataset_to_use
  if _.has_key? :homepage
    _ = _[:homepage]
  else
    e "No :homepage entry for `#{sfancy(of_this_lecture.to_s)}`."
  end
  _
end

#return_this_line_has_n_characters_as_html_colour_tags(i) ⇒ Object

#

return_this_line_has_n_characters_as_html_colour_tags

#


39
40
41
42
43
# File 'lib/studium/base/word_wrap.rb', line 39

def return_this_line_has_n_characters_as_html_colour_tags(i)
  i.scan(REGEX_FOR_OPENING_AND_CLOSING_COLOUR_TAGS).map {|entry|
    entry.size
  }.sum
end

#return_title_from_this_curriculum_file(i, use_a_shorter_name = false) ⇒ Object Also known as: return_title_of

#

return_title_from_this_curriculum_file

The first argument to this method should be the abbreviation of that particular curriculum.

Usage example:

return_title_from_this_curriculum_file(:indi2)
#


36
37
38
39
40
41
# File 'lib/studium/base/curriculum.rb', line 36

def return_title_from_this_curriculum_file(
    i,
    use_a_shorter_name = false
  )
  Studium.return_title_from_this_curriculum_file(i, use_a_shorter_name)
end

#revObject Also known as: revert

#

rev (rev tag)

#


287
288
289
290
291
292
293
# File 'lib/studium/base/colours.rb', line 287

def rev
  if @use_colours
    ::Studium::Colours.rev
  else
    ''
  end
end

#right_arrow?Boolean

#

right_arrow?

#

Returns:

  • (Boolean)


91
92
93
# File 'lib/studium/base/unicode.rb', line 91

def right_arrow?
  UNICODE_RIGHT_ARROW
end

#rinstall2Object

#

rinstall2

#


851
852
853
854
855
856
857
858
859
# File 'lib/studium/base/misc.rb', line 851

def rinstall2
  cpruby
  system 'ruby setup.rb --quiet config'
  system 'ruby setup.rb --quiet setup'
  system 'ruby setup.rb --quiet install'
  delete_file 'setup.rb'
  delete_file 'InstalledFiles'
  delete_file '.config'
end

#roebe_exam_directory?Boolean

#

roebe_exam_directory?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/studium/base/prototype.rb', line 77

def roebe_exam_directory?
  "#{RUBY_STUDIUM_HOME_DIR}exam_topics/"
end

#ruby_src_dir_at_home?Boolean

#

ruby_src_dir_at_home?

#

Returns:

  • (Boolean)


16
17
18
# File 'lib/studium/base/src_dir_at_home.rb', line 16

def ruby_src_dir_at_home?
  Studium.ruby_src_dir_at_home?
end

#runObject

#

run

#


14
15
# File 'lib/studium/base/run.rb', line 14

def run
end

#runmode?Boolean Also known as: mode?

#

runmode?

#

Returns:

  • (Boolean)


78
79
80
# File 'lib/studium/base/mode.rb', line 78

def runmode?
  @runmode
end

#sanitize_this_topic(this_topic) ⇒ Object

#

sanitize_this_topic (sanitize tag, alias tag)

This entry keeps all possible aliases to commonly used topics, in particular abbreviations.

#


147
148
149
# File 'lib/studium/base/misc.rb', line 147

def sanitize_this_topic(this_topic)
  Studium.sanitize_this_theme_topic(this_topic)
end

#sanitize_url(i, optional_extra_modes = nil) ⇒ Object Also known as: sanitized_url

#

sanitize_url

This is such a useful method that we will use it for all subclasses of Studium::Base.

#


649
650
651
# File 'lib/studium/base/misc.rb', line 649

def sanitize_url(i, optional_extra_modes = nil)
  Studium.sanitize_url(i, optional_extra_modes)
end

#select_lectures_with_this_key(searching_for_this_key) ⇒ Object

#

select_lectures_with_this_key

This method allows us to select only entries with a particular key. The key has to be passed to the method and - for now - has to be exactly the same as the key (e. g. string for strings and symbols for symbols; no automatic conversions for now).

The advantage of this method is that it will simplify a lot of code; all code that requires us to select only specific lectures.

Usage examples:

.select_lectures_with_this_key(:exam_registration_at)
.select_lectures_with_this_key(:already_solved)
#


506
507
508
509
510
511
512
513
514
# File 'lib/studium/base/misc.rb', line 506

def select_lectures_with_this_key(
    searching_for_this_key
  )
  dataset = return_sanitized_dataset_from_the_file_lecture_information
  dataset.select! {|name_of_the_lecture, inner_hash|
    inner_hash.has_key? searching_for_this_key
  } if dataset # <- Must check here, since there may be a nil.
  return dataset
end

#set_be_quietObject

#

set_be_quiet

#


819
820
821
# File 'lib/studium/base/misc.rb', line 819

def set_be_quiet
  @be_verbose = false
end

#set_be_verboseObject Also known as: be_verbose

#

set_be_verbose

#


812
813
814
# File 'lib/studium/base/misc.rb', line 812

def set_be_verbose
  @be_verbose = true
end

#set_commandline_arguments(i = ARGV) ⇒ Object

#

set_commandline_arguments

The commandline arguments are always an Array.

#


16
17
18
19
20
21
# File 'lib/studium/base/commandline_arguments.rb', line 16

def set_commandline_arguments(
    i = ARGV
  )
  i = [i].flatten.compact
  @commandline_arguments = i
end

#set_commandline_modeObject Also known as: set_commandline

#

set_commandline_mode

#


52
53
54
# File 'lib/studium/base/mode.rb', line 52

def set_commandline_mode
  set_mode :commandline
end

#set_runmode(i = ::Studium::Exams.runmode?) ⇒ Object Also known as: set_mode

#

set_runmode

This method will delegate towards Exams.set_runmode.

We have three valid modes, which can be passed as argument to this method here, as a Symbol:

(1) :commandline
(2) :www
(3) :gui

The default one is :commandline.

We tap into the class-method Exams.runmode? by default, which will be equal to passing :commandline.

#


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/studium/base/mode.rb', line 30

def set_runmode(
    i = ::Studium::Exams.runmode?
  )
  @runmode = i
  # ======================================================================= #
  # Also synchronize it into the whole studium-project. For this, we
  # require the toplevel-method called Studium.set_runmode().
  # Disabled this as of July 2020 as it interfers with .cgi scripts.
  # ======================================================================= #
  # ::Studium.set_runmode(@runmode) unless ::Studium::Exams.frozen?
  case @runmode
  # ======================================================================= #
  # === :www
  # ======================================================================= #
  when :www, :gui # WWW mode and GUI mode do not use the commandline-colours.
    ::Studium.disable_colours # Disable colours in this case.
  end
end

#set_this_cd_alias_to(cd_alias, new_content, be_verbose = :default) ⇒ Object

#

set_this_cd_alias_to

#


743
744
745
746
747
# File 'lib/studium/base/misc.rb', line 743

def set_this_cd_alias_to(
    cd_alias, new_content, be_verbose = :default
  )
  Studium.set_this_cd_alias_to(cd_alias, new_content, be_verbose)
end

#set_www_modeObject Also known as: www_mode

#

set_www_mode

Set to :www runmode through this method.

#


71
72
73
# File 'lib/studium/base/mode.rb', line 71

def set_www_mode
  set_runmode :www
end

#sfancy(i = '') ⇒ Object

#

sfancy

#


175
176
177
178
# File 'lib/studium/base/colours.rb', line 175

def sfancy(i = '')
  return ::Colours.sfancy(i) if use_colours?
  return i
end

#shall_we_make_use_of_unicode_symbols?Boolean Also known as: use_unicode_symbols?, use_unicode?

#

shall_we_make_use_of_unicode_symbols?

The most common idiom for using this method is actually via:

if use_unicode_symbols?
#

Returns:

  • (Boolean)


28
29
30
# File 'lib/studium/base/unicode.rb', line 28

def shall_we_make_use_of_unicode_symbols?
  ::Studium.shall_we_make_use_of_unicode_symbols?
end

#show_todays_dateObject

#

show_todays_date

#


353
354
355
# File 'lib/studium/base/time.rb', line 353

def show_todays_date
  e 'Today is the '+slateblue(today?)+' ('+lightgreen(weekday?)+')'; e
end

#simp(i = '') ⇒ Object

#

simp

#


167
168
169
170
# File 'lib/studium/base/colours.rb', line 167

def simp(i = '')
  return ::Colours.simp(i) if use_colours? # Delegate to module Colours in this case.
  return i
end

#sort_these_lecture_names_by_time(array, weekday) ⇒ Object

#

sort_these_lecture_names_by_time

#


521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/studium/base/time.rb', line 521

def sort_these_lecture_names_by_time(
    array, weekday
  )
  _ = main_dataset?
  array.sort_by {|entry|
    pointer = _[entry]
    lva_date = pointer['lva_dates'].select {|inner_entry|
      inner_entry.include? weekday
    }
    lva_date = lva_date.first if lva_date.is_a? Array
    lva_date = return_hour_from_this(lva_date) # This will be like "08:00-09:45"
    # ===================================================================== #
    # However had, we only need the last part, so chop it down.
    # ===================================================================== #
    if lva_date.include? '-'
      lva_date = lva_date.split('-').first
    end
    timestamp = Time.parse(lva_date)
    timestamp # And "return" it here.
  }
end

#spacerObject

#

spacer

#


736
737
738
# File 'lib/studium/base/misc.rb', line 736

def spacer
  Studium.spacer
end

#swarn(i = '') ⇒ Object

#

swarn

#


220
221
222
223
# File 'lib/studium/base/colours.rb', line 220

def swarn(i = '')
  return ::Colours.swarn(i) if @use_colours
  return i
end

#this_month_has_n_days?(this_month, this_year = Time.now.year) ⇒ Boolean

#

this_month_has_n_days?

This method will return the maximum amount of days in the given month.

#

Returns:

  • (Boolean)


174
175
176
177
178
179
180
181
# File 'lib/studium/base/time.rb', line 174

def this_month_has_n_days?(
    this_month,
    this_year = Time.now.year
  )
  this_month = this_month.to_i
  return 29 if this_month == 2 && Date.gregorian_leap?(this_year)
  COMMON_YEAR_DAYS_IN_MONTH[this_month] 
end

#total_ects_points_passed(i) ⇒ Object

#

total_ects_points_passed

#


783
784
785
# File 'lib/studium/base/misc.rb', line 783

def total_ects_points_passed(i)
  Studium.total_ects_points_passed(i)
end

#translate_dd_mm_yyyy_to_weekday(i = '25.02.2020') ⇒ Object Also known as: translate_dd_mm_yyy_to_weekday

#

translate_dd_mm_yyyy_to_weekday

This method will return the weekday of a given dd.mm.yyyy date.

If the given input is, for example, the String '25.02.2019', then this method will return the String 'Monday'.

#


268
269
270
271
272
# File 'lib/studium/base/time.rb', line 268

def translate_dd_mm_yyyy_to_weekday(
    i = '25.02.2020'
  )
  weekday?(i)
end

#try_to_require_the_rcfilesObject

#

try_to_require_the_rcfiles

#


899
900
901
902
903
# File 'lib/studium/base/misc.rb', line 899

def try_to_require_the_rcfiles
  begin
    require 'rcfiles'
  rescue LoadError; end
end

#turn_this_array_into_the_full_dataset(i, use_this_dataset) ⇒ Object

#

turn_this_array_into_the_full_dataset

This method accepts an Array of lectures that will be replaced with a full dataset.

#


66
67
68
69
70
71
72
73
74
75
# File 'lib/studium/base/misc.rb', line 66

def turn_this_array_into_the_full_dataset(
    i, use_this_dataset
  )
  hash = {}
  i.flatten.each {|name_of_the_lecture|
    pointer = use_this_dataset[name_of_the_lecture]
    hash[name_of_the_lecture] = pointer
  }
  hash
end

#unicode_blocks_line(optional_use_this_colour = nil, use_n_tokens = :default, use_this_unicode_token = :upper_half_block) ⇒ Object

#

unicode_blocks_line

This method will “draw” a (horizontal) unicode-blocks line, that is, a line that is “built” from unicode blocks.

The optional first argument can be used to use a specific colour.

Usage examples:

unicode_blocks_line :steelblue
unicode_blocks_line(:steelblue) {{ n_tokens: 84 }}
#


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
# File 'lib/studium/base/unicode.rb', line 47

def unicode_blocks_line(
    optional_use_this_colour = nil,
    use_n_tokens             = :default, # <- This defaults to 78.
    use_this_unicode_token   = :upper_half_block
  )
  case use_n_tokens
  when :default # Must come before we check for a given block.
    use_n_tokens = 78
  end
  if block_given?
    yielded = yield
    if yielded.is_a? Hash
      if yielded.has_key? :n_tokens
        use_n_tokens = yielded.delete(:n_tokens)
      end
    end
  end
  begin
    require 'roebe/toplevel_methods/unicode/unicode_block_elements.rb'
  rescue LoadError; end
  _ = (Roebe.send(use_this_unicode_token) * use_n_tokens)
  if optional_use_this_colour
    _ = ::Colours::AllColourMethods.send(optional_use_this_colour, _)
  end
  return _
end

#use_colours?Boolean

#

use_colours?

#

Returns:

  • (Boolean)


280
281
282
# File 'lib/studium/base/colours.rb', line 280

def use_colours?
  @use_colours
end

#use_opn?Boolean

#

@use_opn

#

Returns:

  • (Boolean)


35
36
37
# File 'lib/studium/base/opnn.rb', line 35

def use_opn?
  @use_opn
end

#vertical_bar?Boolean

#

vertical_bar?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/studium/base/unicode.rb', line 77

def vertical_bar?
  return '|'
end

#web_liner(this_token = '*') ⇒ Object

#

web_liner

#


656
657
658
# File 'lib/studium/base/misc.rb', line 656

def web_liner(this_token = '*')
  (this_token * 80)+N
end

#weekday?(i = Date.today.wday, use_this_language = :english) ⇒ Boolean Also known as: return_name_for_this_day, return_weekday_for, return_weekday_of, return_weekday_from_this_input, english_weekday, english_weekday?

#

weekday?

This method will return a String such as “Thursday”. Note that the english name will be returned by default. This can be changed via the second parameter to this method, which can be either :english or :german.

The input to this method should be a number, such as can be obtained via the method .wday().

A String can also be passed into this method, in a form like “dd.mm.yyyy”. So, an input String such as “10.03.2018” is perfectly valid.

#

Returns:

  • (Boolean)


582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'lib/studium/base/time.rb', line 582

def weekday?(
    i                 = Date.today.wday,
    use_this_language = :english
  )
  if i.is_a?(String) and i.include?('.')
    # ===================================================================== #
    # In this case here assume an input-String such as "12.03.2018".
    # ===================================================================== #
    begin
      i = Time.parse(i).wday
    rescue ArgumentError => error
      pp error
    end
  end
  result = Date::DAYNAMES[i]
  case use_this_language
  # ======================================================================= #
  # === :german
  # ======================================================================= #
  when :german,
       :use_german
    # ===================================================================== #
    # In this case we have to translate to the german name.
    # ===================================================================== #
    result = ENGLISH_TO_GERMAN_WEEKDAYS[result]
  end
  return result
end

#weekdays?Boolean

#

weekdays?

This method will return all weekdays, as Array, including german and english names for these weekdays.

#

Returns:

  • (Boolean)


420
421
422
423
424
425
# File 'lib/studium/base/time.rb', line 420

def weekdays?
  (
    ARRAY_GERMAN_WEEKDAYS+
    HASH_SHORT_TO_LONG_WEEKDAYS.values
  ).flatten
end

#word_wrap(text, line_width = N_CHARACTERS_PER_LINE) ⇒ Object

#

word_wrap

This method can re-arrange a given text (a String) to honour a certain size limit, such as 80 characters per line.

Keep in mind that colours that may be used inside of a tag, such as <tomato>foobar</tomato>, will also count for that limit. This has to be remembered when doing the calculation for text-wrapping.

#


28
29
30
31
32
33
# File 'lib/studium/base/word_wrap.rb', line 28

def word_wrap(
    text,
    line_width = N_CHARACTERS_PER_LINE
  )
  ::Studium.word_wrap(text, line_width)
end

#write_what_into(what, into) ⇒ Object Also known as: store_what_into

#

write_what_into

Use this method to save data into a specific file.

#


632
633
634
# File 'lib/studium/base/misc.rb', line 632

def write_what_into(what, into)
  Studium.write_what_into(what, into)
end

#www_connection_is_unavailableObject Also known as: www_is_unavailable

#

www_connection_is_unavailable

#


679
680
681
# File 'lib/studium/base/misc.rb', line 679

def www_connection_is_unavailable
  @no_connection_to_the_www = true
end

#www_mode?Boolean Also known as: is_on_www?, are_we_in_www_mode?, in_www_mode?

#

www_mode?

This method will return true if we run in www mode.

#

Returns:

  • (Boolean)


87
88
89
# File 'lib/studium/base/mode.rb', line 87

def www_mode?
  runmode? == :www
end

#yaml_dir?Boolean

#

yaml_dir?

#

Returns:

  • (Boolean)


40
41
42
# File 'lib/studium/base/prototype.rb', line 40

def yaml_dir?
  Studium.yaml_directory?
end