isword 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 +7 -0
- data/bin/isword +5 -0
- data/lib/isword.rb +46 -0
- data/resources/dictionary.txt +80368 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5776c3544bdba6ee62a01a631f89b2367dc6f12b
|
4
|
+
data.tar.gz: f3b783b93c9da29ac404baf8a209012698a86771
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bb8566239feb195551baaceafdd3035557246c605713ec37bdd4424397d4c4afd89dff18b0d17e4e7fea0e1827f07e5355a13c268a38b46ee67cd30985b7fc0
|
7
|
+
data.tar.gz: 4cd4c4969d521ccf3ec720473727a1e3b4cf15b4cecdcbde24f2e814c9283f49f7af8cb4e3b629526afc028fe0ea4b2bbeff8e6d5aab8fa8a9d97be0afd1d5e1
|
data/bin/isword
ADDED
data/lib/isword.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
# IsWord v1.0 test word existence
|
3
|
+
|
4
|
+
class IsWord
|
5
|
+
|
6
|
+
# Word validating class
|
7
|
+
|
8
|
+
RESOURCE_DIR = File.expand_path( "../resources", File.dirname( __FILE__ ) )
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
|
12
|
+
# Load dictionary
|
13
|
+
|
14
|
+
@words = {}
|
15
|
+
|
16
|
+
begin
|
17
|
+
|
18
|
+
IO.foreach( RESOURCE_DIR + "/dictionary.txt" ) { |word|
|
19
|
+
@words[ word.strip ] = true
|
20
|
+
}
|
21
|
+
|
22
|
+
rescue SystemCallError
|
23
|
+
# In case of missing resource
|
24
|
+
raise IOError.new( "dictoinary.txt resource not found in gem directory" )
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def is?( word )
|
30
|
+
|
31
|
+
# Check for word validity
|
32
|
+
|
33
|
+
begin
|
34
|
+
|
35
|
+
return @words[ word.downcase ]
|
36
|
+
|
37
|
+
rescue NoMethodError
|
38
|
+
# For invalid types
|
39
|
+
raise TypeError.new( "word must be of type String" )
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|