dictionaries 0.3.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dictionaries might be problematic. Click here for more details.

Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +219 -0
  3. data/bin/dictionaries +7 -0
  4. data/bin/unique_words_in_this_file +7 -0
  5. data/dictionaries.gemspec +85 -0
  6. data/doc/README.gen +176 -0
  7. data/doc/todo/todo.md +5 -0
  8. data/lib/dictionaries/ask_english_word.rb +141 -0
  9. data/lib/dictionaries/ask_italian_word.rb +84 -0
  10. data/lib/dictionaries/class/ask_word_from_dictionary.rb +693 -0
  11. data/lib/dictionaries/class/colours.rb +55 -0
  12. data/lib/dictionaries/class/constants.rb +16 -0
  13. data/lib/dictionaries/class/set_search_for_this_word.rb +163 -0
  14. data/lib/dictionaries/commandline/parse_commandline.rb +75 -0
  15. data/lib/dictionaries/constants.rb +133 -0
  16. data/lib/dictionaries/gui/gtk3/dictionary/dictionary.rb +457 -0
  17. data/lib/dictionaries/gui/tk/README.md +2 -0
  18. data/lib/dictionaries/gui/tk/dictionary.rb +85 -0
  19. data/lib/dictionaries/project/project_base_directory.rb +22 -0
  20. data/lib/dictionaries/project/project_yaml_directory.rb +25 -0
  21. data/lib/dictionaries/require_project/require_project.rb +11 -0
  22. data/lib/dictionaries/sinatra/app.rb +105 -0
  23. data/lib/dictionaries/sinatra/english_to_german.rb +88 -0
  24. data/lib/dictionaries/toplevel_methods/e.rb +16 -0
  25. data/lib/dictionaries/toplevel_methods/english_to_german.rb +31 -0
  26. data/lib/dictionaries/toplevel_methods/has_key.rb +32 -0
  27. data/lib/dictionaries/toplevel_methods/is_on_roebe.rb +16 -0
  28. data/lib/dictionaries/toplevel_methods/main_file.rb +88 -0
  29. data/lib/dictionaries/toplevel_methods/misc.rb +185 -0
  30. data/lib/dictionaries/toplevel_methods/module_methods.rb +9 -0
  31. data/lib/dictionaries/toplevel_methods/show_help.rb +31 -0
  32. data/lib/dictionaries/version/version.rb +17 -0
  33. data/lib/dictionaries/yaml/chinese.yml +21 -0
  34. data/lib/dictionaries/yaml/danish.yml +4 -0
  35. data/lib/dictionaries/yaml/deutsche_fremdwoerter.yml +1 -0
  36. data/lib/dictionaries/yaml/dutch.yml +3 -0
  37. data/lib/dictionaries/yaml/english.yml +2537 -0
  38. data/lib/dictionaries/yaml/farsi.yml +8 -0
  39. data/lib/dictionaries/yaml/finnish.yml +2 -0
  40. data/lib/dictionaries/yaml/italian.yml +504 -0
  41. data/lib/dictionaries/yaml/japanese.yml +15 -0
  42. data/lib/dictionaries/yaml/norwegian.yml +26 -0
  43. data/lib/dictionaries/yaml/portugese.yml +42 -0
  44. data/lib/dictionaries/yaml/russian.yml +10 -0
  45. data/lib/dictionaries/yaml/spanish.yml +130 -0
  46. data/lib/dictionaries/yaml/swedish.yml +101 -0
  47. data/lib/dictionaries.rb +1 -0
  48. metadata +208 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 62930bb167bba769a92f5706a71e4c2fe336f2d12aa9b5aeeab1b256b5cc71fc
