LittleWeasel 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.idea/.rakeTasks +1 -1
  4. data/.idea/LittleWeasel.iml +5 -18
  5. data/.idea/workspace.xml +198 -109
  6. data/.reek.yml +17 -0
  7. data/.rspec +4 -2
  8. data/.rubocop.yml +187 -0
  9. data/.ruby-version +1 -0
  10. data/.yardopts +2 -0
  11. data/CHANGELOG.md +16 -0
  12. data/Gemfile +3 -1
  13. data/LittleWeasel.gemspec +31 -18
  14. data/README.md +408 -42
  15. data/Rakefile +296 -3
  16. data/lib/LittleWeasel.rb +5 -171
  17. data/lib/LittleWeasel/block_results.rb +81 -0
  18. data/lib/LittleWeasel/configure.rb +98 -0
  19. data/lib/LittleWeasel/dictionary.rb +125 -0
  20. data/lib/LittleWeasel/dictionary_key.rb +48 -0
  21. data/lib/LittleWeasel/dictionary_manager.rb +85 -0
  22. data/lib/LittleWeasel/errors/dictionary_file_already_loaded_error.rb +9 -0
  23. data/lib/LittleWeasel/errors/dictionary_file_empty_error.rb +8 -0
  24. data/lib/LittleWeasel/errors/dictionary_file_not_found_error.rb +8 -0
  25. data/lib/LittleWeasel/errors/dictionary_file_too_large_error.rb +16 -0
  26. data/lib/LittleWeasel/errors/language_required_error.rb +8 -0
  27. data/lib/LittleWeasel/errors/must_override_error.rb +8 -0
  28. data/lib/LittleWeasel/filters/en_us/currency_filter.rb +19 -0
  29. data/lib/LittleWeasel/filters/en_us/numeric_filter.rb +19 -0
  30. data/lib/LittleWeasel/filters/en_us/single_character_word_filter.rb +21 -0
  31. data/lib/LittleWeasel/filters/word_filter.rb +59 -0
  32. data/lib/LittleWeasel/filters/word_filter_managable.rb +80 -0
  33. data/lib/LittleWeasel/filters/word_filter_validatable.rb +31 -0
  34. data/lib/LittleWeasel/filters/word_filterable.rb +19 -0
  35. data/lib/LittleWeasel/filters/word_filters_validatable.rb +29 -0
  36. data/lib/LittleWeasel/metadata/dictionary_metadata.rb +145 -0
  37. data/lib/LittleWeasel/metadata/invalid_words_metadata.rb +134 -0
  38. data/lib/LittleWeasel/metadata/invalid_words_service_results.rb +45 -0
  39. data/lib/LittleWeasel/metadata/metadata_observable_validatable.rb +22 -0
  40. data/lib/LittleWeasel/metadata/metadata_observerable.rb +90 -0
  41. data/lib/LittleWeasel/metadata/metadatable.rb +136 -0
  42. data/lib/LittleWeasel/modules/class_name_to_symbol.rb +26 -0
  43. data/lib/LittleWeasel/modules/configurable.rb +26 -0
  44. data/lib/LittleWeasel/modules/deep_dup.rb +11 -0
  45. data/lib/LittleWeasel/modules/dictionary_cache_keys.rb +34 -0
  46. data/lib/LittleWeasel/modules/dictionary_cache_servicable.rb +26 -0
  47. data/lib/LittleWeasel/modules/dictionary_cache_validatable.rb +20 -0
  48. data/lib/LittleWeasel/modules/dictionary_creator_servicable.rb +27 -0
  49. data/lib/LittleWeasel/modules/dictionary_file_loader.rb +67 -0
  50. data/lib/LittleWeasel/modules/dictionary_key_validatable.rb +19 -0
  51. data/lib/LittleWeasel/modules/dictionary_keyable.rb +24 -0
  52. data/lib/LittleWeasel/modules/dictionary_loader_servicable.rb +27 -0
  53. data/lib/LittleWeasel/modules/dictionary_metadata_servicable.rb +29 -0
  54. data/lib/LittleWeasel/modules/dictionary_metadata_validatable.rb +17 -0
  55. data/lib/LittleWeasel/modules/dictionary_sourceable.rb +26 -0
  56. data/lib/LittleWeasel/modules/dictionary_validatable.rb +30 -0
  57. data/lib/LittleWeasel/modules/language.rb +23 -0
  58. data/lib/LittleWeasel/modules/language_validatable.rb +16 -0
  59. data/lib/LittleWeasel/modules/locale.rb +40 -0
  60. data/lib/LittleWeasel/modules/order_validatable.rb +18 -0
  61. data/lib/LittleWeasel/modules/orderable.rb +17 -0
  62. data/lib/LittleWeasel/modules/region.rb +23 -0
  63. data/lib/LittleWeasel/modules/region_validatable.rb +16 -0
  64. data/lib/LittleWeasel/modules/tag_validatable.rb +16 -0
  65. data/lib/LittleWeasel/modules/taggable.rb +31 -0
  66. data/lib/LittleWeasel/modules/word_results_validatable.rb +28 -0
  67. data/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor.rb +22 -0
  68. data/lib/LittleWeasel/preprocessors/preprocessed_word.rb +28 -0
  69. data/lib/LittleWeasel/preprocessors/preprocessed_word_validatable.rb +55 -0
  70. data/lib/LittleWeasel/preprocessors/preprocessed_words.rb +55 -0
  71. data/lib/LittleWeasel/preprocessors/preprocessed_words_validatable.rb +27 -0
  72. data/lib/LittleWeasel/preprocessors/word_preprocessable.rb +19 -0
  73. data/lib/LittleWeasel/preprocessors/word_preprocessor.rb +122 -0
  74. data/lib/LittleWeasel/preprocessors/word_preprocessor_managable.rb +114 -0
  75. data/lib/LittleWeasel/preprocessors/word_preprocessor_validatable.rb +40 -0
  76. data/lib/LittleWeasel/preprocessors/word_preprocessors_validatable.rb +24 -0
  77. data/lib/LittleWeasel/services/dictionary_cache_service.rb +262 -0
  78. data/lib/LittleWeasel/services/dictionary_creator_service.rb +94 -0
  79. data/lib/LittleWeasel/services/dictionary_file_loader_service.rb +37 -0
  80. data/lib/LittleWeasel/services/dictionary_killer_service.rb +35 -0
  81. data/lib/LittleWeasel/services/dictionary_loader_service.rb +59 -0
  82. data/lib/LittleWeasel/services/dictionary_metadata_service.rb +114 -0
  83. data/lib/LittleWeasel/services/invalid_words_service.rb +59 -0
  84. data/lib/LittleWeasel/version.rb +3 -1
  85. data/lib/LittleWeasel/word_results.rb +146 -0
  86. data/spec/factories/dictionary.rb +43 -0
  87. data/spec/factories/dictionary_cache_service.rb +95 -0
  88. data/spec/factories/dictionary_creator_service.rb +16 -0
  89. data/spec/factories/dictionary_file_loader_service.rb +13 -0
  90. data/spec/factories/dictionary_hash.rb +39 -0
  91. data/spec/factories/dictionary_key.rb +14 -0
  92. data/spec/factories/dictionary_killer_service.rb +14 -0
  93. data/spec/factories/dictionary_loader_service.rb +14 -0
  94. data/spec/factories/dictionary_manager.rb +10 -0
  95. data/spec/factories/dictionary_metadata.rb +16 -0
  96. data/spec/factories/dictionary_metadata_service.rb +16 -0
  97. data/spec/factories/numeric_filter.rb +12 -0
  98. data/spec/factories/preprocessed_word.rb +16 -0
  99. data/spec/factories/preprocessed_words.rb +41 -0
  100. data/spec/factories/single_character_word_filter.rb +12 -0
  101. data/spec/factories/word_results.rb +16 -0
  102. data/spec/lib/LittleWeasel/block_results_spec.rb +248 -0
  103. data/spec/lib/LittleWeasel/configure_spec.rb +74 -0
  104. data/spec/lib/LittleWeasel/dictionary_key_spec.rb +118 -0
  105. data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +116 -0
  106. data/spec/lib/LittleWeasel/dictionary_spec.rb +289 -0
  107. data/spec/lib/LittleWeasel/filters/en_us/currency_filter_spec.rb +80 -0
  108. data/spec/lib/LittleWeasel/filters/en_us/numeric_filter_spec.rb +66 -0
  109. data/spec/lib/LittleWeasel/filters/en_us/single_character_word_filter_spec.rb +58 -0
  110. data/spec/lib/LittleWeasel/filters/word_filter_managable_spec.rb +180 -0
  111. data/spec/lib/LittleWeasel/filters/word_filter_spec.rb +151 -0
  112. data/spec/lib/LittleWeasel/filters/word_filter_validatable_spec.rb +94 -0
  113. data/spec/lib/LittleWeasel/filters/word_filters_validatable_spec.rb +48 -0
  114. data/spec/lib/LittleWeasel/integraton_tests/dictionary_integration_spec.rb +201 -0
  115. data/spec/lib/LittleWeasel/metadata/dictionary_creator_servicable_spec.rb +54 -0
  116. data/spec/lib/LittleWeasel/metadata/dictionary_metadata_spec.rb +209 -0
  117. data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +155 -0
  118. data/spec/lib/LittleWeasel/metadata/metadata_observerable_spec.rb +31 -0
  119. data/spec/lib/LittleWeasel/metadata/metadatable_spec.rb +35 -0
  120. data/spec/lib/LittleWeasel/modules/class_name_to_symbol_spec.rb +21 -0
  121. data/spec/lib/LittleWeasel/modules/dictionary_file_loader_spec.rb +125 -0
  122. data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +44 -0
  123. data/spec/lib/LittleWeasel/modules/language_spec.rb +52 -0
  124. data/spec/lib/LittleWeasel/modules/locale_spec.rb +140 -0
  125. data/spec/lib/LittleWeasel/modules/region_spec.rb +52 -0
  126. data/spec/lib/LittleWeasel/preprocessors/en_us/capitalize_preprocessor_spec.rb +34 -0
  127. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_spec.rb +105 -0
  128. data/spec/lib/LittleWeasel/preprocessors/preprocessed_word_validatable_spec.rb +143 -0
  129. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_spec.rb +77 -0
  130. data/spec/lib/LittleWeasel/preprocessors/preprocessed_words_validatable_spec.rb +58 -0
  131. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +216 -0
  132. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +175 -0
  133. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_validatable_spec.rb +109 -0
  134. data/spec/lib/LittleWeasel/preprocessors/word_preprocessors_validatable_spec.rb +49 -0
  135. data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +444 -0
  136. data/spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb +119 -0
  137. data/spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb +71 -0
  138. data/spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb +50 -0
  139. data/spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb +279 -0
  140. data/spec/lib/LittleWeasel/word_results_spec.rb +275 -0
  141. data/spec/lib/LittleWeasel/workflow/workflow_spec.rb +20 -0
  142. data/spec/spec_helper.rb +117 -6
  143. data/spec/support/factory_bot.rb +15 -0
  144. data/spec/support/file_helpers.rb +32 -0
  145. data/spec/support/files/empty-dictionary.txt +0 -0
  146. data/{lib/dictionary → spec/support/files/en-US-big.txt} +262156 -31488
  147. data/spec/support/files/en-US-tagged.txt +26 -0
  148. data/spec/support/files/en-US.txt +26 -0
  149. data/spec/support/files/en.txt +26 -0
  150. data/spec/support/files/es-ES.txt +27 -0
  151. data/spec/support/files/es.txt +27 -0
  152. data/spec/support/general_helpers.rb +68 -0
  153. data/spec/support/shared_contexts.rb +108 -0
  154. data/spec/support/shared_examples.rb +105 -0
  155. metadata +415 -52
  156. data/.rbenv-version +0 -1
  157. data/spec/checker/checker_spec.rb +0 -237
