ru_bee 0.0.7 → 0.0.8

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmQyNTg0NWQ5NDM0OWZjYjJmZTk1ZTc0MzA0MTE5YTVlMWYyNzExYw==
4
+ ODM4ZWFiNTliOTgwNjk5ODYwNGU0MTNlOTZmOTdjNzRhM2I0NzIwNg==
5
5
  data.tar.gz: !binary |-
6
- OTVhNDE2MjY4MDU4MzkwMWE0NDJhNDdiZWY1N2FkZjUwODUyYjUxMA==
6
+ NmQ2NWZhYjNhZGVkNjMyNjQzNjI1YjBhMmExNDVkMzZmYmU4ZWNkNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Nzk4ZDk1YWI4MDAwNTYzOGQ1OGRhNGYyNjJiNDJlZGQ0ZThiZmM5M2M1MDZi
10
- M2ZiMzJmMTM5ODIzNTUxNzQwZmM1MzExNzcwYzMyOTJjYzRjOGE3MjlkZTNk
11
- ZTVlYjBlMmVhMzUxMDAyOGE3YTQ5YmFhNTUyMjVjYTdmOWQxODY=
9
+ NTQ1YmE4NTJlNGQzNjVmZjVjMWM5MDc3ZTk4NGU5YTE1ZWY1OWEwOGE3OTVl
10
+ NDUxZWZiM2EyMDUzNzIzN2RjYmYzNzgwMzQ2NzFkMDk4NWU2N2NmNzI1NTc2
11
+ NWUwNjU0YmYwNzY1MjcwOTViNTI1YTE1Zjk0NmFhNjIyNmM0MWI=
12
12
  data.tar.gz: !binary |-
13
- ZWZmZDMyNjcyMDkyZWFhMDY4MjQyZGQwMTgxMWZjZTRjNjc5MDQwOWM5ZDQy
14
- YmY1NjFlYmNiYzU4OGU5N2ExY2U0ZmZhODNhNWU4NzVkZjczMjJhMTlhZGQw
15
- ZGMzNDFjM2U1N2UwMDMxYjJjMjM4OGMzYmMyZWY0ODljODlhYjY=
13
+ ZmQ4MTVhODVkNWU3MTA2YWI0MjI5MDZkNmJjODViMjYwNmVlZGM5MTIyODVk
14
+ YmQ1ZThlMjg5MjkxNDU3NzdhMmI4MGVhMGZiYjI5ZWQxZDMwZTQ5Y2Y1YjI5
15
+ ZGQ5ZmE5ZDRkMmVhMTZiMTQ3NmQ1MjMyMmZiMzM2NjAxMDliZGY=
data/README.md CHANGED
@@ -21,7 +21,11 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- `#correct?`
24
+ ###correct?
25
+
26
+ ```
27
+ #correct?
28
+ ```
25
29
 
26
30
  ######boolean
27
31
 
@@ -29,22 +33,31 @@ Does the string contain a misspelling?
29
33
 
30
34
  ######arguments
31
35
 
32
- `#correct? language: 'english'`
36
+ ```
37
+ #correct? language: 'english'
38
+ ```
33
39
 
34
40
  Other languages coming...
35
41
 
36
42
 
37
- `"This is a correct sentence. It works well and is pretty cool. You can also use numbers 123!".correct?`
43
+ ```ruby
44
+ "This is a correct sentence. It works well and is pretty cool. You can also use numbers 123!".correct?
45
+ ```
38
46
 
39
47
  ##### `=> true`
40
48
 
41
- `"This santence contains a typo.".correct?`
49
+ ```ruby
50
+ "This santence contains a typo.".correct?
51
+ ```
42
52
 
43
53
  ##### `=> false`
44
54
 
45
55
 
56
+ ##misspellings
46
57
 
47
- `#misspellings`
58
+ ```
59
+ #misspellings
60
+ ```
48
61
 