4
+ data.tar.gz: 2b4c175f20c648c169b84727339ea76f46c7ffe836b69ca8d1161e4b56d43db0
5
+ SHA512:
6
+ metadata.gz: 9fc775f6d0a1a339c33d9bb9e7b3bb2c3345298b873a2c498bbaf8f641eb370633290c3ff569b3d3d430f2867344b7fb2728d133436670a46a0ef682fc239cd1
7
+ data.tar.gz: e03551937464bab00ebc197019d5bb73a8e8c52e7e00c3058a7f3288075a16e8618aa729a318e29a75eea2991217e0602b4feacae6e61f20a1d9251d4d40b9d6
data/README.md ADDED
@@ -0,0 +1,219 @@
1
+ [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](https://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
3
+ [![Gem Version](https://badge.fury.io/rb/dictionaries.svg)](https://badge.fury.io/rb/dictionaries)
4
+
5
+ This gem was <b>last updated</b> on the <span style="color: darkblue; font-weight: bold">30.07.2022</span> (dd.mm.yyyy notation), at <span style="color: steelblue; font-weight: bold">18:47:39</span> o'clock.
6
+
7
+ ## Environment variable to use a specific yaml file
8
+
9
+ You can use an <b>environment variable</b> to denote the default
10
+ yaml file in use. This allows you to use your own yaml file
11
+ format, rather than the yaml files that are distributed with
12
+ this gem.
13
+
14
+ The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
15
+ It shall point to your yaml file that holds the key-value pairs.
16
+
17
+ For example, if your file is at /opt/czech.yml, then
18
+ DICTIONARIES_FILE should point at that location.
19
+
20
+ In bash, this may be equivalent to:
21
+
22
+ export DICTIONARIES_FILE=/opt/czech.yml
23
+
24
+ Note that in the long run, the dictionaries gem could be extended
25
+ with these yaml files - or allow means to download these files
26
+ over the www. But before we can do so, let's aim for at the least
27
+ 100 words in such a file before we would consider distributing
28
+ it or offering means to distribute said file.
29
+
30
+ ## Difficult english sentences
31
+
32
+ English is not the most difficult language in the world, but when it
33
+ comes to proper pronounciation of words, english can be surprisingly
34
+ difficult.
35
+
36
+ This subsection may keep a listing of sentences that, for one reason
37
+ or the other, can be somewhat difficult to **read out aloud** without
38
+ mistake, on a first try. It is just a fun-subsection, not meant to be
39
+ taken too seriously; and it is quite subjective.
40
+
41
+ Without any further ado, here comes a listing of sentences that may
42
+ be difficult to pronounce properly so:
43
+
44
+ I would like to distribute something.
45
+
46
+ ## Obtaining all translations into german for a given english word
47
+
48
+ Since as of **November 2020** the following API exists:
49
+
50
+ Dictionaries.return_array_of_translated_words_from_online_leo('cat')
51
+ Dictionaries.return_array_of_translated_words_from_online_leo('dog')
52
+ Dictionaries.return_array_of_translated_words_from_online_leo('human')
53
+
54
+ This will return an Array of german names. It does not work 100% perfectly
55
+ as it is based on a regex; and using a regex to parse HTML is never a
56
+ trivial way. But if you just want to get the first entry, just call
57
+ .first on it, and in most cases this is the best, most likely
58
+ translation available.
59
+
60
+ The regex has to find matches to entries such as the following one:
61
+
62
+ </repr><words><word>der Jazzfan</word></words>
63
+
64
+ Anyone to come up with a more accurate regex is welcome to share it. :)
65
+
66
+ This functionality was specifically necessary because I needed to
67
+ use this in the ruby-gtk bindings for this project.
68
+
69
+ ## Dictionaries.return_unique_words_from_this_file
70
+
71
+ This method will return all words that are presently not registered
72
+ in the english dictionary.
73
+
74
+ The idea here is for me to slowly add more english words into the
75
+ yaml file. I won't add every english word that exists, but I will
76
+ try to aim for a seizable number in the long run, such as
77
+ 5000 english words - already halfway there. \o/
78
+
79
+ ## GUI component
80
+
81
+ The **GUI component** of the dictionaries gem defaults to
82
+ **GTK3** finally. It is not a very advanced GUI, though.
83
+
84
+ First, install the gtk3 gem:
85
+
86
+ gem install gtk3
87
+
88
+ Then install the gtk_paradise project:
89
+
90
+ gem install gtk_paradise
91
+
92
+ Now you should be able to start the GUI component if the above
93
+ has worked:
94
+
95
+ dictionaries --gui
96
+
97
+ See also the help options.
98
+
99
+ dictionaries --help
100
+
101
+ You may need to install some .h files if you use a specific
102
+ Linux distribution; look at the relevant -dev packages for
103
+ this. Or just compile from source. :)
104
+
105
+ The current version of ruby-gtk3 in October 2021 looks like
106
+ this:
107
+
108
+ <img src="https://i.imgur.com/K430Kae.png" style="margin-left: 2em">
109
+
110
+ Yes, this isn't very pretty; I just wanted to focus a bit on
111
+ the functionality. Tons of things are missing, such as
112
+ switching to other .yml files from within the GUI itself.
113
+ I just wanted to showcase a demo - the convert from
114
+ english-to-german functionality is working, though, so
115
+ the GUI is functional, even if not super-pretty.
116
+
117
+ In **February 2022** this was improved a little bit. It's still
118
+ not extremely pretty, but you can see a few small improvements.
119
+ In the long run I will add functionality to switch between
120
+ different .yml files (thus, different dictionaries, such as
121
+ english, italian and so forth) - but it is a hobby project.
122
+ I won't have enough time to add all dictionaries into this
123
+ project as-is. I will, however had, add the possibility to
124
+ load custom .yml files and other formats in the long run,
125
+ so others can adapt the project to suit their needs.
126
+
127
+ <img src="https://i.imgur.com/ChFJmfo.png" style="margin-left: 2em">
128
+
129
+ ## sinatra
130
+
131
+ To start the sinatra interface of the dictionaries gem, do:
132
+
133
+ dictionaries --sinatra
134
+
135
+ You can then visit it on the localhost and it may look like
136
+ this:
137
+
138
+ <img src="https://i.imgur.com/uhzbXZ1.png" style="margin: 0.5em; margin-left: 2em">
139
+
140
+ You can then input an english word into the form, or the
141
+ URL area in your browser. If this word is registered in
142
+ the .yml file then the following result can be seen:
143
+
144
+ <img src="https://i.imgur.com/i1RqRmr.png" style="margin: 0.5em; margin-left: 2em">
145
+
146
+ This is really just very basic - I wanted to show the
147
+ functionality. You may have to adapt the code if you
148
+ have a more realistic use case, so consider the images
149
+ above just as examples of how this <b>could</b> be
150
+ used in a website.
151
+
152
+ ## Generating a .pdf file containing the translations
153
+
154
+ Since as of <b>July 2022</b> you can generate a .pdf file
155
+ with all the translated words. This functionality depends
156
+ on the <b>prawn</b> gem right now, so make sure that
157
+ this gem is installed before invoking the ruby code
158
+ that generates the .pdf file.
159
+
160
+ The toplevel API for creating the .pdf file is as follows:
161
+
162
+ Dictionaries.generate_pdf_file
163
+
164
+ ## Licence
165
+
166
+ Until the 17th of October 2019, this project was using the **GPLv2
167
+ licence** (no later clause).
168
+
169
+ However had, I believe that the GPLv2 licence is not great for
170
+ a project that focuses on existing words in **real languages**,
171
+ aka dictionaries. Thus, I have decided to change the licence into
172
+ the **MIT licence** on that day (**17.11.2019**, in dd.mm.yyyy notation).
173
+
174
+ So the gem is now MIT licenced. There may be dragons! \o/
175
+
176
+ For a description of that licence, see
177
+ https://opensource.org/licenses/MIT.
178
+
179
+
180
+ ## Contact information and mandatory 2FA coming up in 2022
181
+
182
+ If your creative mind has ideas and specific suggestions to make this gem
183
+ more useful in general, feel free to drop me an email at any time, via:
184
+
185
+ shevy@inbox.lt
186
+
187
+ Before that email I used an email account at Google gmail, but in **2021** I
188
+ decided to slowly abandon gmail for various reasons. In order to limit this
189
+ explanation here, allow me to just briefly state that I do not feel as if I
190
+ want to promote any Google service anymore, for various reasons.
191
+
192
+ Do keep in mind that responding to emails may take some time, depending on
193
+ the amount of work I may have at that moment.
194
+
195
+ In 2022 rubygems.org decided to make 2FA mandatory for every gem owner:
196
+ see https://blog.rubygems.org/2022/06/13/making-packages-more-secure.html
197
+
198
+ As I can not use 2FA, for reasons I will skip explaining here (see
199
+ various github issue discussions in the past), this effectively means that
200
+ Betty Li and others who run the show at rubygems.org will perma-ban me
201
+ from using rubygems as a developer.
202
+
203
+ As I disagree with that decision completely, this will mean that all my
204
+ gems will be removed from rubygems.org prior to that sunset date, e. g.
205
+ before they permanently lock me out from the code that I used
206
+ to maintain. It is pointless to want to discuss this with them anymore -
207
+ they have made up their minds and decided that you can only use
208
+ the code if 2FA is in place, even though the code itself works just
209
+ fine. If you don't use 2FA you are effectively locked out from your
210
+ own code; I consider this a malicious attack. See also how they limited
211
+ discussions to people with mandatory 2FA on the ruby-bugtracker, thus
212
+ banning everyone permanently without 2FA:
213
+
214
+ https://bugs.ruby-lang.org/issues/18800
215
+
216
+ Guess it may indeed be time to finally abandon ruby - not because
217
+ ruby is a bad language, but there are people now in charge who
218
+ really should not be part of ruby in the first place.
219
+
data/bin/dictionaries ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'dictionaries'
6
+
7
+ Dictionaries.parse_commandline(ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'dictionaries'
6
+
7
+ pp Dictionaries.return_unique_words_from_this_file(ARGV)
@@ -0,0 +1,85 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Dictionaries.
3
+ # =========================================================================== #
4
+ require 'dictionaries'
5
+ require 'roebe'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'dictionaries'
10
+ s.version = Dictionaries::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ DESCRIPTION = <<-EOF
14
+
15
+ This project is called dictionaries.
16
+
17
+ It used to be called ask_english_words but the name was changed towards
18
+ "dictionaries", when the focus became on dictionaries in general rather
19
+ than merely translations from and to the english language.
20
+
21
+ There are a total of #{Dictionaries.n_entries?} english words
22
+ registered, with the associated german translation. (It is
23
+ german primarily because that is my native language, but in
24
+ principle this project could be extended to include other
25
+ languages as well. You only need to add a yaml file containing
26
+ the key-value pairs.)
27
+
28
+ If you need a more comprehensive dictionary, I can recommend
29
+ the file de-en.txt that is part of the tu-chemnitz
30
+ distribution ( https://www-user.tu-chemnitz.de/~fri/ding/ ). That
31
+ file is really huge - about 20 MB.
32
+
33
+ In principle, the dictionaries project could be extended to
34
+ make use of that massive file instead. I will be thinking
35
+ about this for the time being (starting at July 2018).
36
+
37
+ EOF
38
+
39
+ s.summary = DESCRIPTION
40
+ s.description = DESCRIPTION
41
+
42
+ # ========================================================================= #
43
+ # Show this message when a user installs this project.
44
+ # ========================================================================= #
45
+ s.post_install_message = <<-EOF
46
+
47
+ This project can ask or translate english or italian words (or words
48
+ from any other language, as long as a .yml file is supplied that
49
+ contains these key-value pair entries).
50
+
51
+ This project is probably not very useful for other people, but it helps
52
+ me to improve my knowledge about the english or italian language or
53
+ any other language.
54
+
55
+ For more information, have a look at the main README.md file, which
56
+ can also be found on the hompage of this gem at rubygems.org, on
57
+ the bottom right side (see https://www.rubydoc.info/gems/dictionaries/ ).
58
+
59
+ EOF
60
+
61
+ s.extra_rdoc_files = %w()
62
+
63
+ s.authors = ['Robert A. Heiler']
64
+ s.email = Roebe.email?
65
+ s.files = Dir['**/*']
66
+ # s.files << 'README.md'
67
+ # s.files << 'USAGE.md'
68
+ s.license = 'MIT'
69
+ s.homepage = 'https://www.rubydoc.info/gems/dictionaries/'
70
+
71
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
72
+ s.required_rubygems_version = '>= '+Gem::VERSION
73
+ s.rubygems_version = '>= '+Gem::VERSION
74
+
75
+ # ========================================================================= #
76
+ # External dependencies for the project:
77
+ # ========================================================================= #
78
+ s.add_dependency 'colours'
79
+ s.add_dependency 'generate_shell_completion'
80
+ s.add_dependency 'opn'
81
+ s.add_dependency 'open'
82
+ s.add_dependency 'save_file'
83
+ s.add_dependency 'xorg_buffer'
84
+
85
+ }
data/doc/README.gen ADDED
@@ -0,0 +1,176 @@
1
+ ADD_RUBY_BADGE
2
+ ADD_TIME_STAMP
3
+
4
+ ## Environment variable to use a specific yaml file
5
+
6
+ You can use an <b>environment variable</b> to denote the default
7
+ yaml file in use. This allows you to use your own yaml file
8
+ format, rather than the yaml files that are distributed with
9
+ this gem.
10
+
11
+ The name of that environment variable must be <b>DICTIONARIES_FILE</b>.
12
+ It shall point to your yaml file that holds the key-value pairs.
13
+
14
+ For example, if your file is at /opt/czech.yml, then
15
+ DICTIONARIES_FILE should point at that location.
16
+
17
+ In bash, this may be equivalent to:
18
+
19
+ export DICTIONARIES_FILE=/opt/czech.yml
20
+
21
+ Note that in the long run, the dictionaries gem could be extended
22
+ with these yaml files - or allow means to download these files
23
+ over the www. But before we can do so, let's aim for at the least
24
+ 100 words in such a file before we would consider distributing
25
+ it or offering means to distribute said file.
26
+
27
+ ## Difficult english sentences
28
+
29
+ English is not the most difficult language in the world, but when it
30
+ comes to proper pronounciation of words, english can be surprisingly
31
+ difficult.
32
+
33
+ This subsection may keep a listing of sentences that, for one reason
34
+ or the other, can be somewhat difficult to **read out aloud** without
35
+ mistake, on a first try. It is just a fun-subsection, not meant to be
36
+ taken too seriously; and it is quite subjective.
37
+
38
+ Without any further ado, here comes a listing of sentences that may
39
+ be difficult to pronounce properly so:
40
+
41
+ I would like to distribute something.
42
+
43
+ ## Obtaining all translations into german for a given english word
44
+
45
+ Since as of **November 2020** the following API exists:
46
+
47
+ Dictionaries.return_array_of_translated_words_from_online_leo('cat')
48
+ Dictionaries.return_array_of_translated_words_from_online_leo('dog')
49
+ Dictionaries.return_array_of_translated_words_from_online_leo('human')
50
+
51
+ This will return an Array of german names. It does not work 100% perfectly
52
+ as it is based on a regex; and using a regex to parse HTML is never a
53
+ trivial way. But if you just want to get the first entry, just call
54
+ .first on it, and in most cases this is the best, most likely
55
+ translation available.
56
+
57
+ The regex has to find matches to entries such as the following one:
58
+
59
+ </repr><words><word>der Jazzfan</word></words>
60
+
61
+ Anyone to come up with a more accurate regex is welcome to share it. :)
62
+
63
+ This functionality was specifically necessary because I needed to
64
+ use this in the ruby-gtk bindings for this project.
65
+
66
+ ## Dictionaries.return_unique_words_from_this_file
67
+
68
+ This method will return all words that are presently not registered
69
+ in the english dictionary.
70
+
71
+ The idea here is for me to slowly add more english words into the
72
+ yaml file. I won't add every english word that exists, but I will
73
+ try to aim for a seizable number in the long run, such as
74
+ 5000 english words - already halfway there. \o/
75
+
76
+ ## GUI component
77
+
78
+ The **GUI component** of the dictionaries gem defaults to
79
+ **GTK3** finally. It is not a very advanced GUI, though.
80
+
81
+ First, install the gtk3 gem:
82
+
83
+ gem install gtk3
84
+
85
+ Then install the gtk_paradise project:
86
+
87
+ gem install gtk_paradise
88
+
89
+ Now you should be able to start the GUI component if the above
90
+ has worked:
91
+
92
+ dictionaries --gui
93
+
94
+ See also the help options.
95
+
96
+ dictionaries --help
97
+
98
+ You may need to install some .h files if you use a specific
99
+ Linux distribution; look at the relevant -dev packages for
100
+ this. Or just compile from source. :)
101
+
102
+ The current version of ruby-gtk3 in October 2021 looks like
103
+ this:
104
+
105
+ <img src="https://i.imgur.com/K430Kae.png" style="margin-left: 2em">
106
+
107
+ Yes, this isn't very pretty; I just wanted to focus a bit on
108
+ the functionality. Tons of things are missing, such as
109
+ switching to other .yml files from within the GUI itself.
110
+ I just wanted to showcase a demo - the convert from
111
+ english-to-german functionality is working, though, so
112
+ the GUI is functional, even if not super-pretty.
113
+
114
+ In **February 2022** this was improved a little bit. It's still
115
+ not extremely pretty, but you can see a few small improvements.
116
+ In the long run I will add functionality to switch between
117
+ different .yml files (thus, different dictionaries, such as
118
+ english, italian and so forth) - but it is a hobby project.
119
+ I won't have enough time to add all dictionaries into this
120
+ project as-is. I will, however had, add the possibility to
121
+ load custom .yml files and other formats in the long run,
122
+ so others can adapt the project to suit their needs.
123
+
124
+ <img src="https://i.imgur.com/ChFJmfo.png" style="margin-left: 2em">
125
+
126
+ ## sinatra
127
+
128
+ To start the sinatra interface of the dictionaries gem, do:
129
+
130
+ dictionaries --sinatra
131
+
132
+ You can then visit it on the localhost and it may look like
133
+ this:
134
+
135
+ <img src="https://i.imgur.com/uhzbXZ1.png" style="margin: 0.5em; margin-left: 2em">
136
+
137
+ You can then input an english word into the form, or the
138
+ URL area in your browser. If this word is registered in
139
+ the .yml file then the following result can be seen:
140
+
141
+ <img src="https://i.imgur.com/i1RqRmr.png" style="margin: 0.5em; margin-left: 2em">
142
+
143
+ This is really just very basic - I wanted to show the
144
+ functionality. You may have to adapt the code if you
145
+ have a more realistic use case, so consider the images
146
+ above just as examples of how this <b>could</b> be
147
+ used in a website.
148
+
149
+ ## Generating a .pdf file containing the translations
150
+
151
+ Since as of <b>July 2022</b> you can generate a .pdf file
152
+ with all the translated words. This functionality depends
153
+ on the <b>prawn</b> gem right now, so make sure that
154
+ this gem is installed before invoking the ruby code
155
+ that generates the .pdf file.
156
+
157
+ The toplevel API for creating the .pdf file is as follows:
158
+
159
+ Dictionaries.generate_pdf_file
160
+
161
+ ## Licence
162
+
163
+ Until the 17th of October 2019, this project was using the **GPLv2
164
+ licence** (no later clause).
165
+
166
+ However had, I believe that the GPLv2 licence is not great for
167
+ a project that focuses on existing words in **real languages**,
168
+ aka dictionaries. Thus, I have decided to change the licence into
169
+ the **MIT licence** on that day (**17.11.2019**, in dd.mm.yyyy notation).
170
+
171
+ So the gem is now MIT licenced. There may be dragons! \o/
172
+
173
+ For a description of that licence, see
174
+ https://opensource.org/licenses/MIT.
175
+
176
+ ADD_CONTACT_INFORMATION
data/doc/todo/todo.md ADDED
@@ -0,0 +1,5 @@
1
+ - Add italian, and GUI support for that.
2
+
3
+ - AND add stats to the main README, via macro or so,
4
+ aka "contains 5000 english words, 3000 italian
5
+ words" or so. Split by <br> I think.
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Dictionaries::AskEnglishWord
6
+ #
7
+ # Use this class to ask a random english word.
8
+ #
9
+ # There are two ways to use this class:
10
+ #
11
+ # - Pass in an optional argument to it, which we will use to query this
12
+ # word from the database.
13
+ #
14
+ # - Pass nothing to it, in which case we load a random entry.
15
+ #
16
+ # Specific usage examples:
17
+ #
18
+ # require 'dictionaries'
19
+ # Dictionaries::AskEnglishWord.new
20
+ # Dictionaries.ask_english_word
21
+ #
22
+ # =========================================================================== #
23
+ # require 'dictionaries/ask_english_word.rb'
24
+ # Dictionaries.path_to_the_english_file?
25
+ # =========================================================================== #
26
+ require 'dictionaries/class/ask_word_from_dictionary.rb'
27
+
28
+ module Dictionaries
29
+
30
+ class AskEnglishWord < AskWordFromDictionary
31
+
32
+ # ========================================================================= #
33
+ # === DATA
34
+ # ========================================================================= #
35
+ if defined?(DATA) == 'constant'
36
+ if DATA.respond_to? :read
37
+ _ = DATA.read
38
+ else
39
+ e 'DATA does not respond to :read'
40
+ end
41
+ else
42
+ _ = ''
43
+ end
44
+
45
+ # ========================================================================= #
46
+ # === DEFAULT_DELAY
47
+ # ========================================================================= #
48
+ if _.to_s.empty? # Next, define the default delay.
49
+ DEFAULT_DELAY = 2.2 # How long to wait before asking a question.
50
+ else
51
+ _ = _.first if _.is_a? Array
52
+ DEFAULT_DELAY = _.strip.to_f
53
+ end
54
+
55
+ # ========================================================================= #
56
+ # === AskEnglishWord::THIS_FILE
57
+ # ========================================================================= #
58
+ THIS_FILE = THIS_FILE_HERE = __FILE__.to_s
59
+
60
+ unless ENV['DICTIONARIES_FILE'] and File.exist?(ENV['DICTIONARIES_FILE'])
61
+ Dictionaries.set_main_file(THIS_FILE) # Assign it at once.
62
+ end
63
+
64
+ # ========================================================================= #
65
+ # === initialize
66
+ # ========================================================================= #
67
+ def initialize(
68
+ commandline_arguments = ARGV
69
+ )
70
+ super(commandline_arguments, self.class.main_file?)
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === Dictionaries::AskEnglishWord.main_file?
75
+ # ========================================================================= #
76
+ def self.main_file?
77
+ Dictionaries.main_file?
78
+ end
79
+
80
+ # ========================================================================= #
81
+ # === Dictionaries::AskEnglishWord.dataset?
82
+ #
83
+ # Note that this method will load the dataset from the main file anew
84
+ # whenever you invoke it.
85
+ # ========================================================================= #
86
+ def self.dataset?
87
+ YAML.load_file(self.main_file?)
88
+ end
89
+
90
+ # ========================================================================= #
91
+ # === Dictionaries::AskEnglishWord.n_entries?
92
+ #
93
+ # Feedback how many entries are registered.
94
+ # ========================================================================= #
95
+ def self.n_entries?
96
+ _ = dataset?
97
+ n_entries = _.size
98
+ return n_entries
99
+ end; self.instance_eval { alias n_questions? n_entries? } # === AskEnglishWord.n_questions?
100
+
101
+ # ========================================================================= #
102
+ # === Dictionaries::AskEnglishWord[]
103
+ # ========================================================================= #
104
+ def self.[](i)
105
+ self.new(i)
106
+ end
107
+
108
+ end
109
+
110
+ # =========================================================================== #
111
+ # === Dictionaries.ask_english_word
112
+ # =========================================================================== #
113
+ def self.ask_english_word
114
+ AskEnglishWord.new
115
+ end
116
+
117
+ # =========================================================================== #
118
+ # === Dictionaries.path_to_the_english_file?
119
+ #
120
+ # This method may return a String, as a file path, such as
121
+ # "/home/Programs/Ruby/2.7.2/lib/ruby/site_ruby/2.7.0/dictionaries/yaml/english.yml".
122
+ # =========================================================================== #
123
+ def self.path_to_the_english_file?
124
+ Dictionaries.main_file?
125
+ end
126
+
127
+ # =========================================================================== #
128
+ # === Dictionaries.n_entries?
129
+ # =========================================================================== #
130
+ def self.n_entries?
131
+ ::Dictionaries::AskEnglishWord.n_entries?
132
+ end
133
+
134
+ end
135
+
136
+ if __FILE__ == $PROGRAM_NAME
137
+ Dictionaries::AskEnglishWord.new(ARGV)
138
+ end # askeng
139
+ # This is the delay to use for this class.
140
+ __END__
141
+ 1.8