spell_check 0.0.1
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.
- checksums.yaml +15 -0
- data/lib/spell_check/dictionary.rb +42 -0
- data/lib/spell_check/version.rb +3 -0
- data/lib/spell_check/words.txt +234936 -0
- data/lib/spell_check.rb +129 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDVjNDRmYmQ4YzE4Mjc4ZmYxNTRiYTA3OGM2ODBkNjJiYWU0Yzk4NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2M0MzI4MTU1N2MzMTEwZTEzZTc2YWZmM2I1ZWUxZDNmNmFiNjczYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDcyYjE0MGIxNTZkMTFkYmM1NWZmN2I0MWIxMzUyNDAxNjE3YmMzMTQ0MjMw
|
10
|
+
NmU5NDc1ZjY0MmY1OWI2MGYxYTY2NGJkODIzMDcxNmI1NTE4YWI1MTczN2Q0
|
11
|
+
YWE1YTI5Y2UzM2Q3MDk2Y2IxNDhiNTJlMDMxMzIzZmIwMmRmMDk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDJkMjE1ZDM1MmExNjdjYTJiNzcwZDczNTZjNzM5MWM3NzI4MDUyN2E1Njdh
|
14
|
+
MzEzYzVhNzI5MzcyYTRiOTNkZjViYTc0MjUyYjczZjhkZDhlOTVlNDczNzY0
|
15
|
+
NTcwODZkMTBiYzRhNmQ3M2Y1NGQ0OWNiMjFkZTIyMTU0ZDE2Mzg=
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Dictionary
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
# Instantiates dictionary with words from the words.txt file. This gem has been built specifically for this word
|
5
|
+
# list, so the file name is hard coded.
|
6
|
+
def initialize
|
7
|
+
@words_set = Set.new
|
8
|
+
words_file = File.expand_path(File.dirname(__FILE__) + '/words.txt')
|
9
|
+
File.readlines(words_file).each do |line|
|
10
|
+
@words_set.add(line.to_s.strip)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Checks if this dictionary contains the word, either in lowercase or capitalized (first character) form. Returns
|
15
|
+
# the matched word, or nil if no match was found.
|
16
|
+
# @param [String] word
|
17
|
+
# @return [String]
|
18
|
+
def find_word( word )
|
19
|
+
word_str = word.to_s
|
20
|
+
found_word = nil
|
21
|
+
if @words_set.include? word_str
|
22
|
+
found_word = word_str
|
23
|
+
elsif @words_set.include? word_str.capitalize
|
24
|
+
found_word = word_str.capitalize
|
25
|
+
elsif @words_set.include? word_str.downcase
|
26
|
+
found_word = word_str.downcase
|
27
|
+
end
|
28
|
+
return found_word
|
29
|
+
end
|
30
|
+
|
31
|
+
# Scans the word set (down cased) for any values that match the regular expression parameter
|
32
|
+
# @param [RegExp] reg_ex
|
33
|
+
# @return [Set]
|
34
|
+
def find_reg_ex_matches( reg_ex )
|
35
|
+
match_set = Set.new
|
36
|
+
@words_set.to_a.each do |word|
|
37
|
+
match_set.add word if word.downcase.match(reg_ex)
|
38
|
+
end
|
39
|
+
return match_set
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|