49
62
  ######Array
50
63
 
@@ -52,19 +65,40 @@ Array of misspellings from String
52
65
 
53
66
  ######arguments
54
67
 
55
- `#misspellings? language: 'english'`
56
-
57
- Other languages coming...
68
+ ```
69
+ #misspellings? language: 'english'
70
+ ```
58
71
 
59
- `"This is a correct sentence. It works well and is pretty cool. You can also use numbers 123!".misspellings`
72
+ ```ruby
73
+ "This is a correct sentence. It works well and is pretty cool. You can also use numbers 123!".misspellings
74
+ ```
60
75
 
61
76
  ##### `=> []`
62
77
 
63
- `"This santence contains a typo.".correct?`
78
+ ```ruby
79
+ "This santence contains a typo.".misspellings
80
+ ```
64
81
 
65
82
  ##### `=> ['santence']`
66
83
 
67
84
 
85
+ ###suggestions
86
+
87
+ ```
88
+ #misspellings(suggestions: true)
89
+ ```
90
+
91
+ Returns array of hashes consisting of word and suggestions.
92
+
93
+ ```ruby
94
+ 'fla'.misspellings suggestions: true
95
+ ```
96
+
97
+ ##### `=> [{word: 'fla', suggestions: ["acriflavin", "acriflavine"...]}]`
98
+
99
+
100
+
101
+
68
102
  ## Contributing
69
103
 
70
104
  #### Dictionaries
data/lib/dictionary.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Dictionary
2
+
3
+ def initialize options={}
4
+ @options = options
5
+ end
6
+
7
+ def self.instance options={}
8
+ @instance ||= new(options)
9
+ end
10
+
11
+ def contents
12
+ @contents ||= begin
13
+ filename = @options[:language] || 'english'
14
+ path = File.dirname(__FILE__)
15
+ file = File.open("#{path}/dictionaries/#{filename}", "r")
16
+ contents = file.read.downcase.split(/\n/)
17
+ file.close
18
+ contents || []
19
+ end
20
+ end
21
+
22
+ def check word
23
+ contents.include?(word)
24
+ end
25
+
26
+ end
@@ -1,3 +1,3 @@
1
1
  module RuBee
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/scanner.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'suggestion'
2
+ require 'dictionary'
2
3
 
3
4
  class String
4
5
 
