Class: Dictionaries::AskWordFromDictionary

Inherits:
Object
  • Object
show all
Includes:
Colours::E
Defined in:
lib/dictionaries/class/ask_word_from_dictionary.rb,
lib/dictionaries/class/colours.rb,
lib/dictionaries/class/constants.rb,
lib/dictionaries/class/set_search_for_this_word.rb

Overview

Dictionaries::AskWordFromDictionary

Direct Known Subclasses

AskEnglishWord, AskItalianWord

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect

Instance Method Summary collapse

Constructor Details

#initialize(optional_search_for_this_word = nil, use_this_file_for_the_dataset = :default_file, run_already = true) ⇒ AskWordFromDictionary

#

initialize

#

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/dictionaries/class/ask_word_from_dictionary.rb', line 56

def initialize(
    optional_search_for_this_word = nil,
    use_this_file_for_the_dataset = :default_file,
    run_already                   = true
  )
  register_sigint
  reset
  case optional_search_for_this_word
  when :do_not_run_yet
    run_already = :do_not_run_yet
    optional_search_for_this_word = nil
  end
  # ======================================================================= #
  # === Next, set the main file to use
  # ======================================================================= #
  if use_this_file_for_the_dataset
    set_use_this_file(use_this_file_for_the_dataset)
    load_main_dataset
  end
  set_search_for_this_word(optional_search_for_this_word)
  if run_already.is_a? Hash
    if run_already.has_key? :delay
      set_delay(run_already.delete(:delay))
    end
    run_already = true
  end
  case run_already
  when :dont_run_yet, :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Instance Method Details

#available_keys?Boolean Also known as: array

#

available_keys?

#

Returns:

  • (Boolean)

135
136
137
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 135

def available_keys?
  @words.keys if @words
end

#be_verbose?Boolean

#

be_verbose?

#

Returns:

  • (Boolean)

287
288
289
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 287

def be_verbose?
  @be_verbose
end

#brown(i = '') ⇒ Object

#

brown

#

23
24
25
# File 'lib/dictionaries/class/colours.rb', line 23

def brown(i = '')
  "#{Colours::BROWN}#{i}#{Colours.revert}"
end

#build_url_www_string(i) ⇒ Object

#

build_url_www_string

#

389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 389

def build_url_www_string(i)
  _ = ''.dup
  # ======================================================================= #
  # We need to differ between the english dictionary and the italian
  # dictionary.
  # ======================================================================= #
  language = Dictionaries.return_name_from_compound(main_file?)
  if language == 'english'
    _ << '"' unless _.end_with? '"'
  end
  case language # case tag
  when 'italian'
    _ << URL_FOR_ITALIAN_DICTIONARY
  when 'english' # This is the default.
    _ << URL_FOR_DICT_LEO+'ende/?lp=ende&lang=de&searchLoc=0&cmpType=relaxed&sectHdr=on&spellToler=&search='
  end
  _ << i.to_s
  if language == 'english'
    _ << '"' unless _.end_with? '"' # Append '"' here.
  end
  _
end

#consider_opening_browser_page(i = '') ⇒ Object

#

consider_opening_browser_page

#

380
381
382
383
384
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 380

def consider_opening_browser_page(i = '')
  url = build_url_www_string(i)
  opnn; e 'Consider visiting '+brown(url)+' if you need a translation.'
  open_in_browser url
end

#dataset?Boolean

#

words?

#

dataset?

Returns:

  • (Boolean)

282
283
284
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 282

def words?
  @words
end

#delay?Boolean

#

delay?

#

Returns:

  • (Boolean)

619
620
621
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 619

def delay?
  @delay
end

#do_ask_the_questionObject

#

do_ask_the_question

#

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 324

