LittleWeasel 3.0.4 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.reek.yml +17 -0
  4. data/.rspec +4 -2
  5. data/.rubocop.yml +187 -0
  6. data/.ruby-version +1 -1
  7. data/.yardopts +2 -0
  8. data/Gemfile +3 -1
  9. data/LittleWeasel.gemspec +31 -18
  10. data/README.md +408 -42
  11. data/Rakefile +296 -3
  12. data/lib/LittleWeasel.rb +5 -184
  13. data/lib/LittleWeasel/block_results.rb +81 -0
  14. data/lib/LittleWeasel/configure.rb +98 -0
  15. data/lib/LittleWeasel/dictionary.rb +125 -0
  16. data/lib/LittleWeasel/dictionary_key.rb +48 -0
  17. data/lib/LittleWeasel/dictionary_manager.rb +85 -0
  18. data/lib/LittleWeasel/errors/dictionary_file_already_loaded_error.rb +9 -0
  19. data/lib/LittleWeasel/errors/dictionary_file_empty_error.rb +8 -0
  20. data/lib/LittleWeasel/errors/dictionary_file_not_found_error.rb +8 -0
  21. data/lib/LittleWeasel/errors/dictionary_file_too_large_error.rb +16 -0
  22. data/lib/LittleWeasel/errors/language_required_error.rb +8 -0
  23. data/lib/LittleWeasel/errors/must_override_error.rb +8 -0
  24. data/lib/LittleWeasel/filters/en_us/currency_filter.rb +19 -0
  25. data/lib/LittleWeasel/filters/en_us/numeric_filter.rb +19 -0
  26. data/lib/LittleWeasel/filters/en_us/single_character_word_filter.rb +21 -0
  27. data/lib/LittleWeasel/filters/word_filter.rb +59 -0
  28. data/lib/LittleWeasel/filters/word_filter_managable.rb +80 -0
  29. data/lib/LittleWeasel/filters/word_filter_validatable.rb +31 -0
  30. data/lib/LittleWeasel/filters/word_filterable.rb +19 -0
  31. data/lib/LittleWeasel/filters/word_filters_validatable.rb +29 -0
  32. data/lib/LittleWeasel/metadata/dictionary_metadata.rb +145 -0
  33. data/lib/LittleWeasel/metadata/invalid_words_metadata.rb +134 -0
  34. data/lib/LittleWeasel/metadata/invalid_words_service_results.rb +45 -0
  35. data/lib/LittleWeasel/metadata/metadata_observable_validatable.rb +22 -0
  36. data/lib/LittleWeasel/metadata/metadata_observerable.rb +90 -0
  37. data/lib/LittleWeasel/metadata/metadatable.rb +136 -0
  38. data/lib/LittleWeasel/modules/class_name_to_symbol.rb +26 -0
  39. data/lib/LittleWeasel/modules/configurable.rb +26 -0
  40. data/lib/LittleWeasel/modules/deep_dup.rb +11 -0
  41. data/lib/LittleWeasel/modules/dictionary_cache_keys.rb +34 -0
  42. data/lib/LittleWeasel/modules/dictionary_cache_servicable.rb +26 -0
  43. data/lib/LittleWeasel/modules/dictionary_cache_validatable.rb +20 -0
  44. data/lib/LittleWeasel/modules/dictionary_creator_servicable.rb +27 -0
  45. data/lib/LittleWeasel/modules/dictionary_file_loader.rb +67 -0
  46. data/lib/LittleWeasel/modules/dictionary_key_validatable.rb +19 -0
  47. data/lib/LittleWeasel/modules/dictionary_keyable.rb +24 -0
  48. data/lib/LittleWeasel/modules/dictionary_loader_servicable.rb +27 -0
  49. data/lib/LittleWeasel/modules/dictionary_metadata_servicable.rb +29 -0
  50. data/lib/LittleWeasel/modules/dictionary_metadata_validatable.rb +17 -0
  51. data/lib/LittleWeasel/modules/dictionary_sourceable.rb +26 -0
  52. data/lib/LittleWeasel/modules/dictionary_validatable.rb +30 -0
  53. data/lib/LittleWeasel/modules/language.rb +23 -0
  54. data/lib/LittleWeasel/modules/language_validatable.rb +16 -0
  55. data/lib/LittleWeasel/modules/locale.rb +40 -0
  56. data/lib/LittleWeasel/modules/order_validatable.rb +18 -0
  57. data/lib/LittleWeasel/modules/orderable.rb +17 -0
  58. data/lib/LittleWeasel/modules/region.rb +23 -0
  59. data/lib/LittleWeasel/modules/region_validatable.rb +16 -0
  60. data/lib/LittleWeasel/modules/tag_validatable.rb +16 -0
  61. data/lib/LittleWeasel/modules/taggable.rb +31 -0
  62. data/lib/LittleWeasel/modules/word_results_validatable.rb +28 -0
  63. data/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor.rb +22 -0
  64. data/lib/LittleWeasel/preprocessors/preprocessed_word.rb +28 -0
  65. data/lib/LittleWeasel/preprocessors/preprocessed_word_validatable.rb +55 -0
  66. data/lib/LittleWeasel/preprocessors/preprocessed_words.rb +55 -0
  67. data/lib/LittleWeasel/preprocessors/preprocessed_words_validatable.rb +27 -0
  68. data/lib/LittleWeasel/preprocessors/word_preprocessable.rb +19 -0
  69. data/lib/LittleWeasel/preprocessors/word_preprocessor.rb +122 -0
  70. data/lib/LittleWeasel/preprocessors/word_preprocessor_managable.rb +114 -0
  71. data/lib/LittleWeasel/preprocessors/word_preprocessor_validatable.rb +40 -0
  72. data/lib/LittleWeasel/preprocessors/word_preprocessors_validatable.rb +24 -0
  73. data/lib/LittleWeasel/services/dictionary_cache_service.rb +262 -0
  74. data/lib/LittleWeasel/services/dictionary_creator_service.rb +94 -0
  75. data/lib/LittleWeasel/services/dictionary_file_loader_service.rb +37 -0
  76. data/lib/LittleWeasel/services/dictionary_killer_service.rb +35 -0
  77. data/lib/LittleWeasel/services/dictionary_loader_service.rb +59 -0
  78. data/lib/LittleWeasel/services/dictionary_metadata_service.rb +114 -0
  79. data/lib/LittleWeasel/services/invalid_words_service.rb +59 -0
  80. data/lib/LittleWeasel/version.rb +3 -1
  81. data/lib/LittleWeasel/word_results.rb +146 -0
  82. data/spec/factories/dictionary.rb +43 -0
  83. data/spec/factories/dictionary_cache_service.rb +95 -0
  84. data/spec/factories/dictionary_creator_service.rb +16 -0
  85. data/spec/factories/dictionary_file_loader_service.rb +13 -0
  86. data/spec/factories/dictionary_hash.rb +39 -0
  87. data/spec/factories/dictionary_key.rb +14 -0
  88. data/spec/factories/dictionary_killer_service.rb +14 -0
  89. data/spec/factories/dictionary_loader_service.rb +14 -0
  90. data/spec/factories/dictionary_manager.rb +10 -0
  91. data/spec/factories/dictionary_metadata.rb +16 -0
  92. data/spec/factories/dictionary_metadata_service.rb +16 -0
  93. data/spec/factories/numeric_filter.rb +12 -0
  94. data/spec/factories/preprocessed_word.rb +16 -0
  95. data/spec/factories/preprocessed_words.rb +41 -0
  96. data/spec/factories/single_character_word_filter.rb +12 -0
  97. data/spec/factories/word_results.rb +16 -0
  98. data/spec/lib/LittleWeasel/block_results_spec.rb +248 -0
  99. data/spec/lib/LittleWeasel/configure_spec.rb +74 -0
  100. data/spec/lib/LittleWeasel/dictionary_key_spec.rb +118 -0
  101. data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +116 -0
  102. data/spec/lib/LittleWeasel/dictionary_spec.rb +289 -0
  103. data/spec/lib/LittleWeasel/filters/en_us/currency_filter_spec.rb +80 -0
  104. data/spec/lib/LittleWeasel/filters/en_us/numeric_filter_spec.rb +66 -0
  105. data/spec/lib/LittleWeasel/filters/en_us/single_character_word_filter_spec.rb +58 -0
  106. data/spec/lib/LittleWeasel/filters/word_filter_managable_spec.rb +180 -0
  107. data/spec/lib/LittleWeasel/filters/word_filter_spec.rb +151 -0
  108. data/spec/lib/LittleWeasel/filters/word_filter_validatable_spec.rb +94 -0
  109. data/spec/lib/LittleWeasel/filters/word_filters_validatable_spec.rb +48 -0
  110. data/spec/lib/LittleWeasel/integraton_tests/dictionary_integration_spec.rb +201 -0
  111. data/spec/lib/LittleWeasel/metadata/dictionary_creator_servicable_spec.rb +54 -0
  112. data/spec/lib/LittleWeasel/metadata/dictionary_metadata_spec.rb +209 -0
  113. data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +155 -0
  114. data/spec/lib/LittleWeasel/metadata/metadata_observerable_spec.rb +31 -0
  115. data/spec/lib/LittleWeasel/metadata/metadatable_spec.rb +35 -0
  116. data/spec/lib/LittleWeasel/modules/class_name_to_symbol_spec.rb +21 -0
  117. data/spec/lib/LittleWeasel/modules/dictionary_file_loader_spec.rb +125 -0
  118. data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +44 -0
  119. data/spec/lib/LittleWeasel/modules/language_spec.rb +52 -0
  120. data/spec/lib/LittleWeasel/modules/locale_spec.rb +140 -0
  121. data/spec/lib/LittleWeasel/modules/region_spec.rb +52 -0
  122. data/spec/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor_spec.rb +34 -0
  123. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_spec.rb +105 -0
  124. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_validatable_spec.rb +143 -0
  125. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_spec.rb +77 -0
  126. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_validatable_spec.rb +58 -0
  127. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +216 -0
  128. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +175 -0
  129. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_validatable_spec.rb +109 -0
  130. data/spec/lib/LittleWeasel/preprocessors/word_preprocessors_validatable_spec.rb +49 -0
  131. data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +444 -0
  132. data/spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb +119 -0
  133. data/spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb +71 -0
  134. data/spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb +50 -0
  135. data/spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb +279 -0
  136. data/spec/lib/LittleWeasel/word_results_spec.rb +275 -0
  137. data/spec/lib/LittleWeasel/workflow/workflow_spec.rb +20 -0
  138. data/spec/spec_helper.rb +117 -6
  139. data/spec/support/factory_bot.rb +15 -0
  140. data/spec/support/file_helpers.rb +32 -0
  141. data/spec/support/files/empty-dictionary.txt +0 -0
  142. data/{lib/dictionary → spec/support/files/en-US-big.txt} +262156 -31488
  143. data/spec/support/files/en-US-tagged.txt +26 -0
  144. data/spec/support/files/en-US.txt +26 -0
  145. data/spec/support/files/en.txt +26 -0
  146. data/spec/support/files/es-ES.txt +27 -0
  147. data/spec/support/files/es.txt +27 -0
  148. data/spec/support/general_helpers.rb +68 -0
  149. data/spec/support/shared_contexts.rb +108 -0
  150. data/spec/support/shared_examples.rb +105 -0
  151. metadata +408 -65
  152. data/spec/checker/checker_spec.rb +0 -286
