Class: Studium::Exams::ExamQuestion

Inherits:
Base
  • Object
show all
Defined in:
lib/studium/exams/exam_question/menu.rb,
lib/studium/exams/exam_question/misc.rb,
lib/studium/exams/exam_question/reset.rb,
lib/studium/exams/exam_question/answer.rb,
lib/studium/exams/exam_question/question.rb,
lib/studium/exams/exam_question/constants.rb,
lib/studium/exams/exam_question/exam_question.rb

Overview

Studium::Exams::ExamQuestion

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
DEFAULT_COLOUR_TO_USE =
#

DEFAULT_COLOUR_TO_USE

#
:olivedrab
USE_THESE_COLOURS =
#

USE_THESE_COLOURS

This Hash is used to set up colours. It will be passed to methods that belong to the Colours module (“namespace”), which in turn can be found in the gem called “colours”.

Using a Hash like this allows the user to customize the colours as well.

For the question, we prefer to use :olivedrab.

#
{
  one:            :steelblue,
  two:            :mediumseagreen,
  three:          :mediumpurple, # ← Used to be 'peru' up until 23.11.2019.
  four:           :olivedrab,
  five:           :lightgreen,
  default_colour: DEFAULT_COLOUR_TO_USE # Make use of the colour defined above ^^^ here.
}
DEFAULT_COLOUR_AS_ESCAPE_SEQUENCE =
#

DEFAULT_COLOUR_AS_ESCAPE_SEQUENCE

#
::Colours.remove_trailing_end_from(
  ::Colours.send(USE_THESE_COLOURS[:default_colour])
)
EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_QUESTION =
#

EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_QUESTION

This constant is like the constant called EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_ANSWER, except that here we work on double-quotes, aka '“' characters, in a question.

As of November 2019, this defaults to false, since we already use many other colours at this point.

#
false
EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_ANSWER =
#

EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_ANSWER

#
false
DEFAULT_WORD_WRAP_AT_N_CHARACTERS_PER_LINE =
#

DEFAULT_WORD_WRAP_AT_N_CHARACTERS_PER_LINE

#
72
MAY_WE_SHOW_THE_TOPIC =
false
SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

Shall we debug or shall we not debug. This is specific to this class here.

#
false
SHOW_STATISTICS =
#

SHOW_STATISTICS

If SHOW_STATISTICS is true then we will show the statistics.

#
true
STORE_TEXT =
#

STORE_TEXT

Next comes the string that we will save if we set a new delay.

#
'# ====================================================================== #
# How long to wait before showing the answer in question, in seconds.
# ====================================================================== #
delay: '

Constants inherited from Base

Base::ARRAY_HTML_COLOURS_IN_USE, Base::CHECK_FOR_INCORRECT_ENTRIES_IN_THE_QUESTION_ANSWER_FILE_THAT_SHOULD_BE_COMMENTS, Base::COLOURS, Base::COMMON_YEAR_DAYS_IN_MONTH, Base::GRAY, Base::LEFT_PADDING, Base::N_CHARACTERS_PER_LINE, Base::UNICODE_RIGHT_ARROW

Constants included from Colours

Colours::COLOURS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_proper_year_entry_to_this_line, #already_solved_this_lva_number?, #append_what_into, #available_topics_as_short_name, #average_grade, #bachelor_master_or_diploma, #base_dir?, #be_silent, #be_verbose?, #beautiful_url, #change_directory, #cheering_person, #cliner, #colour_for_ects_points, #colourize_percentage, #commandline_arguments?, #commandline_arguments_joined, #commandline_arguments_with_hyphens?, #convert_this_array_of_lectures_into_the_full_dataset, #copy, #cpruby, #create_directory, #create_file, #csv_file?, #current_month?, #datum?, #day_month_year, #debug?, #delete_file, #directory_of_the_exam_topics?, #directory_to_my_exam_topics, #directory_to_the_exam_topics?, #disable_colours, #disable_colours_globally, #do_not_be_verbose, #do_not_use_opn, #do_these_curricula_include_both_a_bachelor_and_a_master_curriculum?, #does_this_line_include_a_german_weekday?, #does_this_line_include_a_html_colour?, #e, #ecomment, #editor?, #ee, #enable_colours, #enable_colours_globally, #enable_debug, #encoding?, #english_to_german_weekday, #ensure_main_encoding, #ensure_that_the_log_directory_exists, #eparse, #erev, #esystem, #etomato, #exit_program, #expand_topic, #extract_dd_mm_yyyy, #file_lecture_information?, #file_read_with_proper_encoding, #filter_away_invalid_questions, #find_corresponding_exam_topic, #first_argument?, #first_non_hyphen_argument?, #from_curriculum_id_to_university, #german_date_notation, #german_weekday?, #german_weekdays?, #has_a_bachelor_curriculum?, #has_a_master_curriculum?, #has_this_exam_topic_been_solved?, #has_year_entry?, #hh_mm_ss_dd_mm_yyyy, #horizontal_bar?, #html_log_directory?, #is_a_master_lecture?, #is_a_weekday?, #is_connected_to_the_www?, #is_on_roebe?, #is_prüfungsimmanent?, #is_this_a_valid_html_colour?, #is_this_day_today?, #konsole_support?, #last_file?, #lectures_from_indi1, #lectures_from_indi2, #lectures_from_indi3, #lectures_from_indi4, #lectures_from_the_bachelor_genetik_curriculum, #lectures_from_the_individual_vektor_curricula, #load_yaml_dataset, #move_file, #n_days_difference_from_today_to_this_day, #no_ext_name, #no_file_at, #number_to_month, #obtain, #obtain_lectures_from_this_curriculum, #open_in_editor, #path_to_exam_topic?, #read_dataset_from_a_curriculum_file, #read_in_exam_dataset_from_this_file, #read_this_file_with_default_encoding, #readlines_from_this_input_file, #register_sigint, #remove_empty_strings, #remove_escape_sequences, #remove_internal_comments, #remove_leading_comments, #remove_leading_weekday_names_from, #remove_newlines, #remove_tags_from_this_input, #rename_kde_konsole_tab, #rename_konsole_tab?, #replace_all_html_colours_in_this, #replace_bold_token_with_default_colour, #replace_italic_token_with_default_colour, #replace_italic_token_with_this_colour, #replace_regular_numbers_with_unicode_numbers, #replace_underline_token_with_default_colour, #replace_underline_token_with_this_colour, #return_all_bachelor_lectures, #return_all_exams_on_this_day, #return_all_numbers_from, #return_all_registered_curricula, #return_all_steop_lectures, #return_current_year, #return_dataset_for_this_topic, #return_dataset_from_this_curriculum_file, #return_dd_mm_yy_and_time_from, #return_directory_for, #return_ects_points_from_these_lectures, #return_either_grey_or_the_custom_colour_for_answers, #return_either_grey_or_the_custom_colour_for_questions, #return_file_for_this_curriculum, #return_german_name_for_this_english_month, #return_german_weekday_of?, #return_hh_mm_ss_from, #return_hour_from_this, #return_lectures_from_bachelor_vektor_curriculum, #return_lectures_with_at_the_least_one_upcoming_exam, #return_local_path_of_this_pwdstud, #return_lva_number_of_this_lecture, #return_month_fitting_to_this_input, #return_n_days_until_monday, #return_n_days_until_sunday, #return_n_exam_questions_in, #return_n_questions_were_answered_for_this_topic, #return_name_of_the_weekday, #return_name_of_this_curriculum, #return_name_of_this_curriculum_based_on_its_id_number, #return_opnn, #return_passed_courses, #return_pwd, #return_random_curriculum, #return_sanitized_dataset_from_the_file_lecture_information, #return_solved_lectures, #return_steop_lectures, #return_the_remote_homepage_url, #return_this_line_has_n_characters_as_html_colour_tags, #return_title_from_this_curriculum_file, #rev, #right_arrow?, #rinstall2, #roebe_exam_directory?, #ruby_src_dir_at_home?, #runmode?, #sanitize_this_topic, #sanitize_url, #select_lectures_with_this_key, #set_be_quiet, #set_be_verbose, #set_commandline_arguments, #set_commandline_mode, #set_runmode, #set_this_cd_alias_to, #set_www_mode, #sfancy, #shall_we_make_use_of_unicode_symbols?, #show_todays_date, #simp, #sort_these_lecture_names_by_time, #spacer, #swarn, #this_month_has_n_days?, #total_ects_points_passed, #translate_dd_mm_yyyy_to_weekday, #try_to_require_the_rcfiles, #turn_this_array_into_the_full_dataset, #unicode_blocks_line, #use_colours?, #use_opn?, #vertical_bar?, #web_liner, #weekday?, #weekdays?, #word_wrap, #write_what_into, #www_connection_is_unavailable, #www_mode?, #yaml_dir?

Methods included from Colours

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

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true, &block) ⇒ ExamQuestion

#

initialize

The very first argument given to this class is usually the topic that is sought, such as “bem1” or “amg1” or “plants”, and so forth.

#


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/studium/exams/exam_question/exam_question.rb', line 99

def initialize(
    commandline_arguments = ARGV,
    run_already           = true,
    &block
  )
  set_commandline_arguments(
    commandline_arguments
  )
  reset
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded # (case tag)
    # ===================================================================== #
    # === :disable_colours
    # ===================================================================== #
    when :disable_colours,
         :no_colours
      # =================================================================== #
      # The user does not want to use colours in this case, so let's
      # disable colours then.
      # =================================================================== #
      disable_colours
      set_mode :www # ← Experimental as of 13.04.2019.
    # ===================================================================== #
    # === :then_determine_the_split_position_without_using_colours
    # ===================================================================== #
    when :then_determine_the_split_position_without_using_colours
      @internal_hash[:do_determine_the_split_position] = true
      disable_colours
    # ===================================================================== #
    # === :then_determine_the_split_position
    # ===================================================================== #
    when :then_determine_the_split_position
      @internal_hash[:do_determine_the_split_position] = true
    # ===================================================================== #
    # === :then_determine_the_split_position_while_disabling_the_colours
    # ===================================================================== #
    when :then_determine_the_split_position_while_disabling_the_colours
      @internal_hash[:do_determine_the_split_position] = true
      disable_colours
      set_mode :www # ← Experimental as of 13.04.2019.
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet
      run_already = false
    end
  end
  case run_already
  # ======================================================================= #
  # === :do_not_run
  #
  # Handle the situation when we do not want to run automatically.
  #
  # This is for arguments such as :dont_run_yet.
  # ======================================================================= #
  when :do_not_run,
       :do_not,
       :dont_run,
       :dont_run_yet,
       :do_not_run_yet
    run_already = false
  # ======================================================================= #
  # === :commandline
  # ======================================================================= #
  when :commandline
    run_already = false
    set_commandline
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Studium::Exams::ExamQuestion[]

#


994
995
996
# File 'lib/studium/exams/exam_question/exam_question.rb', line 994

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

.rename_konsole_tab?Boolean

#

Studium::Exams::ExamQuestion.rename_konsole_tab?

#

Returns:

  • (Boolean)


81
82
83
# File 'lib/studium/exams/exam_question/exam_question.rb', line 81

def self.rename_konsole_tab?
  @rename_konsole_tab