@@ -19,17 +20,6 @@ class String
19
20
  @words ||= self.downcase.gsub(/[\'\"]/, '').scan(/[a-z]+/)
20
21
  end
21
22
 
22
- def dictionary
23
- @dictionary ||= begin
24
- filename = @options[:language] || 'english'
25
- path = File.dirname(__FILE__)
26
- file = File.open("#{path}/dictionaries/#{filename}", "r")
27
- contents = file.read.downcase.split(/\n/)
28
- file.close
29
- contents || []
30
- end
31
- end
32
-
33
23
  def remove_s word
34
24
  if word[-1] == 's'
35
25
  return word[0...-1]
@@ -59,15 +49,15 @@ class String
59
49
  end
60
50
 
61
51
  def check opts={}
52
+ dictionary = Dictionary.instance @options
62
53
  @bad_words = []
63
54
  words.each do |word|
64
- unless dictionary.include?("#{word}") or
65
- dictionary.include?("#{remove_s(word)}") or
66
- dictionary.include?("#{remove_ed(word)}") or
67
- dictionary.include?("#{remove_ing(word)}") or
68
- dictionary.include?("#{remove_es(word)}")
69
- suggestion = Suggestion.new word, @dictionary
70
- @bad_words << (opts[:suggestions] ? suggestion.search : word)
55
+ unless dictionary.check("#{word}") or
56
+ dictionary.check("#{remove_s(word)}") or
57
+ dictionary.check("#{remove_ed(word)}") or
58
+ dictionary.check("#{remove_ing(word)}") or
59
+ dictionary.check("#{remove_es(word)}")
60
+ @bad_words << (opts[:suggestions] ? (Suggestion.new(word, dictionary.contents).search) : word)
71
61
  return false unless opts[:collect]
72
62
  end
73
63
  end
data/lib/suggestion.rb CHANGED
@@ -31,8 +31,7 @@ class Suggestion
31
31
  end
32
32
 
33
33
  def try_3
34
- parts = @word.chars.to_a.join('')
35
- @dictionary.join("\n").scan(/(.*[#{parts}]+.*)/).flatten
34
+ @dictionary.join("\n").scan(/(.*[#{@word}]+.*)/).flatten
36
35
  end
37
36
 
38
37
  def find word
data/ru_bee.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["dan"]
10
10
  spec.email = ["danbickford007@yahoo.com"]
11
11
  spec.summary = %q{Dictionary for Ruby String.}
12
- spec.description = %q{See if a string contains any incorrect words. Use by 'this is a test'.correct?}
12
+ spec.description = %q{Checks Ruby String for misspellings. Usage: 'this is a test'.correct? 'this is a test'.misspellings(suggestions: true)}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -0,0 +1,32 @@
1
+ require 'dictionary'
2
+
3
+ describe Dictionary do
4
+
5
+ let(:dictionary) { Dictionary.instance {}}
6
+
7
+ describe '#contents' do
8
+
9
+ it 'should have x amount contents' do
10
+ expect(dictionary.contents.count).to eq(235887)
11
+ end
12
+
13
+ end
14
+
15
+ describe '.instance' do
16
+
17
+ it 'should only have 1 instance' do
18
+ dict = Dictionary.instance
19
+ expect(dictionary.object_id).to eq(dict.object_id)
20
+ end
21
+
22
+ end
23
+
24
+ describe '#check' do
25
+
26
+ it 'should word exists in contents' do
27
+ expect(dictionary.check('test')).to eq(true)
28
+ end
29
+
30
+ end
31
+
32
+ end
data/spec/scanner_spec.rb CHANGED
@@ -50,15 +50,6 @@ describe String do
50
50
 
51
51
  end
52
52
 
53
- describe '#load_dictionary' do
54
-
55
- it 'should set DICTIONARY to' do
56
- test_string_good.correct?
57
- expect(test_string_good.send('dictionary').count).to eq(235887)
58
- end
59
-
60
- end
61
-
62
53
  describe '#remove_s' do
63
54
 
64
55
  it 'should trim plural to singluar with s' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ru_bee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - dan
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.2.0
55
- description: See if a string contains any incorrect words. Use by 'this is a test'.correct?
55
+ description: ! 'Checks Ruby String for misspellings. Usage: ''this is a test''.correct? ''this
56
+ is a test''.misspellings(suggestions: true)'
56
57
  email:
57
58
  - danbickford007@yahoo.com
58
59
  executables: []
@@ -65,6 +66,7 @@ files:
65
66
  - README.md
66
67
  - Rakefile
67
68
  - lib/dictionaries/english
69
+ - lib/dictionary.rb
68
70
  - lib/ru_bee.rb
69
71
  - lib/ru_bee/version.rb
70
72
  - lib/scanner.rb
@@ -72,6 +74,7 @@ files:
72
74
  - ru_bee-0.0.2.gem
73
75
  - ru_bee.gemspec
74
76
  - ru_bee_string.rb
77
+ - spec/dictionary_spec.rb
75
78
  - spec/scanner_spec.rb
76
79
  - spec/suggestion_spec.rb
77
80
  homepage: ''
@@ -99,5 +102,6 @@ signing_key:
99
102
  specification_version: 4
100
103
  summary: Dictionary for Ruby String.
101
104
  test_files:
105
+ - spec/dictionary_spec.rb
102
106
  - spec/scanner_spec.rb
103
107
  - spec/suggestion_spec.rb