def do_ask_the_question # This method will ask the english question.
  if search_for?.empty?
    set_search_for_this_word 'RANDOM'
  end
  _ = search_for?
  if _ == 'rand'
    _ = (@search_for_this_word = return_random_word)
  end
  unless is_included? _
    set_xorg_buffer _
    opnn; e 'Sorry, the word `'+sfancy(_)+'` is not included.'
    opnn; e 'We will thus try to open our english dictionary in our editor'
    opnn; e 'and lookup the word in our browser.'
    open_main_yaml_file_in_main_editor # Added ~ 22.02.2013
    consider_opening_browser_page(_)
  else # Ok, we now know that it is included. Thus, continue.
    if be_verbose?
      e "#{rev}What does the word `#{sfancy(_)}` mean? #{show_delay_string}"
      find_this_word_in_yaml_file(_)
      new_buffer = build_url_www_string(_)
      set_xorg_buffer(new_buffer)
      sleep delay?
      reveal_the_answer
    end
  end
end

#feedback_delayObject

#

feedback_delay

#

626
627
628
629
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 626

def feedback_delay
  opnn; e "The delay we use is set to: #{sfancy(@delay.to_s)}"
  exit
end

#feedback_help_optionsObject

#

feedback_help_options

If you wish to trigger this, do:

askeng --help
#

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 253

def feedback_help_options # help tag
  e
  e LPAD+sfancy('TOTAL')+'  # Feedback how many keys are registered, '+
    'also aliased to '+sfancy('STATS')+'.'
  e LPAD+sfancy('OPEN')+'   # Open '+sfile(File.basename(main_file?))+
    ' and '+sfile('ask_english_word.rb')+' in the main editor.'
  e LPAD+sfancy('SOLVED')+' # Set the last word as solved.'
  e LPAD+sfancy('URL')+'    # Show the URL for the dictionary.'
  e LPAD+sfancy('REPEAT')+' # Repeat the last question asked.'
  e LPAD+sfancy('DELAY?')+' # Feedback the delay we use.'
  e LPAD+sfancy('STATS')+'  # To show some statistics, especially '\
    'the amount of registered words.'
  e LPAD+sfancy('FILE?')+'  # Show the main .yml file in question.'
  e
  exit
end

#feedback_statisticsObject

#

feedback_statistics

Feedback the amount of questions registered. In the future, perhaps we may want to have more statistic-options, so this may be expanded at a later time.

To trigger this, do:

askeng --stats?
#

491
492
493
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 491

def feedback_statistics
  feedback_total_amount_of_keys(:do_not_exit)
end

#feedback_total_amount_of_keys(shall_we_exit = true) ⇒ Object

#

feedback_total_amount_of_keys

#

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 528

def feedback_total_amount_of_keys(shall_we_exit = true) # KEYS
  case shall_we_exit
  when :do_not_exit
    shall_we_exit = false
  end
  _ = @original_words.size - @words.size
  opnn; e swarn(@original_words.size.to_s)+' english words in total.'
  rounded = sprintf('%0.2f', 100.0 - (@words.size * 100.0 / @original_words.size) )
  opnn; e swarn(@words.size.to_s)+' unanswered english words, '\
          'thus '+sfancy(_.to_s)+' are already answered. ('+
          simp(rounded.to_s+'%')+')'
  opnn; e 'The yaml file that we we will use is:'
  opnn; e '  '+sfile(main_file?)
  exit if shall_we_exit
end

#feedback_urlObject

#

feedback_url

#

498
499
500
501
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 498

def feedback_url
  opnn; e "  -> #{URL_FOR_DICT_LEO}"
  exit
end

#feedback_yaml_fileObject

#

feedback_yaml_file

#

650
651
652
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 650

def feedback_yaml_file
  efile main_file?
end

#find_all_matches_for(i) ⇒ Object

#

find_all_matches_for

#

127
128
129
130
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 127

def find_all_matches_for(i) # Must return an Array.
  selection = @words.select {|key,value| key.start_with? i }.keys
  return selection
end

#find_this_word_in_yaml_file(this_word) ⇒ Object

#

find_this_word_in_yaml_file

This method will give us the correct line number.

#

144
145
146
147
148
149
150
151
152
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 144