end

.set_rename_konsole_tab(i) ⇒ Object

#

Studium::Exams::ExamQuestion.set_rename_konsole_tab

#


88
89
90
# File 'lib/studium/exams/exam_question/exam_question.rb', line 88

def self.set_rename_konsole_tab(i)
  @rename_konsole_tab = i
end

Instance Method Details

#ask_the_exam_question(exam_question = exam_question?, , use_this_colour = colour_for_questions? ) ⇒ Object Also known as: show_question, ask_the_question, ask_this_question

#

ask_the_exam_question (question tag, ask tag)

Simply display the question via this method.

#


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

def ask_the_exam_question(
    exam_question   = exam_question?,
    use_this_colour = colour_for_questions?
  )
  e
  # ======================================================================= #
  # === Handle underlined text next
  # ======================================================================= #
  if line_contains_underline_token?(exam_question) and use_colours?
    # ===================================================================== #
    # Colourize <ud> for underline next:
    # ===================================================================== #
    exam_question = replace_underline_token_with_default_colour(exam_question, use_this_colour)
  end
  # ======================================================================= #
  # === Handle italic text next
  # ======================================================================= #
  if line_contains_italic_token?(exam_question) and use_colours?
    # ===================================================================== #
    # Colourize <i> for italic next:
    # ===================================================================== #
    exam_question = replace_italic_token_with_default_colour(exam_question, use_this_colour)
  end
  # ======================================================================= #
  # First, handle the commandline situation:
  # ======================================================================= #
  if commandline?
    consider_renaming_konsole_tab # Consider renaming the konsole tab first.
    print return_either_grey_or_the_custom_colour_for_questions
    # ===================================================================== #
    # === Show the topic if the user requested us to do so. Since as of
    #     April 2022 this is now embedded into the cliner-result.
    # ===================================================================== #
    if may_we_show_the_topic?
      fancy_cliner(
        Studium.find_corresponding_exam_title(exam_title?)
      )
      e
    else
      fancy_cliner
    end
    # ===================================================================== #
    # Output the result finally.
    # ===================================================================== #
    _ = ::Colours.replace_number_words_with_the_corresponding_html_colour(
        DEFAULT_COLOUR_AS_ESCAPE_SEQUENCE+
        exam_question,
        USE_THESE_COLOURS
    )
    e ::Colours.fancy_parse(_, use_this_colour)
    e if may_we_show_the_topic?
    fancy_cliner
  else # else tag
    # ===================================================================== #
    # === WWW mode
    #
    # Else we assume that this class is used on the web.
    # ===================================================================== #
    result  = ''.dup
    result << "#{exam_question}#{N}<br><br>"
    @internal_hash[:result_for_www] = result
    # ===================================================================== #
    # Next, show the question, unless we operate in WWW mode.
    # ===================================================================== #
    e result unless www_mode?
  end
  e
end

#ask_the_question_then_sleep_then_reveal_the_answer_to_that_questionObject Also known as: ask_question_then_show_the_answer_after_a_delay, do_ask_a_random_question_before_showing_the_answer, show_question_then_sleep_then_show_answer, ask_sleep_show, ask_the_question_then_reveal_the_answer

#

ask_the_question_then_sleep_then_reveal_the_answer_to_that_question

#


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/studium/exams/exam_question/misc.rb', line 22

def ask_the_question_then_sleep_then_reveal_the_answer_to_that_question
  # ======================================================================= #
  # Next warn the user if there are too many exams registered. This
  # should be shown after the topic has been optionally displayed.
  # Afterwards we will begin to ask the exam-question at hand.
  # ======================================================================= #
  consider_warning_the_user_if_there_are_too_many_exams_registered
  ask_the_exam_question
  sleep_default_delay
  reveal_the_exam_answer
end

#assign_url(i) ⇒ Object

#

assign_url

Only call this method after making a line.include? 'URL:' check. The reason for this is that we will only apply this method on a line that has this substring representing a remote URL.

#


702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# File 'lib/studium/exams/exam_question/misc.rb', line 702

def assign_url(i)
  if use_unicode_symbols?
    nice_token = '' # We will use a slightly prettier symbol for Unicode in this case.
  else
    nice_token = '=>'
  end
  i =~ /URL:\s*(.*)( |)/
  url = sanitize_url($1.to_s.dup) # URL is something like: "http://de.wikipedia.org/wiki/Ester"
  url = url.first if url.is_a? Array
  i = i.dup if i.frozen?
  begin
    # ===================================================================== #
    # The next regex shall also check for input such as:
    #
    #   URL: https://en.wikipedia.org/wiki/2,4-Dinitrophenol
    #   URL: https://en.wikipedia.org/wiki/File:Histidin_-_Histidine.svg
    #
    # Since as of 11.11.2018, we also include any other entry that
    # starts with 'https:'.
    # ===================================================================== #
    if $1 # See: https://rubular.com/r/rNeLS2MH6f
      remote_URL = $1.to_s.dup
      i.gsub!(/URL:\s*(.*)( |)/, nice_token+' \1') # ← Also add a '=>' token.
      if is_on_roebe?
        # ================================================================= #
        # Store this on my home system in a file, in this case.
        # ================================================================= #
        what = "#{remote_URL}\n"
        into = log_dir?+'last_exam_questions_URL.md'
        append_what_into(what, into)
      end
    end
    i = i.to_s.dup
    return i
  rescue Exception => error
    e "Debugging for `#{sfancy(i.to_s)}`:"
    pp error
    p url.class
    e sfancy(url)
  end
end

#assign_url_or_colourize_https_substring(i) ⇒ Object

#

assign_url_or_colourize_https_substring

#


503
504
505
506
507
508
509
# File 'lib/studium/exams/exam_question/exam_question.rb', line 503

def assign_url_or_colourize_https_substring(i)
  if i.include?(' URL:')
    assign_url(i)
  elsif i.include?('  https://')
    colourize_https_substring(i)
  end
end

#colour_for_answers?Boolean

#

colour_for_answers?

#

Returns:

  • (Boolean)


864
865
866
# File 'lib/studium/exams/exam_question/exam_question.rb', line 864

def colour_for_answers?
  @internal_hash[:colour_for_answers]
end

#colour_for_questions?Boolean

#

colour_for_questions?

#

Returns:

  • (Boolean)


871
872
873
# File 'lib/studium/exams/exam_question/exam_question.rb', line 871

def colour_for_questions?
  @internal_hash[:colour_for_questions]
end

#colourize_https_substring(i) ⇒ Object

#

colourize_https_substring

Input that passes into the following method, can look like this:

'Das "CDT-Toxin". => https://www.ncbi.nlm.nih.gov/pubmed/24253566'
#


491
492
493
494
495
496
497
498
# File 'lib/studium/exams/exam_question/exam_question.rb', line 491

def colourize_https_substring(i)
  if i.include? 'https://'
    use_this_regex = /(https:\/\/.+)/ # See: https://rubular.com/r/4quDI8hKxS
    i =~ use_this_regex
    i.gsub!(use_this_regex, slateblue('\1')) if $1
  end
  return i
end

#consider_renaming_konsole_tabObject

#

consider_renaming_konsole_tab

We will delegate to class SetTerminalTitle in order to rename the KDE konsole title.

#


463
464
465
466
467
# File 'lib/studium/exams/exam_question/misc.rb', line 463

def consider_renaming_konsole_tab
  if Studium::Exams::ExamQuestion.rename_konsole_tab?
    rename_kde_konsole_tab(topic?)
  end
end

#consider_warning_the_user_if_there_are_too_many_exams_registered(threshold_value = THRESHOLD_VALUE_N_EXAMS_AT_MAXIMUM) ⇒ Object

#

consider_warning_the_user_if_there_are_too_many_exams_registered

The threshold value of n exam questions at maximum is at 1000 usually.

#


794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/studium/exams/exam_question/exam_question.rb', line 794

def consider_warning_the_user_if_there_are_too_many_exams_registered(
    threshold_value = THRESHOLD_VALUE_N_EXAMS_AT_MAXIMUM
  )
  if WARN_THE_USER_IF_THERE_ARE_TOO_MANY_QUESTIONS_REGISTERED_IN_AN_EXAM_TOPIC and
    # ===================================================================== #
    # Check if we have more questions than we are allowed to have.
    # ===================================================================== #
    (n_exam_questions? > threshold_value)
    e
    opnn; e swarn('Do note that there are too many exam questions '\
            'registered in the file:')
    e
    e "  #{sfile(which_file?)}"
    e
  end
end

#custom_colours?Boolean

#

custom_colours?

#

Returns:

  • (Boolean)


118
119
120
121
122
123
# File 'lib/studium/exams/exam_question/misc.rb', line 118

def custom_colours?
  [
    @internal_hash[:colour_for_questions],
    @internal_hash[:colour_for_answers]
  ]
end

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


332
333
334
# File 'lib/studium/exams/exam_question/exam_question.rb', line 332

def dataset?
  @internal_hash[:dataset_from_the_file]
end

#default_colour?Boolean

#

default_colour?

#

Returns:

  • (Boolean)


578
579
580
# File 'lib/studium/exams/exam_question/exam_question.rb', line 578

def default_colour?
  USE_THESE_COLOURS[:default_colour]
end

#default_delay?Boolean

#

default_delay?

#

Returns:

  • (Boolean)


479
480
481
# File 'lib/studium/exams/exam_question/exam_question.rb', line 479

def default_delay?
  DEFAULT_DELAY
end

#delay?Boolean Also known as: delay

#

delay?

#

Returns:

  • (Boolean)


250
251
252
# File 'lib/studium/exams/exam_question/exam_question.rb', line 250

def delay?
  @internal_hash[:delay]
end

#determine_whether_we_will_rename_the_konsole_tabObject

#

determine_whether_we_will_rename_the_konsole_tab

This method should be called from within the method called reset().

#


427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/studium/exams/exam_question/misc.rb', line 427

def determine_whether_we_will_rename_the_konsole_tab
  if is_on_roebe?
    if File.exist? FILE_RENAME_KONSOLE_TAB
      _ = load_file_rename_konsole_tab
      if _ == true
        do_rename_konsole_tab
      else
        do_not_rename_konsole_tab
      end
    else
      do_not_rename_konsole_tab
    end
  else
    do_not_rename_konsole_tab
  end
end
#

This method will backup files and similar activities.

#


343
344
345
346
347
348
349
350
351
# File 'lib/studium/exams/exam_question/misc.rb', line 343

def do_log_related_and_backup_related_actions
  unless Studium.is_in_www_mode?
    Studium.backup_this_exam_file(exam_file?) # { :be_verbose }
    hash = {} # Build up our data structure here, as a Hash.
    hash[:question_was_asked_when] = Time.now
    hash[:question_full_line]      = line?
    Studium::Log::StoreLastQuestionAskedIntoFile.new(hash) # { :be_verbose }
  end
end

#do_not_rename_konsole_tabObject

#

do_not_rename_konsole_tab

#


479
480
481
# File 'lib/studium/exams/exam_question/misc.rb', line 479

def do_not_rename_konsole_tab
  Studium::Exams::ExamQuestion.set_rename_konsole_tab(false)
end

#do_rename_konsole_tabObject

#

do_rename_konsole_tab