@@ -1,286 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe 'LittleWeasel Inline Options Tests' do
4
-
5
- before do
6
- @spell = LittleWeasel::Checker.instance
7
- end
8
-
9
- it 'should create a LittleWeasel object' do
10
- @spell.should be_an_instance_of LittleWeasel::Checker
11
- end
12
-
13
- it 'should return true for valid word' do
14
- @spell.exists?('apple').should == true
15
- end
16
-
17
- it 'should return false for valid word with leading spaces by default' do
18
- @spell.exists?(' apple').should == false
19
- end
20
-
21
- it 'should return false for valid word with trailing spaces by default' do
22
- @spell.exists?('apple ').should == false
23
- end
24
-
25
- it 'should return false for valid word with leading and trailing spaces by default' do
26
- @spell.exists?(' apple ').should == false
27
- end
28
-
29
- it 'should return false for invalid word' do
30
- @spell.exists?('appel').should == false
31
- end
32
-
33
- it 'should return false for nil' do
34
- @spell.exists?(nil).should == false
35
- end
36
-
37
- it 'should return false for non-String' do
38
- @spell.exists?(:word).should == false
39
- end
40
-
41
- it 'should return true if option exclude_alphabet is false, and word is a letter' do
42
- @spell.options = {exclude_alphabet: false}
43
- @spell.exists?('x').should == true
44
- @spell.exists?('X').should == true
45
- end
46
-
47
- it 'should return false if option exclude_alphabet is true, and word is a letter' do
48
- @spell.options = {exclude_alphabet: true}
49
- @spell.exists?('x').should == false
50
- @spell.exists?('X').should == false
51
- end
52
-
53
- it 'should use options passed to exist? 1' do
54
- @spell.options = {exclude_alphabet: false}
55
- @spell.exists?('h', {exclude_alphabet: true}).should == false
56
- end
57
-
58
- it 'should use options passed to exist? 2' do
59
- @spell.options = {exclude_alphabet: true}
60
- @spell.exists?('h', {exclude_alphabet: false}).should == true
61
- end
62
-
63
- it 'should return false for valid word with leading spaces' do
64
- @spell.exists?(' apple', {strip_whitespace: false}).should == false
65
- end
66
-
67
- it 'should return false for valid word with trailing spaces' do
68
- @spell.exists?('apple ', {strip_whitespace: false}).should == false
69
- end
70
-
71
- it 'should return false for valid word with leading and trailing spaces' do
72
- @spell.exists?(' apple ', {strip_whitespace: false}).should == false
73
- end
74
-
75
- it 'should return true for valid word with leading spaces' do
76
- @spell.exists?(' apple', {strip_whitespace: true}).should == true
77
- end
78
-
79
- it 'should return true for valid word with trailing spaces' do
80
- @spell.exists?('apple ', {strip_whitespace: true}).should == true
81
- end
82
-
83
- it 'should return true for valid word with leading and trailing spaces' do
84
- @spell.exists?(' apple ', {strip_whitespace: true}).should == true
85
- end
86
-
87
- # TODO: Profile
88
- it "shouldn't take forever to find a lot of words" do
89
- words = %w{ all bad cap dad eat fad glad had inch jump kind lend monster on put quiet run sad tape under vector was xenophobe yes zebra }
90
-
91
- words *= 100
92
-
93
- words.each { |word| @spell.exists?(word).should == true }
94
- end
95
-
96
- it 'should return true if option ignore_numeric is true, and word is a number' do
97
- @spell.options = {ignore_numeric: true}
98
- @spell.exists?('1').should == true
99
- @spell.exists?('-1').should == true
100
- @spell.exists?('1.0').should == true
101
- @spell.exists?('-1.0').should == true
102
- end
103
-
104
- it 'should return false if option ignore_numeric is false, and word is a number' do
105
- @spell.options = {ignore_numeric: false}
106
- @spell.exists?('1').should == false
107
- @spell.exists?('-1').should == false
108
- @spell.exists?('1.0').should == false
109
- @spell.exists?('-1.0').should == false
110
- end
111
-
112
- it 'should not alter the original input' do
113
- expect = " Hello! "
114
- actual = expect.dup
115
- @spell.exists?(actual, {strip_whitespace: false})
116
- actual.should == expect
117
- end
118
-
119
- end
120
-
121
- describe 'LittleWeasel Global Options Tests' do
122
-
123
- before (:each) do
124
- @spell = LittleWeasel::Checker.instance
125
- @spell.options = {exclude_alphabet: true, strip_whitespace: true, ignore_numeric: true}
126
- end
127
-
128
- it 'should create a LittleWeasel object' do
129
- @spell.should be_an_instance_of LittleWeasel::Checker
130
- end
131
-
132
- it 'should return true for valid word' do
133
- @spell.exists?('apple').should == true
134
- end
135
-
136
- it 'should return false for invalid word' do
137
- @spell.exists?('appel').should == false
138
- end
139
-
140
- it 'should return false for nil' do
141
- @spell.exists?(nil).should == false
142
- end
143
-
144
- it 'should return false for non-String' do
145
- @spell.exists?(:word).should == false
146
- end
147
-
148
- it 'should return false if option exclude_alphabet is true, and word is a letter' do
149
- @spell.exists?('x').should == false
150
- @spell.exists?('X').should == false
151
- end
152
-
153
- it 'should use options passed to exist? but not override global options' do
154
- @spell.exists?('h', {exclude_alphabet: false}).should == true
155
- @spell.exists?('h').should == false
156
-
157
- @spell.exists?(' h ', {exclude_alphabet: false, strip_whitespace: true}).should == true
158
- @spell.exists?(' h ').should == false
159
-
160
- @spell.exists?('1', {ignore_numeric: false}).should == false
161
- @spell.exists?('1').should == true
162
- end
163
-
164
- it 'should return true for valid word with leading spaces' do
165
- @spell.exists?(' apple').should == true
166
- end
167
-
168
- it 'should return true for valid word with trailing spaces' do
169
- @spell.exists?('apple ').should == true
170
- end
171
-
172
- it 'should return true for valid word with leading and trailing spaces' do
173
- @spell.exists?(' apple ').should == true
174
- end
175
-
176
- it 'should return true if word is a number' do
177
- @spell.exists?('1').should == true
178
- @spell.exists?('-1').should == true
179
- @spell.exists?('1.0').should == true
180
- @spell.exists?('-1.0').should == true
181
- end
182
-
183
- it 'should return false if word is a number' do
184
- @spell.options = {ignore_numeric: false}
185
- @spell.exists?('1').should == false
186
- @spell.exists?('-1').should == false
187
- @spell.exists?('1.0').should == false
188
- @spell.exists?('-1.0').should == false
189
- end
190
-
191
- it 'should not alter the original input' do
192
- expect = "Hello!"
193
- actual = expect.dup
194
- @spell.exists?(actual)
195
- actual.should == expect
196
- end
197
-
198
- end
199
-
200
- describe 'LittleWeasel Word Block Tests' do
201
-
202
- before (:all) do
203
- @spell = LittleWeasel::Checker.instance
204
- @spell.options = {exclude_alphabet: true, strip_whitespace: true}
205
- end
206
-
207
- it 'should return true for valid words' do
208
- @spell.exists?('apple sauce').should == true
209
- end
210
-
211
- it 'should return false for invalid words' do
212
- @spell.exists?('appel sauce').should == false
213
- end
214
-
215
- it 'should return true for valid words with leading spaces' do
216
- @spell.exists?(' apple sauce').should == true
217
- end
218
-
219
- it 'should return true for valid words with trailing spaces' do
220
- @spell.exists?('apple sauce ').should == true
221
- end
222
-
223
- it 'should return true for valid words with leading and trailing spaces' do
224
- @spell.exists?(' apple sauce ').should == true
225
- end
226
-
227
- it 'should return true for valid words split across \n and \r\n' do
228
- @spell.exists?("apple\r\n\n\nsauce is great\r\n").should == true
229
- end
230
-
231
- it 'should return true for valid words separated by \t' do
232
- @spell.exists?("\tapple\t\t\tsauce is great\t").should == true
233
- end
234
-
235
- it 'should return true for valid words that are repeated' do
236
- @spell.exists?(' are you bad are you bad are you bad ').should == true
237
- end
238
-
239
- it 'should return true for valid words separated by non-alpha chars' do
240
- @spell.exists?("hello, mister; did I \'mention\'' that lemon cake is \"great?\" It's just wonderful!").should == true
241
- end
242
-
243
- it 'should return true for valid pluralized words' do
244
- @spell.exists?('Apples and peaches are great! Some people are good, each person is a people.').should == true
245
- end
246
-
247
- it 'should return true for valid words' do
248
- @spell.exists?('Hell o').should == true
249
- end
250
-
251
- it 'should not alter the original input' do
252
- expect = "This 'cool' string should not be altered in any way, so I'm 100.00% confident!"
253
- actual = expect.dup
254
- @spell.exists?(actual)
255
- actual.should == expect
256
- end
257
-
258
- end
259
-
260
- describe "option single_word_mode" do
261
- before (:all) do
262
- @spell = LittleWeasel::Checker.instance
263
- #@spell.options = {exclude_alphabet: true, strip_whitespace: true}
264
- end
265
-
266
- describe "set globally" do
267
- it 'should return true for a valid word block by default' do
268
- @spell.exists?('I love apple pie').should == true
269
- end
270
-
271
- it 'should return false for a valid word block if set to true' do
272
- @spell.options = { single_word_mode: true }
273
- @spell.exists?('I love apple pie').should == false
274
- end
275
- end
276
-
277
- describe "set inline" do
278
- it 'should return false for a valid word block if set to true' do
279
- @spell.exists?('I hate ice cream', single_word_mode: true).should == false
280
- end
281
-
282
- it 'should return true for a valid word block if set to false' do
283
- @spell.exists?('I had a hard day', single_word_mode: false).should == true
284
- end
285
- end
286
- end