def find_this_word_in_yaml_file(this_word)
  _ = File.readlines(
    @use_this_file, :encoding => USE_THIS_ENCODING
  )
  _ = _.index() {|x| x =~ /^#{this_word}/ }
  line_number = _.to_i + 1
  save_line_number(line_number)
  save_last_question_asked(this_word)
end

#generate_tab_completion(this_language = 'english') ⇒ Object

#

generate_tab_completion (tab tag)

The first argument should be the name of the dictionary in question, such as 'english' or 'italian'.

To generate the tab completion, do this:

askeng TAB
#

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 183

def generate_tab_completion(
    this_language = 'english'
  )
  require 'generate_shell_completion'
  dataset = @original_words.keys # cat $SCI/YAML/DICTIONARIES/english.yml
  # Next, determine where to store the completion stuff.
  generate_where =
    ENV['MY_OS'].to_s+'/LINUX/SHELL/SCRIPTS/'+this_language+'_completion.sh'
  _ = GenerateShellCompletion::GenerateShellCompletion.new(:do_not_run_yet)
  _.add_data(dataset)
  _.set_file(generate_where)
  _.set_name_of_function(this_language.to_sym)
  _.add_aliases %w( askeng ask_eng ) 
  _.generate
end

#greenObject

#

green

#

16
17
18
# File 'lib/dictionaries/class/colours.rb', line 16

def green
  Colours::GREEN
end

#is_included?(i) ⇒ Boolean

#

is_included?

#

Returns:

  • (Boolean)

241
242
243
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 241

def is_included?(i)
  @original_words.has_key?(i)
end

#load_dataset(of_this_file = @use_this_file) ⇒ Object Also known as: load_main_dataset

#

load_dataset

Here we will define the important instance variable @original_words.

#

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 425

def load_dataset(
    of_this_file = @use_this_file
  ) # called via reset()
  of_this_file = of_this_file.to_s # We must work with a String.
  if File.exist? of_this_file
    dataset = YAML.load_file(of_this_file)
    @original_words = dataset
    # ^^^ This is the file english.yml
  else
    e 'Did not find a file at '+of_this_file+'.'
    e 'Thus, the @original_words will be empty.'
    e 'If you wish to change this, modify the constant ENGLISH_WORDS'
    e 'to point at a yaml-dataset (we require a hash, thus key: value pairs)'
    @original_words = {}
  end
  @words = @original_words.dup
  sanitize_dataset # Get rid of lines that have [] as entry.
end

#load_the_english_fileObject

#

load_the_english_file

#

462
463
464
465
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 462

def load_the_english_file
  set_use_this_file(:english)
  load_main_dataset
end

#main_file?Boolean Also known as: currently_selected_file?

#

main_file?

#

Returns:

  • (Boolean)

657
658
659
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 657

def main_file?
  Dictionaries.main_file?
end

#notify_the_user_that_we_will_next_open_this_file(this_file) ⇒ Object

#

notify_the_user_that_we_will_next_open_this_file

#

521
522
523
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 521

def notify_the_user_that_we_will_next_open_this_file(this_file)
  opnn; e 'Opening file `'+sfile(this_file)+'` next.'
end

#on_roebe?Boolean

#

on_roebe?

#

Returns:

  • (Boolean)

317
318
319
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 317

def on_roebe?
  ENV['IS_ROEBE'].to_s == '1'
end

#open_this_file_here(be_verbose = false) ⇒ Object

#

open_this_file_here

#

547
548
549
550
551
552
553
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 547

def open_this_file_here(be_verbose = false)
  _= Dictionaries.main_file?
  if be_verbose
    opnn; notify_the_user_that_we_will_next_open_this_file(_)
  end
  system 'bluefish '+_
end

#open_yaml_file_in_main_editor(this_file = main_file? ) ⇒ Object Also known as: open_main_yaml_file_in_main_editor

#

open_yaml_file_in_main_editor

#

506
507
508
509
510
511
512
513
514
515
516
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 506

def open_yaml_file_in_main_editor(
    this_file = main_file?
  )
  if on_roebe? # Rewrite for my own system at home.
    this_file = File.basename(this_file)
    this_file = MY_DICTIONARIES+this_file
  end
  _= this_file
  notify_the_user_that_we_will_next_open_this_file(_)
  system 'bluefish '+_
end

#opnnObject

#

opnn

#

477
478
479
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 477

def opnn
  Opn.opn(namespace: NAMESPACE)
end

#register_sigintObject

#

register_sigint

#

234
235
236
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 234

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

#resetObject

#

reset

#

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 92

def reset
  # ======================================================================= #
  # === @original_words
  # ======================================================================= #
  @original_words = {} # A Hash.
  # ======================================================================= #
  # === @words
  # ======================================================================= #
  @words = nil
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
  # ======================================================================= #
  # === @store_line_number_where
  # ======================================================================= #
  @store_line_number_where = STORE_LINE_NUMBER_HERE
  # ======================================================================= #
  # === @ask_the_question
  # ======================================================================= #
  @ask_the_question = true # Whether to ask the question or not.
  set_use_this_file # Set to nil initially.
  set_delay
end

#result?Boolean Also known as: result

#

result?

#

Returns:

  • (Boolean)

294
295
296
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 294

def result?
  @result
end

#return_random_wordObject

#

return_random_word

#

168
169
170
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 168

def return_random_word
  available_keys?.sample
end

#revObject

#

rev

#

354
355
356
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 354

def rev
  Colours.rev
end

#reveal_the_answerObject Also known as: reveal_answer

#

reveal_the_answer

Show the answer here.

#

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
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 204

def reveal_the_answer
  @result = @original_words[@search_for_this_word].to_s
  _ = @result
  begin
    _[0,1] = _[0,1].upcase
  rescue Exception => error
    opnn; e 'An exception happened at line '+simp(__LINE__.to_s)+' when '\
            'we tried to use .upcase.'
    opnn; e 'The file was '+sfile(__FILE__)
    opnn; e 'The difficult word in question was `'+simp(_)+'`.'
    opnn; e 'The encoding in use was '+simp(_.encoding.to_s)+'.'
    pp error
    begin
      _ = _.encode(USE_THIS_ENCODING)
      _[0,1] = _[0,1].upcase
    rescue Exception => error
      pp error
    end
  end
  _ = sanitize_answer(_)
  if _.include? '[]' # Chop off [] token, if it is part of the String.
    _ = _.force_encoding(USE_THIS_ENCODING) if _.encoding.to_s.include? 'UTF'
    _ = _.delete('[').delete(']').strip
  end
  e N+simportant(_)+'.'+N+N
end

#runObject

#

run (run tag)

#

664
665
666
667
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 664

def run
  load_dataset
  do_ask_the_question if @ask_the_question
end

#sanitize_answer(i) ⇒ Object

#

sanitize_answer

This may also re-encode the given String object.

#

560
561
562
563
564
565
566
567
568
569
570
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 560

def sanitize_answer(i)
  begin
    unless i.encoding.to_s.include? USE_THIS_ENCODING
      i = i.force_encoding(USE_THIS_ENCODING)
    end
    i.gsub!(/ \[\]/,'') if i.include? '[]'
  rescue Exception => error
    opnn; pp error # Propagate the error here to the user.
  end
  return i
end

#sanitize_datasetObject

#

sanitize_dataset

#

308
309
310
311
312
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 308

def sanitize_dataset # We have to ignore all entries that contain []. We do this only for @words.
  words?.reject! {|key, value|
    value.include? '[]'
  }
end

#save_file(what, into) ⇒ Object

#

save_file

#

612
613
614
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 612

def save_file(what, into)
  SaveFile.write_what_into(what, into)
end

#save_last_question_asked(what) ⇒ Object

#

save_last_question_asked

#

600
601
602
603
604
605
606
607
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 600

def save_last_question_asked(what) # Save the last question asked.
  into = store_last_question_asked_where?
  begin
    save_file(what, into)
  rescue Errno::ENOENT
    opnn; e "Can not store into `#{sfile(into)}`."
  end
end

#save_line_number(what) ⇒ Object

#

save_line_number

#

575
576
577
578
579
580
581
582
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 575

def save_line_number(what) # save tag
  begin
    save_file(what, @store_line_number_where)
  rescue => error
    pp error
    pp error.class
  end
end

#sdir(i) ⇒ Object

#

sdir

#

51
52
53
# File 'lib/dictionaries/class/colours.rb', line 51

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

#search_for?Boolean

#

search_for?

#

Returns:

  • (Boolean)

273
274
275
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 273

def search_for?
  @search_for_this_word
end

#set_delay(i = DEFAULT_DELAY) ⇒ Object

#

set_delay (delay tag)

#

120
121
122
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 120

def set_delay(i = DEFAULT_DELAY)
  @delay = i
end

#set_last_word_solvedObject

#

set_last_word_solved

#

587
588
589
590
591
592
593
594
595
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 587

def set_last_word_solved # Call this only when you want to solve an english word.
  begin
    require 'roebe/classes/append_to_line.rb'
    _ = Roebe::AppendToLine.new(:english, false) # bl $RUBY_TOOLS/append_to_line.rb
    _.set_line File.read(STORE_LINE_NUMBER_HERE)
    _.run
  rescue LoadError; end  
  exit
end

#set_search_for_this_word(i = :rand) ⇒ Object

#

set_search_for_this_word (menu tag)

This method will also have the menu-functionality of the class.

#

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
# File 'lib/dictionaries/class/set_search_for_this_word.rb', line 16

def set_search_for_this_word(i = :rand)
  i = i.join(' ').strip if i.is_a? Array # This will also handle empty ARGV passed to us.
  i = :rand if i.nil?
  case i
  when :rand, 'rand' # We want a random word here.
    i = return_random_word if @words
  end
  # ======================================================================= #
  # We want a String past this point.
  # ======================================================================= #
  i = i.to_s.dup
  # ======================================================================= #
  # We can not downcase the input since we also try to have it match
  # towards regular english letters. It is a dictionary after all.
  # ======================================================================= #
  # === Chop off last char if it is a question mark.
  # ======================================================================= #
  i.chop! if i.end_with? '?'
  case i # case tag
  # ======================================================================= #
  # === askeng --delay?
  # ======================================================================= #
  when /^-?-?delay\??$/i
    feedback_delay
  # ======================================================================= #
  # === askeng --openall
  # ======================================================================= #
  when 'OPEN',
       'OPE',
       'OP',
       'O',
       'EDIT',
       'OPEN_ALL',
       /open/,
       'OPENALL',
       '--openall'
    open_this_file_here(true) # true for "be verbose".
    open_yaml_file_in_main_editor
    exit
  # ======================================================================= #
  # === askeng --n-entries
  # ======================================================================= #
  when 'TOTAL',
       'KEYS',
       'KEYSTATS',
       '--n-entries',
       '--nentries',
       'keys?',
       'nkeys',
       /-?-?nwords\??/
    feedback_total_amount_of_keys
  # ======================================================================= #
  # === askeng --stats
  # ======================================================================= #  
  when '--stats','--statistics','STATS','STATISTICS','STATS?','--stats?'
    feedback_statistics; exit
  # ======================================================================= #
  # === askeng --help
  # ======================================================================= #
  when 'HELP','--help','show_help','--HELP'
    feedback_help_options # This will also exit.
  # ======================================================================= #
  # === askeng --every_word
  # ======================================================================= #
  when 'SHOW',
       '--show-every-word',
       '--every_word'
    show_every_word
    exit
  # ======================================================================= #
  # === askeng --generate-tab
  # ======================================================================= #
  when 'GENERATE',
       'TAB',
       'GENERATE_COMPLETION',
       'TABCOMPLETION',
       'COMPLETION',
       '--generate-tab'
    generate_tab_completion
    exit
  # ======================================================================= #
  # === askeng --open-in-browser
  # ======================================================================= #
  when 'OPEN_BROWSER','--open-in-browser'
    open_in_browser
  # ======================================================================= #
  # === askeng --solved
  # ======================================================================= #
  when 'SOLVED',/-?-?solved/
    set_last_word_solved
  # ======================================================================= #
  # === askeng --yaml-file?
  # ======================================================================= #
  when 'FILE?',
       'YAML_FILE?','--yaml-file?'
    feedback_yaml_file
    exit
  # ======================================================================= #
  # === askeng --open-dictionary
  # ======================================================================= #
  when 'OPEN_DICTIONARY','OPEN_DICT','--open-dictionary'
    open_main_yaml_file_in_main_editor
    exit
  # ======================================================================= #
  # === askeng --repeat
  # ======================================================================= #
  when 'REPEAT','--repeat'
    _ = STORE_LAST_QUESTION_ASKED_HERE
    if File.exist? _
      i = File.read(_)
    else
      opnn; e 'The file `'+sfile(_)+'` was not found, thus we can'
      opnn; e 'not read in anything.'
      exit
    end
  # ======================================================================= #
  # === askeng --url
  # ======================================================================= #
  when '--url','URL'
    feedback_url
  # ======================================================================= #
  # === askeng --random
  # ======================================================================= #
  when /^-?-?random$/i,'RAND','rand' # Pass through here.
    i = return_random_word if available_keys?
  # else tag
  else # Handle assignment cases next.
    if i.include?('=') and i.downcase.include? 'delay'
      new_delay = i.split('=').last.strip
      e 'It seems as if you may want to assign a new delay.'
      e 'We will thus set the last line of this file here'
      e 'with the new delay of:'
      e '  '+sfancy(new_delay)
      what = File.readlines(Dictionaries::AskEnglishWord.main_file?)
      what[-1,1] = new_delay # Set the new entry here.
      SaveFile.write_what_into(what.join, Dictionaries::AskEnglishWord.main_file?)
      exit
    end
  end
  i = i.to_s.dup
  i = i.downcase if SHALL_WE_DOWNCASE
  if i.size == 1 # We assume that the user wants to get a category.
    i = find_all_matches_for(i).sample
  end
  @search_for_this_word = i # We will search for this word here.
end

#set_use_this_file(i = :default) ⇒ Object

#

set_use_this_file

This sets the main dictionary-file to use, the file path to it.

#

449
450
451
452
453
454
455
456
457
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 449

def set_use_this_file(i = :default)
  case i
  when :english
    i = ENGLISH_WORDS
  when :default_file, :default
    i = main_file?
  end
  @use_this_file = i
end

#set_xorg_buffer(i) ⇒ Object

#

set_xorg_buffer

#

361
362
363
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 361

def set_xorg_buffer(i)
  XorgBuffer[i] if Object.const_defined? :XorgBuffer
end

#sfancy(i) ⇒ Object

#

sfancy

#

30
31
32
# File 'lib/dictionaries/class/colours.rb', line 30

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

#sfile(i) ⇒ Object

#

sfile

#

44
45
46
# File 'lib/dictionaries/class/colours.rb', line 44

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

#show_delay_stringObject

#

show_delay_string

#

641
642
643
644
645
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 641

def show_delay_string
  result = '(Delay is at '+simp(@delay.to_s)+' seconds)'
  result = '' if @delay.to_i == 0
  return result
end

#show_every_wordObject

#

show_every_word

This will simply show every word.

#

159
160
161
162
163
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 159

def show_every_word
  @original_words.each_pair {|key, value|
    e "#{key.to_s.ljust(20)} -> #{value}"
  }
end

#show_helpObject

#

show_help

Show the help options.

#

417
418
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 417

def show_help
end

#simp(i) ⇒ Object Also known as: simportant

#

simp

#

37
38
39
# File 'lib/dictionaries/class/colours.rb', line 37

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

#store_last_question_asked_where?Boolean

#

store_last_question_asked_where?

This method will try to automatically find out where we will store the last question asked.

#

Returns:

  • (Boolean)

371
372
373
374
375
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 371

def store_last_question_asked_where?
  name = Dictionaries.return_name_from_compound(main_file?)
  path = DEPOT_INFORMATION_DIR+'last_'+name+'_question_asked'
  return path
end

#translate(i) ⇒ Object

#

translate

#

634
635
636
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 634

def translate(i)
  return @original_words[i].to_s
end

#use_this_file?Boolean

#

use_this_file?

#

Returns:

  • (Boolean)

470
471
472
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 470

def use_this_file?
  @use_this_file
end

#words?Boolean

#

words?

#

Returns:

  • (Boolean)

280
281
282
# File 'lib/dictionaries/class/ask_word_from_dictionary.rb', line 280

def words?
  @words
end