#


472
473
474
# File 'lib/studium/exams/exam_question/misc.rb', line 472

def do_rename_konsole_tab
  Studium::Exams::ExamQuestion.set_rename_konsole_tab(true)
end

#download_exam_topicsObject

#

download_exam_topics

You can use this method to download all exam topics.

To call this, do:

qa --dexamtopics
#


541
542
543
# File 'lib/studium/exams/exam_question/misc.rb', line 541

def download_exam_topics
  Studium.download_exam_topics
end

#edit_sanitize_topics_in_vimObject

#

edit_sanitize_topics_in_vim

To trigger this, do:

qa --vim
#


278
279
280
281
282
283
284
# File 'lib/studium/exams/exam_question/misc.rb', line 278

def edit_sanitize_topics_in_vim
  position_in_the_file = 445
  file =
    RUBY_STUDIUM_HOME_DIR+'toplevel_methods/find_exam_topic_and_exam_title.rb'
  _ = 'vim '+file+' +'+position_in_the_file.to_s
  esystem _
end

#exam_answer?Boolean Also known as: answer?, answer, last

#

exam_answer?

#

Returns:

  • (Boolean)


622
623
624
# File 'lib/studium/exams/exam_question/exam_question.rb', line 622

def exam_answer?
  @internal_hash[:exam_answer]
end

#exam_file?Boolean Also known as: file?

#

exam_file?

This query-method shows as to where the specific file at hand is.

#

Returns:

  • (Boolean)


159
160
161
# File 'lib/studium/exams/exam_question/misc.rb', line 159

def exam_file?
  @internal_hash[:exam_file]
end

#exam_pool?Boolean

#

exam_pool?

#

Returns:

  • (Boolean)


555
556
557
# File 'lib/studium/exams/exam_question/misc.rb', line 555

def exam_pool?
  @internal_hash[:exam_pool]
end

#exam_question?Boolean Also known as: question?, question, first

#

exam_question?

#

Returns:

  • (Boolean)


521
522
523
# File 'lib/studium/exams/exam_question/exam_question.rb', line 521

def exam_question?
  @internal_hash[:exam_question]
end

#exam_question_line?Boolean Also known as: line?, line, full_question_line?

#

exam_question_line?

#

Returns:

  • (Boolean)


903
904
905
# File 'lib/studium/exams/exam_question/exam_question.rb', line 903

def exam_question_line?
  @internal_hash[:exam_question_line]
end

#fancy_cliner(optional_content_to_be_displayed = nil) ⇒ Object

#

fancy_cliner

Since as of April 2022 this method can also optionally display some content. If this is the case then said content will be padded via '*'.

#


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

def fancy_cliner(
    optional_content_to_be_displayed = nil
  )
  print seagreen('') # Always reset the colour here first.
  if optional_content_to_be_displayed
    e mediumaquamarine('*' * 3)+' '+
      forestgreen( # or lightskyblue
        optional_content_to_be_displayed
      )+
      ' '+
      mediumaquamarine(
        '*' * (75 - optional_content_to_be_displayed.size)
      )
  else
    cliner('*', :mediumaquamarine)
  end
end

#generate_statistical_webpageObject

#

generate_statistical_webpage

Invoke like so:

qa --www
#


361
362
363
364
365
366
367
368
# File 'lib/studium/exams/exam_question/misc.rb', line 361

def generate_statistical_webpage
  require 'studium/statistics/report_how_many_exam_questions_were_answered.rb'
  Studium::Statistics::ReportHowManyExamQuestionsWereAnswered.generate_webpage
  require 'open'
  Open.in_browser(
    Dir.home+'/Studium/html/statistics.html'
  )
end

#internal_hash?Boolean

#

internal_hash?

#

Returns:

  • (Boolean)


585
586
587
# File 'lib/studium/exams/exam_question/exam_question.rb', line 585

def internal_hash?
  @internal_hash
end

#invoke_all_the_necessary_steps_before_the_question_is_askedObject Also known as: initial_steps

#

invoke_all_the_necessary_steps_before_the_question_is_asked

#


975
976
977
978
979
980
981
# File 'lib/studium/exams/exam_question/exam_question.rb', line 975

def invoke_all_the_necessary_steps_before_the_question_is_asked
  determine_the_topic
  try_to_read_in_the_dataset_from_the_corresponding_exam_file
  sanitize_the_obtained_dataset
  pick_a_random_line_from_the_obtained_dataset
  parse_the_random_line_from_the_obtained_dataset
end

#line_contains_bold_token?(i = line?) ) ⇒ Boolean

#

line_contains_bold_token?

#

Returns:

  • (Boolean)


949
950
951
# File 'lib/studium/exams/exam_question/exam_question.rb', line 949

def line_contains_bold_token?(i = line?)
  (i.include?('<b>') and i.include?('</b>'))
end

#line_contains_italic_token?(i = line?) ) ⇒ Boolean

#

line_contains_italic_token?

#

Returns:

  • (Boolean)


933
934
935
936
# File 'lib/studium/exams/exam_question/exam_question.rb', line 933

def line_contains_italic_token?(i = line?)
  (i.include?('<it>') and i.include?('</it>')) or
  (i.include?('<i>')  and i.include?('</i>'))
end

#line_contains_underline_token?(i = line?) ) ⇒ Boolean

#

line_contains_underline_token?

#

Returns:

  • (Boolean)


941
942
943
944
# File 'lib/studium/exams/exam_question/exam_question.rb', line 941

def line_contains_underline_token?(i = line?)
  (i.include?('<ud>') and i.include?('</ud>')) or
  (i.include?('<u>')  and i.include?('</u>'))
end

#load_file_rename_konsole_tabObject

#

load_file_rename_konsole_tab

#


150
151
152
# File 'lib/studium/exams/exam_question/misc.rb', line 150

def load_file_rename_konsole_tab
  YAML.load_file(FILE_RENAME_KONSOLE_TAB)
end

#main_file_exists?(i = exam_file? ) ⇒ Boolean

#

main_file_exists?

#

Returns:

  • (Boolean)


166
167
168
169
170
# File 'lib/studium/exams/exam_question/misc.rb', line 166

def main_file_exists?(
    i = exam_file?
  )
  i and File.exist?(i)
end

#may_we_show_the_topic?Boolean Also known as: may_we_show_the_topic

#

may_we_show_the_topic?

#

Returns:

  • (Boolean)


718
719
720
# File 'lib/studium/exams/exam_question/exam_question.rb', line 718

def may_we_show_the_topic?
  @internal_hash[:may_we_show_the_topic]
end
#

menu (menu tag)

This is the main menu-interface of this class, the part of the code where we take the commandline (if the user has done so) and evaluate what is to be done.

By default, we will assume that the user has not given any special instructions, hence why the default argument is nil.

Next we show some usage examples:

qa "delay = 3.0"
qa delay?
#


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/studium/exams/exam_question/menu.rb', line 31

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === qa --all-topics?
    #
    # Entry point for showing all available exam-topics:
    #
    #   qa --show_topics
    #
    # ===================================================================== #
    when /^-?-?ALL/,
         /^-?-?TOPICS/,
         /^-?-?available(_|-)?topics\??$/i,
         /^-?-?topics\??$/i,
         /^-?-?show(_|-)?topics$/i,
         /^-?-?all(_|-)?topics$/i,
         /^-?-?ALL(-|_| )?TOPICS$/i,
         /^-?-?all(-|_| )?topics\??$/i,
         /^-?-?all(-|_| )?topics\??$/i,
         /^-?-?show(-|_| )?available(-|_| )?topics$/i,
         /^-?-?show(-|_| )?all(-|_| )?exam(-|_| )?topics$/i,
         'detailed_topic'
      show_available_topics # This also includes an exit-step.
    # ===================================================================== #
    # === qa amg1 --also-ask-from-solved-questions
    # === qa amg1 --full-pool
    # === qa amg1 --all-questions
    # === qa amg1 --everything
    #
    # This entry point allows us to pick a random question from ALL
    # questions of the given example theme, not only from the pool
    # that does not end with a trailing "[]".
    #
    # And yet another usage example:
    #
    #   qa agrarmarkt --full
    #
    # ===================================================================== #
    when /^-?-?also(-|_| )?ask(-|_| )?from(-|_| )?solved(-|_| )?questions$/i,
         /^-?-?full(-|_| )?pool$/i,
         /^-?-?full$/i,
         /^-?-?all(-|_| )?questions$/i,
         /^-?-?everything$/i
      @internal_hash[:reject_lines_that_end_with_a_done_token] = false
    # ===================================================================== #
    # === qa --last-question?
    # ===================================================================== #
    when 'LAST?', # qa LAST_QUESTION?
         /^-?-?last$/,
         /^-?-?last(_|-)?question\??$/i
      show_last_question_asked
      exit_program
    # ===================================================================== #
    # === qa --total?
    # ===================================================================== #
    when /^-?-?TOTAL\??$/i # qa TOTAL?
      show_how_many_exam_questions_are_available
      exit_program
    # ===================================================================== #
    # === SHOW_ALL
    #
    # Invocation example:
    #
    #   qa ethik --show-all
    #
    # ===================================================================== #
    when /^-?-?show(_|-)?all$/i,
         /^-?-?show(_|-)?everything$/i
      show_content_of_this_topic(topic?)
      exit
    # ===================================================================== #
    # === qa --default-topic?
    # ==================================================================== #
    when /^-?-?default(_|-)?topic\??$/i
      report_the_default_topic_in_use
      exit
    # ===================================================================== #
    # === qa --n-topics
    # ===================================================================== #
    when /^-?-?n(_|-)?topics$/i # qa N_TOPICS
      report_how_many_topics_are_available
      exit_program
    # ===================================================================== #
    # === qa --show-statistics
    # ===================================================================== #
    when /^-?-?show(_|-| )?statistics/i
      show_statistics
      exit_program
    # ===================================================================== #
    # === qa --filesize?
    # ===================================================================== #
    when /^-?-?size\??/i,
         /^-?-?filesize\??/i
      show_filesize_of_all_exams
      exit
    # ===================================================================== #
    # === qa --show-topic?
    # ===================================================================== #
    when /^-?-?show(_|-| )?topic\??/i
      report_whether_we_will_show_the_topic
      exit_program
    # ===================================================================== #
    # === qa --upload_exams
    # ===================================================================== #
    when 'examtopics?',
         'upload_exam_topics',
         /^upload_?exams/,
         'uexams',
         'uexam'
      Studium.upload_exam_questions { :be_verbose }
    # ===================================================================== #
    # === qa ALL_SOLVED
    #
    # This entry point will mark all questions from a particular topic
    # to "solved", that is, to have been answered already.
    #
    # Usage example:
    #
    #   qa agrarmarkt --all-solved
    #
    # ===================================================================== #
    when /^-?-?all(-|_| )?solved$/i
      set_all_questions_from_the_topic_to_solved
      exit
    # ===================================================================== #
    # === qa --nquestions?
    # ===================================================================== #
    when /^-?-?n(_|-| )?questions\??$/i
      report_how_many_registered_questions_are_available
      exit
    # ===================================================================== #
    # === qa OPEN
    #
    # This entry point exists to edit this file here.
    # ===================================================================== #
    when 'OPEN',
         'OPENALL',
         'OALL',
         /^-?-?open$/
      open_this_file_in_editor
      exit_program
    # ===================================================================== #
    # === qa --ask_last_topic
    # ===================================================================== #
    when /^-?-?ask(_|-)?last(_|-)?topic$/
      target_file = "#{log_dir?}use_this_exam_topic.yml"
      if File.exist? target_file
        use_this_topic = YAML.load_file(
          target_file
        )
        set_use_this_topic(use_this_topic)
      else
        no_file_exists_at(target_file)
      end
      exit_program
    # ===================================================================== #
    # === qa ftp
    # ===================================================================== #
    when 'ftp',
         /^ftp(_|-)?upload$/
      Studium.upload_exam_questions { :be_verbose }
      exit_program
    # ===================================================================== #
    # === qa EDIT
    # ===================================================================== #
    when /^-?-?edit$/i,
         /^-?-?vim$/i
      edit_sanitize_topics_in_vim
      exit_program
    # ===================================================================== #
    # === qa --set_default_topic=phys
    # ===================================================================== #
    when /^-?-?set_default_topic=(.+)/,
         /^-?-?set-default-topic=(.+)/,
         /^-?-?topic=(.+)/,
         /^-?-?setdefaulttopic=(.+)/
      set_default_topic_for_the_gui($1.to_s)
      exit
    # ===================================================================== #
    # === qa --rename-tab?
    # ===================================================================== #
    when 'rename_tab?',
         '--rename-tab?',
         'renametab',
         'renametab?' # qa rename_tab?
      tell_whether_we_will_rename_the_kde_konsole_tab
      exit_program
    # ===================================================================== #
    # === qa --download-exam-topics
    # ===================================================================== #
    when /download_?exam_?topics/,
         /((_|-)+(_|-)+download(_|-)+exam(_|-)+topics)/,
         /^-?-?dexamtopics/
      download_exam_topics
    # ===================================================================== #
    # === qa --delay?
    # ===================================================================== #
    when 'del?',
         'DELAY?',
         'speed?', # qa delay?
         'del',
         /^-?-?delay\??$/i
      report_the_delay
      exit_program(:no_newline)
    # ===================================================================== #
    # === qa LASTTOPIC
    # ===================================================================== #
    when /^-?-?last(_|-)?topic$/i,
         /^-?-?show(_|-)?last(_|-)?topic$/i,
         'ltopic?'
      show_the_last_topic
      exit
    # ===================================================================== #
    # === qa --set-delay=2.8
    # ===================================================================== #
    when /^-?-?set(-|_| )?delay=(.+)/
      set_and_store_delay($2.to_s.dup)
      exit
    # ===================================================================== #
    # === qa --www
    # ===================================================================== #
    when /^-?-?www$/i
      generate_statistical_webpage
      exit
    # ===================================================================== #
    # === qa --finished?
    # ===================================================================== #
    when /^-?-?finished\??$/i
      show_all_finished_exam_topics
      exit
    # ===================================================================== #
    # === qa --log-dir?
    # ===================================================================== #
    when 'log?',
         'log_dir?',
         'store_where?',
         'store_where',
         '--dir?',
         'dir?',
         /^-?-?log(-|_| )?dir\??$/i
      e "#{rev}The log directory can be found at: "\
        "#{sdir(log_dir?)}"
      exit
    # ===================================================================== #
    # === qa --help?
    # ===================================================================== #
    when 'HELP',
         'help',
         '--help',
         '--hep',
         '--help?',
         'help?'
      show_help_usage(:do_exit)
    # ===================================================================== #
    # === ptype --openlast
    # ===================================================================== #
    when /^OPEN(_|-)?LAST$/i,
         /^OLAST$/i
      open_the_last_file_via_your_editor
      exit
    # ===================================================================== #
    # === qa --german?
    # ===================================================================== #
    when 'SOLVED_GERMAN?',
         'german',
         'german?',
         'in_german?',
         'n_solved_in_german?',
         'nsolved2?',
         'n_german?',
         '--german?',
         /^-?-?solved(_|-)?in(_|-)?german$/i
      show_how_many_exam_questions_were_already_solved_in_german
      exit_program
    # ===================================================================== #
    # === qa --nsolved?
    # ===================================================================== #
    when /SOLVED/,
         'N_SOLVED?',
         'n_solved?',
         '--nsolved?',
         '--nsolved',
         'nsolved',
         '--english?',
         '--english',
         'english',
         'english?'
      show_how_many_exam_questions_were_already_solved
      exit_program
    else
      if ::Studium.is_this_an_exam_topic?(i)
        set_exam_topic(i)
      end
    end
  end
end
#

menu_on_the_commandline_as_a_string

#


814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# File 'lib/studium/exams/exam_question/exam_question.rb', line 814

def menu_on_the_commandline_as_a_string(
    i = commandline_as_string
  )
  case i
  # ======================================================================= #
  # === qa --open
  #
  # This entry point can be used to open an exam topic file via the
  # editor.
  #
  # A commandline example follows:
  #
  #   qa ab2 open
  #
  # ======================================================================= #
  when /open (.+)/,
       /(.+) open/
    topic = $1.to_s.dup # Example: qa --open amg
    topic = find_corresponding_exam_topic(topic)
    topic = ::Studium.directory_to_my_exam_topics+File.basename(topic)
    open_this_file_in_editor(topic)
    exit
  # ======================================================================= #
  # === qa "delay = 3.0"
  #
  # Invoke this like so:
  #
  #   qa delay = 3.0
  #
  # ======================================================================= #
  when /^DELAY =? ?(\d{0,1}.\d{1})/i,
       /^DEL =? ?(\d{0,1}.\d{1})/i,
       /^set_delay =? ?(\d{0,1}.\d{1})/i,
       /^set_delay :? ?(\d{0,1}.\d{1})/i,
       /^set_delay ?(\d{0,1}.\d{1})/i # === qa set_delay 3.1
    _ = $1.to_s.dup
    set_and_store_delay(_)
  end
end

#n_questions_already_answered?Boolean

#

n_questions_already_answered?

#

Returns:

  • (Boolean)


878
879
880
# File 'lib/studium/exams/exam_question/exam_question.rb', line 878

def n_questions_already_answered?
  @internal_hash[:n_exam_questions_answered]
end

#n_questions_available?Boolean Also known as: n_exam_questions?

#

n_questions_available?

Return how many questions are available in the given dataset at hand.

#

Returns:

  • (Boolean)


887
888
889
# File 'lib/studium/exams/exam_question/exam_question.rb', line 887

def n_questions_available?
  @internal_hash[:n_exam_questions_in_total]
end

#notify_the_user_that_all_questions_have_been_answered_already(which_topic = which_topic? ) ⇒ Object

#

notify_the_user_that_all_questions_have_been_answered_already

#


107
108
109
110
111
112
113
# File 'lib/studium/exams/exam_question/misc.rb', line 107

def notify_the_user_that_all_questions_have_been_answered_already(
    which_topic = which_topic?
  )
  opnn; e 'All questions have already been answered '
  opnn; e "for the topic `#{orange(which_topic)}`. "\
          "#{slateblue(cheering_person?)}"
end

#open_the_last_file_via_your_editor(this_file = last_file? ) ⇒ Object

#

open_the_last_file_via_your_editor

#


81
82
83
84
85
# File 'lib/studium/exams/exam_question/misc.rb', line 81

def open_the_last_file_via_your_editor(
    this_file = last_file?
  )
  open_this_file_in_editor(this_file)
end

#open_this_file_in_editor(this_file = __FILE__) ⇒ Object

#

open_this_file_in_editor

Open this file in the editor.

#


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/studium/exams/exam_question/misc.rb', line 92

def open_this_file_in_editor(
    this_file = __FILE__
  )
  use_this_editor = editor?
  # ======================================================================= #
  # Since as of December 2017, on my home system, I will use nano instead.
  # ======================================================================= #
  use_this_editor = 'nano -w' if is_on_roebe?
  _ = "#{use_this_editor} #{this_file}" #&
  esystem _
end

#opnnObject

#

opnn

#


415
416
417
418
419
420
# File 'lib/studium/exams/exam_question/misc.rb', line 415

def opnn
  super(
    namespace:   @namespace,
    use_colours: use_colours?
  )
end

#parse_the_random_line_from_the_obtained_dataset(_ = ) ⇒ Object Also known as: determine_the_split_position, determine_index_position, parse_that_line, determine_the_question_and_the_answer

#

parse_the_random_line_from_the_obtained_dataset

This method must also determine the split-position in the given exam-question-line, which is also called the “index” position.

Example string:

- Name abc def. A: <one>DNA-Methylation</one>.
#


789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/studium/exams/exam_question/misc.rb', line 789

def parse_the_random_line_from_the_obtained_dataset(
    # ===================================================================== #
    # Obtain a handle to the exam-question-line first.
    # ===================================================================== #
    _ = @internal_hash[:exam_question_line]
  )
  # if _
  #   # =================================================================== #
  #   # We will chop off leading '- ' tokens next. The reason for this
  #   # is that these leading '- ' are NEVER a part of a question-answer
  #   # combination. They exist purely because of this being visually
  #   # more pleasing to my eyes, so a cosmetic thing.
  #   # This was, however had, disabled in January of 2022, because it
  #   # led to problems in regards to storing the full line, which had
  #   # to be stored in an unmodified manner.
  #   # =================================================================== #
  #   _ = _.dup if _.frozen?
  #   if _.start_with? '- '
  #     _[0, 2] = '' # Chop off leading '- ' tokens.
  #   end
  # end
  if _.nil?
    notify_the_user_that_all_questions_have_been_answered_already
    exit_program
    return
  end
  # ======================================================================= #
  # We must determine the question and answer next. We do this by
  # determining the index to split at. First, initialize it to 0.
  # ======================================================================= #
  index_to_split_at = 0
  # ======================================================================= #
  # The first strategy that is employed by this method is that the most
  # important '?' token is to be found. If it is found then we can split
  # split on it. This is, by definition, the very last '?' that
  # we can find in the given String, hence why we use .rindex()
  # rather than .index().
  # ======================================================================= #
  if _.include?('?')
    index_to_split_at = _.rindex('?')
    # ===================================================================== #
    # Some entries may have a '?' but also a 'A:' token. In this case,
    # we have to change the index position. However had, we must be
    # careful here, as a few answers will contain something like this
    # here:
    #
    #   '(1) A: Asymmetry (2) B: Border (3) C: Color (4) D: Diameter (5) E: Evolving'
    #
    # ===================================================================== #
    if _.include?('?') and
       _.include?(' A: ') and
       !(_ =~ /\d{1}\) A: /) # The last one here is explained above.
      index_to_split_at = _.index(' A: ')
    end
    set_split_position(index_to_split_at)
  elsif _.include?(' A: ') # This should be the only valid format in this case.
    index_to_split_at = _.index(' A: ')
    set_split_position(index_to_split_at)
  else # And here we report that something isn't quite right in the given file.
    opnn; e 'No ? and no A: was found. Please check the following line:'
    e
    e "  #{tomato(_)}"
    e
    opnn; e
    opnn; report_this_error
    opnn; e
  end
  set_exam_question(_[0 .. index_to_split_at])
  set_exam_answer(_[index_to_split_at .. -1])
