Class: Dictionaries::AskWordFromDictionary
- Defined in:
- lib/dictionaries/class/class.rb
Overview
Dictionaries::AskWordFromDictionary
Direct Known Subclasses
Constant Summary collapse
- USE_THIS_EDITOR =
#
USE_THIS_EDITOR
#
'bluefish'
- NAMESPACE =
#
NAMESPACE
#
inspect
Instance Method Summary collapse
-
#available_keys? ⇒ Boolean
(also: #array)
# === available_keys? ========================================================================= #.
-
#be_verbose? ⇒ Boolean
# === be_verbose? ========================================================================= #.
-
#brown(i = '') ⇒ Object
# === brown ========================================================================= #.
-
#build_url_www_string(i) ⇒ Object
# === build_url_www_string ========================================================================= #.
-
#consider_opening_browser_page(i = '') ⇒ Object
# === consider_opening_browser_page ========================================================================= #.
-
#dataset? ⇒ Boolean
# === words? ========================================================================= # === dataset?.
-
#delay? ⇒ Boolean
# === delay? ========================================================================= #.
-
#do_ask_the_question ⇒ Object
# === do_ask_the_question ========================================================================= #.
-
#feedback_delay ⇒ Object
# === feedback_delay ========================================================================= #.
-
#feedback_help_options ⇒ Object
# === feedback_help_options.
-
#feedback_statistics ⇒ Object
# === feedback_statistics.
-
#feedback_total_amount_of_keys(shall_we_exit = true) ⇒ Object
# === feedback_total_amount_of_keys ========================================================================= #.
-
#feedback_url ⇒ Object
# === feedback_url ========================================================================= #.
-
#feedback_yaml_file ⇒ Object
# === feedback_yaml_file ========================================================================= #.
-
#find_all_matches_for(i) ⇒ Object
# === find_all_matches_for ========================================================================= #.
-
#find_this_word_in_yaml_file(this_word) ⇒ Object
# === find_this_word_in_yaml_file.
-
#generate_tab_completion(this_language = 'english') ⇒ Object
# === generate_tab_completion (tab tag).
-
#green ⇒ Object
# === green ========================================================================= #.
-
#initialize(optional_search_for_this_word = nil, use_this_file_for_the_dataset = :default_file, run_already = true) ⇒ AskWordFromDictionary
constructor
# === initialize ========================================================================= #.
-
#is_included?(i) ⇒ Boolean
# === is_included? ========================================================================= #.
-
#load_dataset(of_this_file = @use_this_file) ⇒ Object
(also: #load_main_dataset)
# === load_dataset.
-
#load_the_english_file ⇒ Object
# === load_the_english_file ========================================================================= #.
-
#main_file? ⇒ Boolean
(also: #currently_selected_file?)
# === main_file? ========================================================================= #.
-
#notify_the_user_that_we_will_next_open_this_file(this_file) ⇒ Object
# === notify_the_user_that_we_will_next_open_this_file ========================================================================= #.
-
#on_roebe? ⇒ Boolean
# === on_roebe? ========================================================================= #.
-
#open_this_file_here(be_verbose = false) ⇒ Object
# === open_this_file_here ========================================================================= #.
-
#open_yaml_file_in_main_editor(this_file = main_file? ) ⇒ Object
(also: #open_main_yaml_file_in_main_editor)
# === open_yaml_file_in_main_editor ========================================================================= #.
-
#opnn ⇒ Object
# === opnn ========================================================================= #.
-
#register_sigint ⇒ Object
# === register_sigint ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#result? ⇒ Boolean
(also: #result)
# === result? ========================================================================= #.
-
#return_random_word ⇒ Object
# === return_random_word ========================================================================= #.
-
#rev ⇒ Object
(also: #revert)
# === rev ========================================================================= #.
-
#reveal_the_answer ⇒ Object
(also: #reveal_answer)
# === reveal_the_answer.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#sanitize_answer(i) ⇒ Object
# === sanitize_answer.
-
#sanitize_dataset ⇒ Object
# === sanitize_dataset ========================================================================= #.
-
#save_file(what, into) ⇒ Object
# === save_file ========================================================================= #.
-
#save_last_question_asked(what) ⇒ Object
# === save_last_question_asked ========================================================================= #.
-
#save_line_number(what) ⇒ Object
# === save_line_number ========================================================================= #.
-
#sdir(i) ⇒ Object
# === sdir ========================================================================= #.
-
#search_for? ⇒ Boolean
# === search_for? ========================================================================= #.
-
#set_delay(i = DEFAULT_DELAY) ⇒ Object
# === set_delay (delay tag) ========================================================================= #.
-
#set_last_word_solved ⇒ Object
# === set_last_word_solved ========================================================================= #.
-
#set_search_for_this_word(i = :rand) ⇒ Object
# === set_search_for_this_word (menu tag).
-
#set_use_this_file(i = :default) ⇒ Object
# === set_use_this_file.
-
#set_xorg_buffer(i) ⇒ Object
# === set_xorg_buffer ========================================================================= #.
-
#sfancy(i) ⇒ Object
# === sfancy ========================================================================= #.
-
#sfile(i) ⇒ Object
# === sfile ========================================================================= #.
-
#show_delay_string(delay = delay? ) ⇒ Object
# === show_delay_string ========================================================================= #.
-
#show_every_word ⇒ Object
# === show_every_word.
-
#show_help ⇒ Object
# === show_help.
-
#simp(i) ⇒ Object
(also: #simportant)
# === simp ========================================================================= #.
-
#store_last_question_asked_where? ⇒ Boolean
# === store_last_question_asked_where?.
-
#translate(i) ⇒ Object
# === translate ========================================================================= #.
-
#use_this_file? ⇒ Boolean
# === use_this_file? ========================================================================= #.
-
#words? ⇒ Boolean
# === words? ========================================================================= #.
Methods inherited from Base
#commandline_arguments?, #first_argument?, #opne, #set_commandline_arguments
Constructor Details
#initialize(optional_search_for_this_word = nil, use_this_file_for_the_dataset = :default_file, run_already = true) ⇒ AskWordFromDictionary
#
initialize
#
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 |
# File 'lib/dictionaries/class/class.rb', line 60 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 # ======================================================================= # # === :do_not_run_yet # ======================================================================= # when :do_not_run_yet run_already = false 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?
#
184 185 186 |
# File 'lib/dictionaries/class/class.rb', line 184 def available_keys? @words.keys if @words end |
#be_verbose? ⇒ Boolean
#
be_verbose?
#
304 305 306 |
# File 'lib/dictionaries/class/class.rb', line 304 def be_verbose? @be_verbose end |
#brown(i = '') ⇒ Object
#
brown
#
106 107 108 |
# File 'lib/dictionaries/class/class.rb', line 106 def brown(i = '') "#{::Colours::BROWN}#{i}#{revert}" end |
#build_url_www_string(i) ⇒ Object
#
build_url_www_string
#
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/dictionaries/class/class.rb', line 403 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§Hdr=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
#
838 839 840 841 842 |
# File 'lib/dictionaries/class/class.rb', line 838 def consider_opening_browser_page(i = '') url = build_url_www_string(i) opne 'Consider visiting '+brown(url)+' if you need a translation.' Open.in_browser(url) if Object.const_defined?(:Open) end |
#dataset? ⇒ Boolean
#
words?
#
dataset?
299 300 301 |
# File 'lib/dictionaries/class/class.rb', line 299 def words? @words end |
#delay? ⇒ Boolean
#
delay?
#
633 634 635 |
# File 'lib/dictionaries/class/class.rb', line 633 def delay? @delay end |
#do_ask_the_question ⇒ Object
#
do_ask_the_question
#
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/dictionaries/class/class.rb', line 341 def do_ask_the_question # This method will ask the english question. if search_for?.empty? # set_search_for_this_word 'RANDOM' # The above ^^^ was changed in August 2023. e "#{rev}Please provide an argument to this class, the word that is" e "#{rev}to be translated." return end _ = search_for? case _ when 'rand' _ = (@search_for_this_word = return_random_word) end unless is_included? _ set_xorg_buffer _ opne "The word `#{sfancy(_)}"\ "#{rev}` is not included in the database." opne 'Thus, the english-dictionary will now be opened via the main' opne 'editor, before that missing word is then looked-up via the browser.' open_main_yaml_file_in_main_editor # Added this as of ~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(_)}#{rev}` 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_delay ⇒ Object
#
feedback_delay
#
640 641 642 643 |
# File 'lib/dictionaries/class/class.rb', line 640 def feedback_delay opne "The delay we use is set to: #{sfancy(@delay.to_s)}" exit end |
#feedback_help_options ⇒ Object
#
feedback_help_options
If you wish to trigger this, do:
askeng --help
#
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/dictionaries/class/class.rb', line 270 def # 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_statistics ⇒ Object
#
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?
#
505 506 507 |
# File 'lib/dictionaries/class/class.rb', line 505 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
#
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/dictionaries/class/class.rb', line 542 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 opne swarn(@original_words.size.to_s)+' english words in total.' rounded = sprintf('%0.2f', 100.0 - (@words.size * 100.0 / @original_words.size) ) opne swarn(@words.size.to_s)+' unanswered english words, '\ 'thus '+sfancy(_.to_s)+' are already answered. ('+ simp(rounded.to_s+'%')+')' opne 'The yaml file that we we will use is:' opne ' '+sfile(main_file?) exit if shall_we_exit end |
#feedback_url ⇒ Object
#
feedback_url
#
512 513 514 515 |
# File 'lib/dictionaries/class/class.rb', line 512 def feedback_url opne " -> #{URL_FOR_DICT_LEO}" exit end |
#feedback_yaml_file ⇒ Object
#
feedback_yaml_file
#
824 825 826 |
# File 'lib/dictionaries/class/class.rb', line 824 def feedback_yaml_file efile main_file? end |
#find_all_matches_for(i) ⇒ Object
#
find_all_matches_for
#
176 177 178 179 |
# File 'lib/dictionaries/class/class.rb', line 176 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.
#
193 194 195 196 197 198 199 200 201 |
# File 'lib/dictionaries/class/class.rb', line 193 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
#
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/dictionaries/class/class.rb', line 232 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 |
#green ⇒ Object
#
green
#
99 100 101 |
# File 'lib/dictionaries/class/class.rb', line 99 def green Colours::GREEN end |
#is_included?(i) ⇒ Boolean
#
is_included?
#
258 259 260 |
# File 'lib/dictionaries/class/class.rb', line 258 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.
#
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
# File 'lib/dictionaries/class/class.rb', line 439 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_file ⇒ Object
#
load_the_english_file
#
476 477 478 479 |
# File 'lib/dictionaries/class/class.rb', line 476 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?
#
831 832 833 |
# File 'lib/dictionaries/class/class.rb', line 831 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
#
535 536 537 |
# File 'lib/dictionaries/class/class.rb', line 535 def notify_the_user_that_we_will_next_open_this_file(this_file) opne 'Opening file `'+sfile(this_file)+'` next.' end |
#on_roebe? ⇒ Boolean
#
on_roebe?
#
334 335 336 |
# File 'lib/dictionaries/class/class.rb', line 334 def on_roebe? ENV['IS_ROEBE'].to_s == '1' end |
#open_this_file_here(be_verbose = false) ⇒ Object
#
open_this_file_here
#
561 562 563 564 565 566 567 |
# File 'lib/dictionaries/class/class.rb', line 561 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 "#{USE_THIS_EDITOR} #{_}" 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
#
520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/dictionaries/class/class.rb', line 520 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 "#{USE_THIS_EDITOR} #{_}" end |
#opnn ⇒ Object
#
opnn
#
491 492 493 |
# File 'lib/dictionaries/class/class.rb', line 491 def opnn Opn.opn(namespace: NAMESPACE) end |
#register_sigint ⇒ Object
#
register_sigint
#
251 252 253 |
# File 'lib/dictionaries/class/class.rb', line 251 def register_sigint Signal.trap('SIGINT') { exit } end |
#reset ⇒ Object
#
reset
#
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dictionaries/class/class.rb', line 141 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?
#
311 312 313 |
# File 'lib/dictionaries/class/class.rb', line 311 def result? @result end |
#return_random_word ⇒ Object
#
return_random_word
#
217 218 219 |
# File 'lib/dictionaries/class/class.rb', line 217 def return_random_word available_keys?.sample end |
#rev ⇒ Object Also known as: revert
#
rev
#
377 378 379 |
# File 'lib/dictionaries/class/class.rb', line 377 def rev ::Colours.rev end |
#reveal_the_answer ⇒ Object Also known as: reveal_answer
#
reveal_the_answer
Show the answer here.
#
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
# File 'lib/dictionaries/class/class.rb', line 849 def reveal_the_answer @result = @original_words[@search_for_this_word].to_s _ = @result begin _[0,1] = _[0,1].upcase rescue Exception => error opne 'An exception happened at line '+simp(__LINE__.to_s)+' when '\ 'we tried to use .upcase.' opne 'The file was '+sfile(__FILE__) opne 'The difficult word in question was `'+simp(_)+'`.' opne '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 # ======================================================================= # # Finally show the answer: # ======================================================================= # e "#{N} #{simportant(_)}#{rev}.#{N}#{N}" # Slight leading padding since as of February 2024. end |
#run ⇒ Object
#
run (run tag)
#
882 883 884 885 |
# File 'lib/dictionaries/class/class.rb', line 882 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.
#
574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/dictionaries/class/class.rb', line 574 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_dataset ⇒ Object
#
sanitize_dataset
#
325 326 327 328 329 |
# File 'lib/dictionaries/class/class.rb', line 325 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
#
626 627 628 |
# File 'lib/dictionaries/class/class.rb', line 626 def save_file(what, into) SaveFile.write_what_into(what, into) end |
#save_last_question_asked(what) ⇒ Object
#
save_last_question_asked
#
614 615 616 617 618 619 620 621 |
# File 'lib/dictionaries/class/class.rb', line 614 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 opne "Can not store into `#{sfile(into)}`." end end |
#save_line_number(what) ⇒ Object
#
save_line_number
#
589 590 591 592 593 594 595 596 |
# File 'lib/dictionaries/class/class.rb', line 589 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
#
134 135 136 |
# File 'lib/dictionaries/class/class.rb', line 134 def sdir(i) ::Colours.sdir(i) end |
#search_for? ⇒ Boolean
#
search_for?
#
290 291 292 |
# File 'lib/dictionaries/class/class.rb', line 290 def search_for? @search_for_this_word end |
#set_delay(i = DEFAULT_DELAY) ⇒ Object
#
set_delay (delay tag)
#
169 170 171 |
# File 'lib/dictionaries/class/class.rb', line 169 def set_delay(i = DEFAULT_DELAY) @delay = i end |
#set_last_word_solved ⇒ Object
#
set_last_word_solved
#
601 602 603 604 605 606 607 608 609 |
# File 'lib/dictionaries/class/class.rb', line 601 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.
#
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 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 743 744 745 746 747 748 749 750 751 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 777 778 779 780 781 782 783 784 785 786 787 788 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 |
# File 'lib/dictionaries/class/class.rb', line 668 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 # ======================================================================= # # === :rand # ======================================================================= # 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 --help # ======================================================================= # when /^-?-?help$/i, 'show_help' # This will also exit. # ======================================================================= # # === 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 --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.
#
463 464 465 466 467 468 469 470 471 |
# File 'lib/dictionaries/class/class.rb', line 463 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
#
384 385 386 |
# File 'lib/dictionaries/class/class.rb', line 384 def set_xorg_buffer(i) XorgBuffer[i] if Object.const_defined? :XorgBuffer end |
#sfancy(i) ⇒ Object
#
sfancy
#
113 114 115 |
# File 'lib/dictionaries/class/class.rb', line 113 def sfancy(i) ::Colours.sfancy(i) end |
#sfile(i) ⇒ Object
#
sfile
#
127 128 129 |
# File 'lib/dictionaries/class/class.rb', line 127 def sfile(i) ::Colours.sfile(i) end |
#show_delay_string(delay = delay? ) ⇒ Object
#
show_delay_string
#
655 656 657 658 659 660 661 |
# File 'lib/dictionaries/class/class.rb', line 655 def show_delay_string( delay = delay? ) result = "(Delay is at #{simp(@delay.to_s)}#{rev} seconds)" result = '' if delay.to_i == 0 return result end |
#show_every_word ⇒ Object
#
show_every_word
This will simply show every word.
#
208 209 210 211 212 |
# File 'lib/dictionaries/class/class.rb', line 208 def show_every_word @original_words.each_pair {|key, value| e "#{key.to_s.ljust(20)} -> #{value}" } end |
#show_help ⇒ Object
#
show_help
Show the help options.
#
431 432 |
# File 'lib/dictionaries/class/class.rb', line 431 def show_help end |
#simp(i) ⇒ Object Also known as: simportant
#
simp
#
120 121 122 |
# File 'lib/dictionaries/class/class.rb', line 120 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.
#
394 395 396 397 398 |
# File 'lib/dictionaries/class/class.rb', line 394 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
#
648 649 650 |
# File 'lib/dictionaries/class/class.rb', line 648 def translate(i) return @original_words[i].to_s end |
#use_this_file? ⇒ Boolean
#
use_this_file?
#
484 485 486 |
# File 'lib/dictionaries/class/class.rb', line 484 def use_this_file? @use_this_file end |
#words? ⇒ Boolean
#
words?
#
297 298 299 |
# File 'lib/dictionaries/class/class.rb', line 297 def words? @words end |