ru_bee 0.0.4

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.
@@ -0,0 +1,3 @@
1
+ module RuBee
2
+ VERSION = "0.0.4"
3
+ end
data/lib/ru_bee.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "ru_bee/version"
2
+ require "scanner"
3
+
4
+ module RuBee
5
+ end
data/lib/scanner.rb ADDED
@@ -0,0 +1,69 @@
1
+ class String
2
+
3
+ @dictionary = []
4
+ @options = {}
5
+
6
+ def correct? options={}
7
+ @options = options
8
+ get_parts
9
+ load_dictionary
10
+ check
11
+ end
12
+
13
+ private
14
+
15
+ def get_parts
16
+ @parts = self.downcase.gsub(/[\'\"]/, '').scan(/[a-z]+/)
17
+ end
18
+
19
+ def load_dictionary
20
+ filename = @options[:language] || 'english'
21
+ path = File.dirname(__FILE__)
22
+ file = File.open("#{path}/dictionaries/#{filename}", "r")
23
+ @dictionary = file.read.downcase.split(/\n/)
24
+ file.close
25
+ @dictionary
26
+ end
27
+
28
+ def remove_s word
29
+ if word[-1] == 's'
30
+ return word[0...-1]
31
+ end
32
+ word
33
+ end
34
+
35
+ def remove_ed(word)
36
+ if word[-1] == 'd' and word[-2] == 'e'
37
+ return word[0...-2]
38
+ end
39
+ word
40
+ end
41
+
42
+ def remove_es(word)
43
+ if word[-1] == 's' and word[-2] == 'e'
44
+ return word[0...-2]
45
+ end
46
+ word
47
+ end
48
+
49
+ def remove_ing(word)
50
+ if word[-1] == 'g' and word[-2] == 'n' and word[-3] == 'i'
51
+ return word[0...-3]
52
+ end
53
+ word
54
+ end
55
+
56
+ def check
57
+ @parts.each do |word|
58
+ unless @dictionary.include?("#{word}") or
59
+ @dictionary.include?("#{remove_s(word)}") or
60
+ @dictionary.include?("#{remove_ed(word)}") or
61
+ @dictionary.include?("#{remove_ing(word)}") or
62
+ @dictionary.include?("#{remove_es(word)}")
63
+ return false
64
+ end
65
+ end
66
+ true
67
+ end
68
+
69
+ end
data/ru_bee-0.0.2.gem ADDED
Binary file
data/ru_bee.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ru_bee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ru_bee"
8
+ spec.version = RuBee::VERSION
9
+ spec.authors = ["dan"]
10
+ spec.email = ["danbickford007@yahoo.com"]
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?}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "3.2.0"
24
+ end
data/ru_bee_string.rb ADDED
@@ -0,0 +1,34 @@
1
+ class String
2
+
3
+ @dictionary = []
4
+
5
+ def correct? options={}
6
+ @options = options
7
+ get_parts
8
+ load_dictionary
9
+ check
10
+ end
11
+
12
+ def get_parts
13
+ @parts = self.downcase.gsub(/[\'\"]/, '').scan(/[a-z]+/)
14
+ end
15
+
16
+ def load_dictionary
17
+ filename = @options[:language] || 'english'
18
+ file = File.open("lib/#{filename}", "r")
19
+ @dictionary = file.read.downcase.split(/\n/)
20
+ file.close
21
+ @dictionary
22
+ end
23
+
24
+ def check
25
+ @parts.each do |word|
26
+ unless @dictionary.include?("#{word}") or @dictionary.include?("#{word[0...-1]}")
27
+ return false
28
+ end
29
+ end
30
+ true
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,70 @@
1
+ require 'scanner'
2
+
3
+ describe String do
4
+
5
+ let(:test_string_good) { "This is a test string. It doesn't have 123 any issues." }
6
+ let(:test_string_bad) { "This is a test string. But it conaens a bad word." }
7
+
8
+
9
+ describe '#correct?' do
10
+
11
+ it 'should return true with correct word' do
12
+ expect(test_string_good.correct?).to eq(true)
13
+ end
14
+
15
+ it 'should return false with incorrect word' do
16
+ expect(test_string_bad.correct?).to eq(false)
17
+ end
18
+
19
+ end
20
+
21
+ describe '#get_parts' do
22
+
23
+ it 'should break string into word parts' do
24
+ expect(test_string_good.send('get_parts').count).to eq(10)
25
+ end
26
+
27
+ end
28
+
29
+ describe '#load_dictionary' do
30
+
31
+ it 'should set DICTIONARY to' do
32
+ test_string_good.correct?
33
+ expect(test_string_good.send('load_dictionary').count).to eq(235887)
34
+ end
35
+
36
+ end
37
+
38
+ describe '#remove_s' do
39
+
40
+ it 'should trim plural to singluar with s' do
41
+ expect(test_string_good.send('remove_s', 'tests')).to eq('test')
42
+ end
43
+
44
+ end
45
+
46
+ describe '#remove_ed' do
47
+
48
+ it 'should trim past with ed' do
49
+ expect(test_string_good.send('remove_ed', 'tested')).to eq('test')
50
+ end
51
+
52
+ end
53
+
54
+ describe '#remove_es' do
55
+
56
+ it 'should trim past with es' do
57
+ expect(test_string_good.send('remove_es', 'testes')).to eq('test')
58
+ end
59
+
60
+ end
61
+
62
+ describe '#remove_ing' do
63
+
64
+ it 'should trim past with ing' do
65
+ expect(test_string_good.send('remove_ing', 'testing')).to eq('test')
66
+ end
67
+
68
+ end
69
+
70
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ru_bee
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - dan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ description: See if a string contains any incorrect words. Use by 'this is a test'.correct?
56
+ email:
57
+ - danbickford007@yahoo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/dictionaries/english
68
+ - lib/ru_bee.rb
69
+ - lib/ru_bee/version.rb
70
+ - lib/scanner.rb
71
+ - ru_bee-0.0.2.gem
72
+ - ru_bee.gemspec
73
+ - ru_bee_string.rb
74
+ - spec/scanner_spec.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Dictionary for Ruby String.
99
+ test_files:
100
+ - spec/scanner_spec.rb