end

#pick_a_random_line_from_the_obtained_datasetObject

#

pick_a_random_line_from_the_obtained_dataset

#


767
768
769
770
771
772
# File 'lib/studium/exams/exam_question/exam_question.rb', line 767

def pick_a_random_line_from_the_obtained_dataset
  _ = dataset?.reject {|line| line.end_with?(' []') } # Reject already solved exam questions.
  use_this_sample = _.sample
  set_exam_question_line(use_this_sample)
  try_to_save_the_line(use_this_sample)
end

#read_delay_from_fileObject

#

read_delay_from_file (load delay)

Use this method here, read_delay_from_file(), to read in the default delay from a stored file.

#


306
307
308
309
310
311
312
313
314
# File 'lib/studium/exams/exam_question/exam_question.rb', line 306

def read_delay_from_file
  if File.exist? DELAY_CONSTANT_STORED_HERE
    _ = YAML.load_file(DELAY_CONSTANT_STORED_HERE)
    result = _['delay']
  else # Else the file does not exist, so we use the default delay.
    result = DEFAULT_DELAY
  end
  return result
end

#register_last_modified_file(i = exam_file? ) ⇒ Object

#

register_last_modified_file

#


383
384
385
386
387
# File 'lib/studium/exams/exam_question/misc.rb', line 383

def register_last_modified_file(
    i = exam_file?
  )
  Studium.set_last_file_for_exam_questions(i) # , :be_verbose
end

#report_file_does_not_exist(this_file = exam_file? ) ⇒ Object

#

report_file_does_not_exist

#


373
374
375
376
377
# File 'lib/studium/exams/exam_question/misc.rb', line 373

def report_file_does_not_exist(
    this_file = exam_file?
  )
  opnn; e "#{rev}No file at `#{sfile(this_file)}` exists."
end

#report_how_many_registered_questions_are_available(n_questions = ::Studium.n_questions_available?) ⇒ Object

#

report_how_many_registered_questions_are_available

#


245
246
247
248
249
250
# File 'lib/studium/exams/exam_question/misc.rb', line 245

def report_how_many_registered_questions_are_available(
    n_questions = ::Studium.n_questions_available?
  )
  opnn; e "#{rev}There are #{simp(n_questions.to_s)} registered "\
          "questions available."
end

#report_how_many_topics_are_availableObject

#

report_how_many_topics_are_available

#


550
551
552
553
554
# File 'lib/studium/exams/exam_question/exam_question.rb', line 550

def report_how_many_topics_are_available
  opnn; e 'There are exactly '+
          simp(Studium.available_topics?.size.to_s)+
          ' topics available.'
end

#report_the_default_topic_in_use(this_file = "#{log_dir?}use_this_exam_topic.yml") ⇒ Object

#

report_the_default_topic_in_use

This method will report the default topic in use. We must also check whether the file in questions exists, before proceeding.

To invoke this, do:

qa --default-topic?
#


600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/studium/exams/exam_question/exam_question.rb', line 600

def report_the_default_topic_in_use(
    this_file = "#{log_dir?}use_this_exam_topic.yml"
  )
  if File.exist? this_file
    topic = File.read(this_file).chomp
    e "The default topic in use is: #{simp(topic)}"
  else
    e "#{rev}No file exists at `#{sfile(this_file)}`. This "\
      "means that no"
    e 'default topic has been set.'
    e
    e 'If you wish to designate a default topic, use this invocation:'
    e
    e steelblue('  qa --set_default_topic=amg')
    e steelblue('  qa --set_default_topic=phys')
    e
  end
end

#report_the_delayObject

#

report_the_delay

#


243
244
245
# File 'lib/studium/exams/exam_question/exam_question.rb', line 243

def report_the_delay
  e "#{rev}The delay is set to: #{sfancy(delay?.to_s)}"
end

#report_this_error(error = nil) ⇒ Object

#

report_this_error

#


228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/studium/exams/exam_question/misc.rb', line 228

def report_this_error(error = nil)
  opnn; e 'We encountered an '+swarn('error')+
          '. The @index_position was probably '\
          'out of range.'
  opnn; e 'Feedbacking @line next:'
  pp line?
  opnn; e "Feedbacking #{royalblue('the split position')} next:"
  pp split_position?
  if error
    pp error
    pp error.class
  end
end

#report_whether_we_will_show_the_topicObject

#

report_whether_we_will_show_the_topic

#


894
895
896
897
898
# File 'lib/studium/exams/exam_question/exam_question.rb', line 894

def report_whether_we_will_show_the_topic
  opnn; e 'Will we show the topic of the exams when '\
          'asking a question: '+
          simp(VerboseTruth[may_we_show_the_topic?])
end

#resetObject

#

reset (reset tag)

#


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

def reset
  super()
  register_sigint
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :dataset_from_the_file
  #
  # The next variable must be initially nil, in order to distinguish it
  # from the the startup-situation, before any exam file has been
  # read in.
  # ======================================================================= #
  @internal_hash[:dataset_from_the_file] = nil
  # ======================================================================= #
  # === :n_exam_questions_in_total
  # ======================================================================= #
  @internal_hash[:n_exam_questions_in_total] = 0
  # ======================================================================= #
  # === :word_wrap_at
  # ======================================================================= #
  @internal_hash[:word_wrap_at] = DEFAULT_WORD_WRAP_AT_N_CHARACTERS_PER_LINE
  # ======================================================================= #
  # === :colour_for_answers
  # ======================================================================= #
  @internal_hash[:colour_for_answers] = nil
  # ======================================================================= #
  # === :exam_file
  #
  # This instance variable will keep track where the full path to the
  # exam file can be found.
  # ======================================================================= #
  @internal_hash[:exam_file] = nil
  # ======================================================================= #
  # === @may_we_show_the_topic
  # ======================================================================= #
  @internal_hash[:may_we_show_the_topic] = MAY_WE_SHOW_THE_TOPIC
  # ======================================================================= #
  # === :colour_for_questions
  # ======================================================================= #
  @internal_hash[:colour_for_questions] = nil
  # ======================================================================= #
  # === @reject_lines_that_end_with_a_done_token
  #
  # If this variable is set to true (which is the default) then all
  # entries that end with [] will be removed.
  # ======================================================================= #
  @internal_hash[:reject_lines_that_end_with_a_done_token] = true
  # ======================================================================= #
  # === :debug
  # ======================================================================= #
  @internal_hash[:debug] = SHALL_WE_DEBUG
  # ======================================================================= #
  # === :result_for_www
  #
  # This can be a String, which is then used for display on the www.
  # Initially it is set to nil, though, to indicate that we will not
  # need it when in commandline-mode.
  # ======================================================================= #
  @internal_hash[:result_for_www] = nil
  set_delay
  set_split_position
  # ======================================================================= #
  # The default colours will not be made available when we run in the www-mode.
  # ======================================================================= #
  if are_we_in_www_mode?
    disable_colours
  end
  set_be_verbose # Be verbose, output lots of stuff to the user.
  try_to_load_custom_colours
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


548
549
550
# File 'lib/studium/exams/exam_question/misc.rb', line 548

def result?
  @internal_hash[:result_for_www]
end

#return_the_full_expanded_exam_title(exam_title = exam_title?) ) ⇒ Object

#

return_the_full_expanded_exam_title

#


857
858
859
# File 'lib/studium/exams/exam_question/exam_question.rb', line 857

def return_the_full_expanded_exam_title(exam_title = exam_title?)
  return Studium.find_corresponding_exam_title(exam_title)
end

#reveal_the_exam_answer(exam_answer = exam_answer?, , include_numbers_in_parens = false) ⇒ Object Also known as: show_this_answer, show_the_answer, show_answer, reveal_the_answer

#

reveal_the_exam_answer (answer tag, reveal tag)

This method will show the proper answer to the given exam question as hand.

The second argument to this method, called `include_numbers_in_parens`, can be used to keep track as to whether we have numbers such as (2).

#


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/studium/exams/exam_question/answer.rb', line 24