data/.rbenv-version DELETED
@@ -1 +0,0 @@
1
- system
@@ -1,237 +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
- end
113
-
114
- describe 'LittleWeasel Global Options Tests' do
115
-
116
- before (:each) do
117
- @spell = LittleWeasel::Checker.instance
118
- @spell.options = {exclude_alphabet: true, strip_whitespace: true, ignore_numeric: true}
119
- end
120
-
121
- it 'should create a LittleWeasel object' do
122
- @spell.should be_an_instance_of LittleWeasel::Checker
123
- end
124
-
125
- it 'should return true for valid word' do
126
- @spell.exists?('apple').should == true
127
- end
128
-
129
- it 'should return false for invalid word' do
130
- @spell.exists?('appel').should == false
131
- end
132
-
133
- it 'should return false for nil' do
134
- @spell.exists?(nil).should == false
135
- end
136
-
137
- it 'should return false for non-String' do
138
- @spell.exists?(:word).should == false
139
- end
140
-
141
- it 'should return false if option exclude_alphabet is true, and word is a letter' do
142
- @spell.exists?('x').should == false
143
- @spell.exists?('X').should == false
144
- end
145
-
146
- it 'should use options passed to exist? but not override global options' do
147
- @spell.exists?('h', {exclude_alphabet: false}).should == true
148
- @spell.exists?('h').should == false
149
-
150
- @spell.exists?(' h ', {exclude_alphabet: false, strip_whitespace: true}).should == true
151
- @spell.exists?(' h ').should == false
152
-
153
- @spell.exists?('1', {ignore_numeric: false}).should == false
154
- @spell.exists?('1').should == true
155
- end
156
-
157
- it 'should return true for valid word with leading spaces' do
158
- @spell.exists?(' apple').should == true
159
- end
160
-
161
- it 'should return true for valid word with trailing spaces' do
162
- @spell.exists?('apple ').should == true
163
- end
164
-
165
- it 'should return true for valid word with leading and trailing spaces' do
166
- @spell.exists?(' apple ').should == true
167
- end
168
-
169
- it 'should return true if word is a number' do
170
- @spell.exists?('1').should == true
171
- @spell.exists?('-1').should == true
172
- @spell.exists?('1.0').should == true
173
- @spell.exists?('-1.0').should == true
174
- end
175
-
176
- it 'should return false if word is a number' do
177
- @spell.options = {ignore_numeric: false}
178
- @spell.exists?('1').should == false
179
- @spell.exists?('-1').should == false
180
- @spell.exists?('1.0').should == false
181
- @spell.exists?('-1.0').should == false
182
- end
183
-
184
- end
185
-
186
- describe 'LittleWeasel Block Tests' do
187
-
188
- before (:all) do
189
- @spell = LittleWeasel::Checker.instance
190
- @spell.options = {exclude_alphabet: true, strip_whitespace: true}
191
- end
192
-
193
- it 'should return true for valid words' do
194
- @spell.exists?('apple sauce').should == true
195
- end
196
-
197
- it 'should return false for invalid words' do
198
- @spell.exists?('appel sauce').should == false
199
- end
200
-
201
- it 'should return true for valid words with leading spaces' do
202
- @spell.exists?(' apple sauce').should == true
203
- end
204
-
205
- it 'should return true for valid words with trailing spaces' do
206
- @spell.exists?('apple sauce ').should == true
207
- end
208
-
209
- it 'should return true for valid words with leading and trailing spaces' do
210
- @spell.exists?(' apple sauce ').should == true
211
- end
212
-
213
- it 'should return true for valid words split across \n and \r\n' do
214
- @spell.exists?("apple\r\n\n\nsauce is great\r\n").should == true
215
- end
216
-
217
- it 'should return true for valid words separated by \t' do
218
- @spell.exists?("\tapple\t\t\tsauce is great\t").should == true
219
- end
220
-
221
- it 'should return true for valid words that are repeated' do
222
- @spell.exists?(' are you bad are you bad are you bad ').should == true
223
- end
224
-
225
- it 'should return true for valid words separated by non-alpha chars' do
226
- @spell.exists?("hello, mister; did I \'mention\'' that lemon cake is \"great?\" It's just wonderful!").should == true
227
- end
228
-
229
- it 'should return true for valid pluralized words' do
230
- @spell.exists?('Apples and peaches are great! Some people are good, each person is a people.').should == true
231
- end
232
-
233
- it 'should return true for valid words' do
234
- @spell.exists?('Hell o').should == true
235
- end
236
-
237
- end