def reveal_the_exam_answer(
    exam_answer               = exam_answer?,
    include_numbers_in_parens = false
  )
  # if exam_answer.include? 'IMAGE: '
  #   image_path = exam_answer.scan(/IMAGE: (.+)$/).flatten
  #   image_path = image_path.first if image_path.is_a? Array
  #   system("tiv #{image_path}")
  #   exam_answer.sub!(/IMAGE: (.+)$/, '')
  # end
  # ======================================================================= #
  # Try to cut down at about 76 characters per line, or whatever the
  # limit-per-line is. We have to ignore special tags, though, such
  # as <u> or <orange>. We also have to call this BEFORE replacing
  # these tags with the corresponding escape values.
  # ======================================================================= #
  unless include_numbers_in_parens
    string_without_tags = remove_tags_from_this_input(exam_answer.dup)
    n_characters_to_consider_in_the_line = string_without_tags.size
    if n_characters_to_consider_in_the_line > word_wrap_at?
      exam_answer = word_wrap(exam_answer, word_wrap_at?) # word-wrap is a value such as 85.
      exam_answer.gsub!(/\n/, N+LEFT_PADDING) if exam_answer.include? N # Also pad these newlines.
    end
  end
  # ======================================================================= #
  # === Get rid of (2) and similar numbers
  #
  # We assume this to also include (1) and (3) and so forth here.
  # ======================================================================= #
  if exam_answer.include? '(2)'
    include_numbers_in_parens = true
    # ===================================================================== #
    # Do a word wrap if the size range from the part up to the first
    # '(' is larger than the allowed characters per line.
    # Since as of August 2019 we will honour HTML colour-tags though
    # and add that to the subrange size.
    # ===================================================================== #
    subrange = exam_answer[0 .. (exam_answer.index('(') - 1)].dup
    subrange_size = subrange.size
    if does_this_line_include_a_html_colour?(subrange)
      subrange_size += return_this_line_has_n_characters_as_html_colour_tags(subrange)
    end
    if subrange_size > @internal_hash[:word_wrap_at]
      exam_answer[0 .. (exam_answer.index('(') - 1)] = ''.dup
      subrange = word_wrap(subrange, @internal_hash[:word_wrap_at]).dup+N
      exam_answer[0,0] = subrange
    end
    12.times { |iteration_number_n|
      if use_colours?
        # ================================================================= #
        # Colourize the parens - and also add a leading newline.
        # ================================================================= #
        replace_with_this = N+
                            '  '+
                            rev+
                            slategray('(')+
                            skyblue(iteration_number_n.to_s.chomp)+
                            slategray(')')
        if use_colours?
          use_this_colour = ::Colours.send(colour_for_answers?) { :omit_end }
          replace_with_this << use_this_colour
        end
        exam_answer.gsub!(/\(#{iteration_number_n}\)/,replace_with_this)
      else
        exam_answer.gsub!(/\(#{iteration_number_n}\)/,
          N+'('+iteration_number_n.to_s+')') # Will add a leading newline.
      end
    } # The above is equivalent to the below, by the way:
      # exam_answer.gsub!(/\(6\)/, N+'(6)')
  end
  # ======================================================================= #
  # === Handle URLs next
  # ======================================================================= #
  if exam_answer.include? ' URL:' # This is the valid form; the check is necessary.
    exam_answer = assign_url(exam_answer)
  # ======================================================================= #
  # === Handle entries that include the substring ' https://'
  # ======================================================================= #
  elsif exam_answer.include? '  https://'
    exam_answer = colourize_https_substring(exam_answer) if use_colours?
  end
  exam_answer = exam_answer.to_s
  if exam_answer.include?(' URL:') or exam_answer.include?('  https://')
    assign_url_or_colourize_https_substring(exam_answer) if use_colours?
  end
  _ = ::Colours.replace_number_words_with_the_corresponding_html_colour(
        exam_answer,
        USE_THESE_COLOURS.merge(default_colour: colour_for_answers?)
      )
  result = "  #{::Colours.fancy_parse(_, colour_for_answers?)}\n\n"
  # ======================================================================= #
  # === Handle entries that are between <ud>foo</ud> tags
  # ======================================================================= #
  if line_contains_underline_token?(result) and use_colours?
    # ===================================================================== #
    # Colourize <ud> for underline next:
    # ===================================================================== #
    result = replace_underline_token_with_default_colour(result)+
             colour_for_answers?
  end
  # ======================================================================= #
  # === Handle italic text next
  # ======================================================================= #
  if line_contains_italic_token?(result) and use_colours?
    # ===================================================================== #
    # Colourize <i> for italic next:
    # ===================================================================== #
    result = replace_italic_token_with_default_colour(result)+
             ::Colours.send(use_this_colour,'')
  end
  # ======================================================================= #
  # === Handle entries that are between <b>foo</b> tags
  # ======================================================================= #
  if line_contains_bold_token?(result) and use_colours?
    # ===================================================================== #
    # Colourize <b> for bold font-style next:
    # ===================================================================== #
    result = replace_bold_token_with_default_colour(result)+
             use_this_colour
  end
  # ======================================================================= #
  # === Colourize https-links, if we use colours.
  #     This will also include links to wikipedia.
  # ======================================================================= #
  if use_colours? and result.include?('https://') 
    use_this_regex =
      /(https:\/\/.+)$/ # See: https://rubular.com/r/drYvZc4a91
    result.sub!(use_this_regex, mediumaquamarine('\\1'))
  end
  # ======================================================================= #
  # Add <div> element if we run in www-mode.
  # ======================================================================= #
  if www_mode?
    e '<div id="answer_div">'+N
    e result
    e "</div>\n"
  else
    e result
  end
end

#runObject

#

run (run tag)

#


956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
# File 'lib/studium/exams/exam_question/exam_question.rb', line 956

def run
  menu_on_the_commandline_as_a_string
  menu
  invoke_all_the_necessary_steps_before_the_question_is_asked
  ask_the_question_then_sleep_then_reveal_the_answer_to_that_question
  # ======================================================================= #
  # After the answer has been shown, it is time to display some statistics.
  # ======================================================================= #
  show_statistics
  do_log_related_and_backup_related_actions
  # ======================================================================= #
  # Register the last file that was modified.
  # ======================================================================= #
  register_last_modified_file
end

#sanitize_the_obtained_datasetObject

#

sanitize_the_obtained_dataset (sanitized tag)

This method exists primarily to remove all trailing “n”, and then remove all [] entries, as well as show how many exam questions are in that given file.

#


350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/studium/exams/exam_question/exam_question.rb', line 350

def sanitize_the_obtained_dataset
  dataset = dataset?.map {|entry| entry.strip }
  set_dataset(dataset)
  # ======================================================================= #
  # === :n_exam_questions_in_total
  # ======================================================================= #
  @internal_hash[:n_exam_questions_in_total] = dataset.size
  _ = dataset.reject {|line|
    line.end_with? '[]'
  }
  set_exam_pool(_) if _ # Keep track of the unanswered exam questions here.
  # ======================================================================= #
  # === :n_exam_questions_unanswered
  # ======================================================================= #
  @internal_hash[:n_exam_questions_unanswered] = _.size
  # ======================================================================= #
  # === :n_exam_questions_answered
  # ======================================================================= #
  @internal_hash[:n_exam_questions_answered]   = (
    @internal_hash[:n_exam_questions_in_total] - _.size
  )
end

#set_all_questions_from_the_topic_to_solvedObject

#

set_all_questions_from_the_topic_to_solved

This will solve all questions from a given topic.

Invocation example:

qa ALL_SOLVED
#


215
216
217
218
219
220
221
222
223
# File 'lib/studium/exams/exam_question/misc.rb', line 215

def set_all_questions_from_the_topic_to_solved
  if commandline?
    require 'studium/exams/solve_all_questions_from_this_topic.rb'
    this_topic = which_topic?
    e "#{rev}Setting all questions from the topic "\
      "#{sfancy(this_topic)} to solved."
    Studium::SolveAllQuestionsFromThisTopic.new(this_topic)
  end
end

#set_and_store_delay(i) ⇒ Object

#

set_and_store_delay

Combine two methods in one here.

#


295
296
297
298
# File 'lib/studium/exams/exam_question/exam_question.rb', line 295

def set_and_store_delay(i)
  set_delay(i)
  store_delay(i)
end

#set_colour_for_answers(i) ⇒ Object

#

set_colour_for_answers

#


740
741
742
# File 'lib/studium/exams/exam_question/exam_question.rb', line 740

def set_colour_for_answers(i)
  @internal_hash[:colour_for_answers] = i.to_sym
end

#set_colour_for_questions(i) ⇒ Object

#

set_colour_for_questions

#


733
734
735
# File 'lib/studium/exams/exam_question/exam_question.rb', line 733

def set_colour_for_questions(i)
  @internal_hash[:colour_for_questions] = i.to_sym
end

#set_custom_colours(i) ⇒ Object

#

set_custom_colours

This setter is, since as of January 2022, just calling two methods now. This was simpler to maintain than using another ad-hoc Hash.

Valid keys for the colours should be, for instance, “colour_for_questions” or “colour_for_answers”.

#


753
754
755
756
757
758
759
760
761
762
# File 'lib/studium/exams/exam_question/exam_question.rb', line 753

def set_custom_colours(i)
  if i.is_a?(String) and i.include?('|')
    # ===================================================================== #
    # Allow custom input, as String, so users can override this.
    # ===================================================================== #
    splitted = i.split('|')
    set_colour_for_questions(splitted.first)
    set_colour_for_answers(splitted.last)
  end
end

#set_dataset(i) ⇒ Object

#

set_dataset

#


339
340
341
# File 'lib/studium/exams/exam_question/exam_question.rb', line 339

def set_dataset(i)
  @internal_hash[:dataset_from_the_file] = i
end

#set_default_topic_for_the_gui(what, into = "#{log_dir?}use_this_exam_topic.yml") ⇒ Object

#

set_default_topic_for_the_gui

#


912
913
914
915
916
917
918
# File 'lib/studium/exams/exam_question/exam_question.rb', line 912

def set_default_topic_for_the_gui(
    what,
    into = "#{log_dir?}use_this_exam_topic.yml"
  )
  opnn; e "Now setting the default topic to `#{simp(what)}`."
  write_what_into(what, into)
end

#set_delay(i = :load_from_file) ⇒ Object Also known as: determine_the_default_delay, delay=

#

set_delay

Set the default delay value via this method.

#


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/studium/exams/exam_question/exam_question.rb', line 259

def set_delay(
    i = :load_from_file
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       :load_from_file,
       nil
    # ===================================================================== #
    # === :delay
    # ===================================================================== #
    if File.exist? FILE_DELAY
      i = YAML.load_file(FILE_DELAY)
      i = i['delay'] if i.respond_to?('delay')
    else
      # =================================================================== #
      # This is the default if the file can not be found/read. It
      # can be found in the file studium/constants/delay.rb.
      # =================================================================== #
      i = DEFAULT_DELAY
    end
  end
  if i.is_a? Hash
    i = i['delay']
  end
  @internal_hash[:delay] = i.to_f
end

#set_exam_answer(i) ⇒ Object Also known as: set_answer

#

set_exam_answer

This method can be used to keep track of the current exam-answer - that is the answer that fits to the exam-question at hand. Before it is set, though, this method will do various sanitizing actions, to make sure the answer is sufficiently “improved”, before it is displayed to the user (or whoever invoked this class).

Perhaps this should be factored out into a separate method, but for now it will remain as it is.

Note that every question must have an associated answer. This is the very basic assumption for the “studium” gem every question must adhere to.

#


644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/studium/exams/exam_question/exam_question.rb', line 644

def set_exam_answer(
    i
  )
  # ======================================================================= #
  # === Handle Array as input
  #
  # This can happen due to assign_url() returning an Array.
  # ======================================================================= #
  i = i.first if i.is_a? Array
  i = i.dup if i.frozen? # Work on non-frozen Strings past this point here.
  i.strip! # This also implies .chomp.
  i[-3, 3] = '' if i.end_with?(' []') # Get rid of trailing [], just in case.
  # ======================================================================= #
  # === Get rid of ' A:' if they are in that string.
  #
  # At this point, we do no longer want to have 'A:' in our answer-string,
  # so we get rid of it.
  #
  # The old code up until 2022 was:
  #
  #   if i.include? ' A:'
  #     i.sub!(/ A:/,'') unless i.include? ') A:' # The unless check exists to avoid rare cases..
  #
  # ======================================================================= #
  i[0, 3] = '' if i.start_with?('A: ') # Three characters are in the argument.
  i[0, 2] = '' if i.start_with?('- ')
  i[0, 2] = '' if i.start_with?(': ','? ','?:')
  i.sub!(/^\?/,'') if i.start_with? '?' # Only chop it away at the beginning.
  if i.include? '(a)' # Also assume (b) (c) etc..
    i.gsub!(/\(a\)/, N+'  (a)')
    i.gsub!(/\(b\)/, N+'  (b)') if i.include? '(b)'
    i.gsub!(/\(c\)/, N+'  (c)') if i.include? '(c)'
    i.gsub!(/\(d\)/, N+'  (d)') if i.include? '(d)'
    i.gsub!(/\(e\)/, N+'  (e)') if i.include? '(e)'
    i.gsub!(/\(f\)/, N+'  (f)') if i.include? '(f)'
  end
  # ======================================================================= #
  # Assume () modifications. But this conflicts with entries that have
  # a pure () as part of their answer, which may happen on computer
  # related questions such as foobar(). Hence, since as of December 2014,
  # I have disabled the following line.
  # ======================================================================= #
  # i.gsub!(/\(\)/, N+'- ') if i.include? '()'
  # ======================================================================= #
  if debug?
    e "We will now set the answer to: #{sfancy(i)}" if commandline?
  end
  # ======================================================================= #
  # === Replace <br> tags, should they be part of the answer
  # ======================================================================= #
  i.gsub!(/<br>/, N) if i.include? '<br>'
  # ======================================================================= #
  # === Colourize words in quotes
  #
  # Next, consider colourizing all answers that have at the least 2
  # '"' characters. These will be colourized.
  # ======================================================================= #
  if EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_ANSWER
    if use_colours? and commandline? and (i.count('"') > 1)
      use_this_regex = /"(.+?\s*.*?)"/ # See: http://rubular.com/r/6WK5NjMJld
      use_this_colour = ::Colours.send(colour_for_answers?) { :omit_end }
      i.gsub!(
        use_this_regex,
        '"'+steelblue('\1'.delete(N))+
        use_this_colour+'"'
      )
    end
  end
  @internal_hash[:exam_answer] = i
end

#set_exam_file(i) ⇒ Object Also known as: set_file

#

set_exam_file

The file location will be something like:

/Programs/Ruby/2.3.1/lib/ruby/site_ruby/2.3.0/studium/exam_topics/physiologie
#


472
473
474
# File 'lib/studium/exams/exam_question/exam_question.rb', line 472

def set_exam_file(i)
  @internal_hash[:exam_file] = i
end

#set_exam_pool(i = nil) ⇒ Object

#

set_exam_pool

The “exam pool” constitutes the available, unanswered exams.

What this means, essentially, is that every line ending with a '[]' will be disregarded.

#


133
134
135
# File 'lib/studium/exams/exam_question/misc.rb', line 133

def set_exam_pool(i = nil)
  @internal_hash[:exam_pool] = i
end

#set_exam_question(i) ⇒ Object Also known as: set_question

#

set_exam_question

#


376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/studium/exams/exam_question/exam_question.rb', line 376

def set_exam_question(i)
  i = i.dup if i.frozen?
  i.strip! # Get rid of trailing newlines.
  i[0,  2] = '' if i.start_with?('- ') # Chop off leading '-' components.
  i[-2, 2] = '' if i.end_with?(' A')
  i[-2, 2] = '' if i.end_with?('?A')
  i[-3, 3] = '' if i.end_with?(' A?')
  i[-2, 2] = '' if i.end_with?('! ?') # Preserve the ! here.
  # ======================================================================= #
  # i[-2,2] = '' if i.end_with? 'A?'
  # ^^^ The above check is not good because the question may end like:
  #   "T-DNA?". Perhaps we have to think of another way.
  # ======================================================================= #
  if i.end_with? '. ?' # This can not be correct - it must be a typo.
    i[-2, 2] = '' # Thus get rid of the last two entries.
  end
  if i.end_with? '.?','!?' # These two values can not be correct - it must thus be a typo.
    i.chop! # Thus get rid of the last two entries.
  end
  i.strip! # ← Always chop off trailing newlines, just in case.
  # ======================================================================= #
  # A question typically will have a trailing '?', thus we ensure this
  # by actually appending a question mark '?' - unless the string
  # already ends with '?', '.' or a '!'.
  # ======================================================================= #
  unless i.rstrip.end_with?('?','.','!')
    i << '?' # Ensure a trailing '?' here.
  end
  # ======================================================================= #
  # Next we will determine how many characters are in the given line.
  # We need to exclude ANSII escape sequences, though, as they
  # will not be shown on the commandline - they will be interpreted
  # differently, such as displaying a red underline colour for the
  # given text.
  # ======================================================================= #
  trimmed_sequence = remove_escape_sequences(
    remove_tags_from_this_input(i)
  )
  n_characters_to_consider_in_the_line = trimmed_sequence.size
  if n_characters_to_consider_in_the_line > @internal_hash[:word_wrap_at]
    i = word_wrap(i, @internal_hash[:word_wrap_at])
  end
  # ======================================================================= #
  # Next, consider colourizing all questions that have at the least 2
  # '"' characters. These will be colourized if a certain constant is
  # set to true.
  # ======================================================================= #
  if EMPHASIZE_WORDS_IN_QUOTES_IN_A_GIVEN_QUESTION
    if use_colours? and commandline? and (i.count('"') > 1)
      use_this_regex = /"(.+?\s*.*?)"/ # See: https://rubular.com/r/6WK5NjMJld
      # =================================================================== #
      # Next make use of the default colour to use.
      # =================================================================== #
      use_this_colour = ::Colours.send(colour_for_questions?) { :omit_end }
      i.gsub!(use_this_regex,
        '"'+forestgreen('\1'.delete(N))+ # forestgreen is the hardcoded colour to be used for now.
        use_this_colour+'"' 
      )
    end
  end
  @internal_hash[:exam_question] = i
end

#set_exam_question_line(i) ⇒ Object Also known as: set_line, set_this_line

#

set_exam_question_line

A full exam-question line, also shorter called “line”, is a line that contains a question, and the associated answer to this question.

This setter may not modify anything - we just want to assign to the correct entry in our main Hash. Additionally the line itself may not be tampered with at all, so that we can act on that information, such as by storing that line into a local file.

#


874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/studium/exams/exam_question/misc.rb', line 874

def set_exam_question_line(i)
  if i.is_a? Array
    i = i.first.to_s.dup # We only need the first entry in this case, if it is an Array.
  end
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    case yield
    # ===================================================================== #
    # === :then_determine_the_split_position
    # ===================================================================== #
    when :then_determine_the_split_position
      determine_the_split_position
    end
  end
  @internal_hash[:exam_question_line] = i
end

#set_exam_question_line_and_then_parse_that_line(i) ⇒ Object

#

set_exam_question_line_and_then_parse_that_line

#


986
987
988
989
# File 'lib/studium/exams/exam_question/exam_question.rb', line 986

def set_exam_question_line_and_then_parse_that_line(i)
  set_exam_question_line(i)
  parse_that_line
end

#set_exam_topic(i = first_non_hyphen_argument? ) ⇒ Object Also known as: set_this_topic, determine_the_topic, determine_the_exam_topic

#

set_exam_topic

We need to store the expanded topic name, so that something like “bioanalytik” is turned into “bioanalytik_und_biosensoren”.

Whenever a topic is set through this method, this will also be stored into a file. This then allows us to query what the last topic was, e. g. via “qa –last_topic?”.

#


616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# File 'lib/studium/exams/exam_question/misc.rb', line 616

def set_exam_topic(
    i = first_non_hyphen_argument?
  )
  i = i.first if i.is_a? Array
  # ======================================================================= #
  # === Handle Hashes
  #
  # If a Hash is given then we will try to find a specific key in that
  # Hash.
  # ======================================================================= #
  if i.is_a?(Hash) and i.has_key?(:use_this_topic)
    i = i[:use_this_topic]
  end
  case i
  when nil, ''
    i = 'random_topic' # or :random
  end
  i = i.to_s.dup # Work with a String past this point.
  i.downcase! # Convention is to store the file downcased.
  case i
  # ======================================================================= #
  # === random
  #
  # We fetch a random topic via this entry-point.
  # ======================================================================= #
  when 'fetch_a_random_topic',
       'random_topic',
       'random',
       'rand'
    i = ::Studium::Exams.random_short_name_topic # This is allowed, for random topics.
    # i = ::Studium.return_random_exam_topic # ← This may be an alternative.
  # ======================================================================= #
  # === molbio
  #
  # This entry point is special.
  # ======================================================================= #
  when 'molbio',
       'molekularbiologie',
       'molbio?'
    i = 'amg|amg2|genex1|gentech1|gentech2|pcr'
  # ======================================================================= #
  # === OLAST
  # ======================================================================= #
  when /^qlast$/i,
       /^olast$/i # === olast tag
    _ = FILE_LAST_TOPIC
    if File.exist? _
      i = File.read(FILE_LAST_TOPIC).strip
    else
      opnn; no_file_exists_at(_)
    end
  end
  # ======================================================================= #
  # If the input has a '|', we assume that the user wants to randomly
  # pick one entry.
  # ======================================================================= #
  if i.include? '|'
    i = i.split('|').shuffle
  end
  # ======================================================================= #
  # Before we do the real assignment, we will sanitize this through
  # the Studium.find_corresponding_exam_topic "filter".
  # ======================================================================= #
  if ::Studium.is_this_a_registered_exam_topic?(i)
    i = Studium.find_corresponding_exam_topic(i)
  else
    opnn; e "Not a registered exam topic: #{i}"
  end
  @internal_hash[:topic] = i
  # ======================================================================= #
  # Next we will store the topic into a file.
  # ======================================================================= # 
  unless in_www_mode?
    store_last_topic_into_file(i)
  end
end

#set_may_we_show_the_topic(i = MAY_WE_SHOW_THE_TOPIC) ⇒ Object Also known as: may_we_show_the_topic=, set_show_topic

#

set_may_we_show_the_topic

#


725
726
727
# File 'lib/studium/exams/exam_question/exam_question.rb', line 725

def set_may_we_show_the_topic(i = MAY_WE_SHOW_THE_TOPIC)
  @internal_hash[:may_we_show_the_topic] = i
end

#set_split_position(i = nil) ⇒ Object Also known as: set_index_position

#

set_split_position

#


777
778
779
# File 'lib/studium/exams/exam_question/exam_question.rb', line 777

def set_split_position(i = nil)
  @internal_hash[:split_position] = i
end

#show_all_finished_exam_topicsObject

#

show_all_finished_exam_topics

To invoke this method, do:

qa --finished?
#


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/studium/exams/exam_question/misc.rb', line 491

def show_all_finished_exam_topics
  stats = Studium::Statistics::ReportHowManyExamQuestionsWereAnswered.new {
    :do_not_show_the_result
  }.internal_dataset
  e "#{rev}The following topics are completely answered "\
    "(#{colourize_percentage('100%')} answered ratio)."
  array_finished_topics = []
  stats.select {|key, value|
    percentage = value[:percentage_of_questions_answered]
    if percentage == 100.0
      array_finished_topics << ::Studium.beautify_this_topic(key)
    end
  }
  e
  array_finished_topics.each {|topic|
    e "  #{simp(topic)} is completely answered."
  }
  e
end

#show_available_topics(shall_we_exit = true) ⇒ Object

#

show_available_topics (topics tag)

This method will show which topics are all available.

By default, it will also exit after having done so.

To invoke this method, try:

qa topics?
qa --show-available-topics
#


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'lib/studium/exams/exam_question/misc.rb', line 572

def show_available_topics(
    shall_we_exit = true
  )
  e
  use_these_topics = Studium.available_topics.sort # And sort it.
  use_these_topics.each_with_index {|category, index|
    # ===================================================================== #
    # Number the results via the index.
    # ===================================================================== #
    index = '%4s' % ('('+(index+1).to_s)
    result = ' '.dup
    if use_colours?
      result << ::Colours::CYAN if commandline?
    end
    result << "#{index}) - " # Add the index here.
    if use_colours? # And "close" the escape-sequences next.
      result << rev if commandline?
    end
    category = category.to_s.delete('_')
    category = steelblue(category) if use_colours?
    result << category
    e result
  }
  e
  exit if shall_we_exit
end

#show_content_of_this_topic(i = topic? ) ⇒ Object

#

show_content_of_this_topic

Invocation example:

qa ethik --show-everything
#


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

def show_content_of_this_topic(
    i = topic?
  )
  dataset = filter_away_invalid_questions(
    File.readlines(directory_to_the_exam_topics?+i)
  )
  dataset.each {|line|
    e "  #{simp(line.chomp)}"
  }
end

#show_filesize_of_all_examsObject

#

show_filesize_of_all_exams

To call this method, do:

qa --filesize?
#


447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/studium/exams/exam_question/exam_question.rb', line 447

def show_filesize_of_all_exams
  this_exam_topic = directory_of_the_exam_topics?
  all_filesizes = Dir["#{this_exam_topic}*"].map {|entry|
    File.size?(entry)
  }
  sum = all_filesizes.sum
  sum_in_kb = sum / 1000.0
  sum_in_mb = sum_in_kb / 1000.0
  e "#{rev}The total file size of all exams in "\
    "#{sdir(this_exam_topic)} is:"
  e
  e '  '+simp(sum.to_s)+
    ' Bytes ('+
    sfancy(sum_in_mb.round(2).to_s)+' MB)'
  e
end

#show_help_usage(then_exit = false) ⇒ Object

#

show_help_usage (help tag)

We show help usage of this class here via this method. It is typically used from the commandline.

To show this help message, use this:

qa --help
#


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/studium/exams/exam_question/exam_question.rb', line 185

def show_help_usage(
    then_exit = false
  )
  case then_exit
  # ======================================================================= #
  # === :do_exit
  # ======================================================================= #
  when :do_exit,
       :exit
    then_exit = true
  end
  opnn; e "Currently the following extra commands can be issued:#{N}#{N}"
  lpad = ' ' * 4
  e "#{lpad}--set_default_topic= #{yellow('   Set a default topic.')}"
  e lpad+'TOPICS '+
      yellow('                 List all available topics.')
  e lpad+'TOTAL '+
      yellow("                  Show how many questions are known in total.")
  e lpad+'FINISHED '+
      yellow('               Show which topics are '\
      'completely finished (100% answered).')
  e lpad+'EDIT '+
      yellow('                   To edit the exam questions '\
      'file, via vim.')
  e lpad+'LAST_TOPIC '+
      yellow('             Show the last topic used.')
  e lpad+'BLOCK '+
      yellow('                  List all questions that '\
      'were already answered for a given section.')
  e lpad+'OPEN '+
      yellow('                   Open this file here in an editor.')
  e lpad+'--download-exam-topics '+
      yellow(' Download the exam topics.')
  e lpad+'--all-questions        '+
      yellow(' Ask all questions, including those marked '\
      'with a trailing "[]".')
  e lpad+'delay? '+
      yellow('                 show the default delay.')
  e lpad+"'delay = 5' "+
      yellow('            to set a new delay to 5 seconds.')
  e lpad+"'set-delay = 5' "+
      yellow('        to set a new delay '\
      'to 5 seconds. (as ^^^ above)')
  if is_on_roebe? # Show more options only on my system.
    e lpad+'rename_tab? '+
      yellow('            whether to rename the KDE konsole tab or not.')
    e lpad+'rename_tab: true'+
      yellow('        enable renaming of the KDE konsole tab.')
    e lpad+'rename_tab: false'+
      yellow('       disable rename of the KDE konsole tab.')
  end
  e
  exit if then_exit
end

#show_how_many_exam_questions_are_availableObject Also known as: total, n_total_questions_available?

#

show_how_many_exam_questions_are_available

This method can be called by passing in 'TOTAL' as argument.

Example:

qa TOTAL?
#


400
401
402
403
404
405
406
407
408
409
# File 'lib/studium/exams/exam_question/misc.rb', line 400

def show_how_many_exam_questions_are_available
  n_questions = ::Studium.n_questions_available?.to_s
  result = 'Total amount of registered questions: '.dup
  if commandline? and use_colours?
    result << simp(n_questions.to_s)
  else
    result << n_questions.to_s
  end
  e result
end

#show_how_many_exam_questions_were_already_solvedObject

#

show_how_many_exam_questions_were_already_solved

Use this method to show how many exam questions were already solved.

To invoke this method, do:

qa SOLVED?

Or in code, do:

Studium::Exams.report_how_many_exam_questions_were_already_solved
#


266
267
268
# File 'lib/studium/exams/exam_question/misc.rb', line 266

def show_how_many_exam_questions_were_already_solved
  Studium.report_how_many_exam_questions_were_already_solved
end

#show_how_many_exam_questions_were_already_solved_in_germanObject

#

show_how_many_exam_questions_were_already_solved_in_german

Similar to the above, except that we will report in german.

Invocation example:

qa --solved-in-german
#


74
75
76
# File 'lib/studium/exams/exam_question/misc.rb', line 74

def show_how_many_exam_questions_were_already_solved_in_german
  Studium::Exams.report_how_many_exam_questions_were_already_solved(:german)
end

#show_last_question_asked(i = store_where? ) ⇒ Object

#

show_last_question_asked

This will show the last question asked.

#


449
450
451
452
453
454
455
# File 'lib/studium/exams/exam_question/misc.rb', line 449

def show_last_question_asked(
    i = store_where?
  )
  if File.exist? i
    e File.read(i)
  end
end

#show_lineObject

#

show_line

#


514
515
516
# File 'lib/studium/exams/exam_question/exam_question.rb', line 514

def show_line
  e exam_question_line?
end

#show_statistics(dataset = dataset? ) ⇒ Object Also known as: report_statistics

#

show_statistics

To invoke this method from the commandline, try:

qa --show-statistics
#


752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/studium/exams/exam_question/misc.rb', line 752

def show_statistics(
    dataset = dataset?
  )
  unless in_www_mode?
    n_questions = n_questions_available?
    n_answered  = n_questions_already_answered?
    percentage = (n_answered.to_f * 100) / n_questions
    result = olivedrab(n_questions.to_s)+' questions available, '+
             mediumaquamarine(n_answered.to_s)+
             ' ('+
             colourize_percentage(percentage.round(2).to_s+'%')+
             ') already answered.'+N
    # ===================================================================== #
    # Also add how many questions in absolute numbers have to be answered
    # still.
    # ===================================================================== #
    padded_amount_of_questions_answered = (n_questions - n_answered).to_s
    padded_amount_of_questions_answered =
      padded_amount_of_questions_answered.rjust(n_questions.to_s.size)
    result << "#{crimson(padded_amount_of_questions_answered)} questions "\
              "could still be answered. Topic: "\
              "#{olive(return_the_full_expanded_exam_title)}.#{rev}"
    e result
  end
end

#show_the_last_topic(_ = FILE_LAST_TOPIC) ⇒ Object

#

show_the_last_topic

Invocation example:

qa --show-last-topic
#


180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/studium/exams/exam_question/misc.rb', line 180

def show_the_last_topic(
    _ = FILE_LAST_TOPIC
  )
  if File.exist? _
    e rev+'The last topic was `'+
       simp(
         expand_topic(File.read(_).chomp)
       )+'`.'
  else
    opnn; no_file_exists_at(_.to_s)
  end
end

#sleep_default_delay(i = delay? ) ⇒ Object Also known as: default_sleep, do_sleep, start_default_sleep

#

sleep_default_delay

This method can be used to sleep for the specified duration.

Since as of April 2012 the method will also handle SIGINT-events gracefully.

#


535
536
537
538
539
540
541
542
543
# File 'lib/studium/exams/exam_question/exam_question.rb', line 535

def sleep_default_delay(
    i = delay?
  )
  begin
    sleep(i)
  rescue Interrupt # We are silent here.
    exit_program
  end
end

#split_position?Boolean

#

split_position?

#

Returns:

  • (Boolean)


784
785
786
# File 'lib/studium/exams/exam_question/exam_question.rb', line 784

def split_position?
  @internal_hash[:split_position]
end

#store_delay(i) ⇒ Object

#

store_delay (store tag)

This method will store/save the delay into a file.

#


143
144
145
# File 'lib/studium/exams/exam_question/misc.rb', line 143

def store_delay(i)
  Studium.save_this_delay_between_questions_and_answers(i)
end

#store_last_topic_into_file(what = topic?, , into = FILE_LAST_TOPIC) ⇒ Object

#

store_last_topic_into_file

By default we will not report this activity.

#


198
199
200
201
202
203
# File 'lib/studium/exams/exam_question/misc.rb', line 198

def store_last_topic_into_file(
    what = topic?,
    into = FILE_LAST_TOPIC
  )
  write_what_into(what, into)
end

#store_where?Boolean

#

store_where?

#

Returns:

  • (Boolean)


333
334
335
# File 'lib/studium/exams/exam_question/misc.rb', line 333

def store_where?
  Studium.file_last_question_asked?
end

#tell_whether_we_will_rename_the_kde_konsole_tabObject

#

tell_whether_we_will_rename_the_kde_konsole_tab

#


923
924
925
926
927
928
# File 'lib/studium/exams/exam_question/exam_question.rb', line 923

def tell_whether_we_will_rename_the_kde_konsole_tab
  e 'Will we rename the KDE konsole tab? '+
    simp(
      VerboseTruth[load_file_rename_konsole_tab.to_s]
    )
end

#topic?Boolean Also known as: exam_topic?, exam_title?, which_topic?, topic, title, title?, category?

#

topic?

#

Returns:

  • (Boolean)


319
320
321
# File 'lib/studium/exams/exam_question/exam_question.rb', line 319

def topic?
  @internal_hash[:topic]
end

#try_to_load_custom_coloursObject

#

try_to_load_custom_colours

This method can be used to designate specific colours for use by this class.

#


562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/studium/exams/exam_question/exam_question.rb', line 562

def try_to_load_custom_colours
  _ = "#{::Studium.project_yaml_directory?}custom_colours.yml"
  if File.exist? _
    dataset = YAML.load_file(_)
    set_colour_for_questions(
      dataset['colour_for_questions']
    )
    set_colour_for_answers(
      dataset['colour_for_answers']
    )
  end
end

#try_to_read_in_the_dataset_from_the_corresponding_exam_file(_ = exam_topics_directory?+ topic?.to_s) ⇒ Object

#

try_to_read_in_the_dataset_from_the_corresponding_exam_file

#


514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/studium/exams/exam_question/misc.rb', line 514

def try_to_read_in_the_dataset_from_the_corresponding_exam_file(
    _ = exam_topics_directory?+
        topic?.to_s
  )
  if File.exist? _
    # ===================================================================== #
    # Keep track of where the exam-file can be found.
    # ===================================================================== #
    set_exam_file(_)
    @internal_hash[:dataset_from_the_file] =
      read_in_exam_dataset_from_this_file(_)
  else
    report_file_does_not_exist(_)
  end
end

#try_to_save_the_line(i = line? ) ⇒ Object

#

try_to_save_the_line (save tag)

This is called whenever the main line is obtained. The original line is copied, not any modified variant.

We will store into a file, which is kept at @store_where.

It usually defaults to the file /Depot/Studium/last_question_asked.md or wherever else the base-directory has been defined.

#


316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/studium/exams/exam_question/misc.rb', line 316

def try_to_save_the_line(
    i = line?
  )
  _ = store_where? # Where to store.
  if File.exist?(File.dirname(_))
    if debug?
      opnn; e "Now saving: #{bold_blue(i)} into the file #{sfile(_)}"
    end if commandline?
    if File.writable?(File.dirname(_))
      write_what_into(i, _) # Save it.
    end
  end
end

#word_wrap_at?Boolean

#

word_wrap_at?

#

Returns:

  • (Boolean)


602
603
604
# File 'lib/studium/exams/exam_question/misc.rb', line 602

def word_wrap_at?
  @internal_hash[:word_wrap_at]
end