google_spell_checker 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd33719da11926dc4260604e7bf8760ee7c9a3c2
4
- data.tar.gz: d6564aa2e9fa1702433691bccd495da71a48a4bf
3
+ metadata.gz: 6637d2b991d84b685bc8d64ceb521640672f3364
4
+ data.tar.gz: b2224570f1539679694f70954524b28e1f78faa5
5
5
  SHA512:
6
- metadata.gz: 59b4841159c31d1bae1360d55dc46bacba2b4889c4c97ca032ca2dbafd40b6457b363e1748b6f9cde8d10266ed1882b584ba94d4834557aacf1e39efc6da5ff8
7
- data.tar.gz: d6943a9d2779bb1d686a67f6dea8f10df40ac5c3873af5d86e33dcdc67065ef411682e3e368f4318b7cce5f2ff76bc1c7d8b829b559e13d59c7bb892f3133e2b
6
+ metadata.gz: 211b76f40429b7b35b1eebada985395cc2c0524e5647d42d726c2fc61b84d53ae79713fdd89e3e3ccd201055ffbabb45d1b9a50eac7a4bd0f25064b1884b0a9e
7
+ data.tar.gz: 9b4aa6d77e0ec0116d54325c2aa97ea9d82ad9ccd6cbf002a3c0937bae775df9640acadf00c12e82f736161d523e2b421b17ac3962d3fe227f3855433f5ceb91
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ google_spell_checker
2
+ ====================
3
+
4
+ ###Intro
5
+
6
+ This gem is using google to check word's spelling.
7
+
8
+
9
+ ###Installation
10
+
11
+ ```
12
+ gem 'google_spell_checker','0.0.0'
13
+ ```
14
+
15
+ and run the `bundle` command.
16
+
17
+ ###Examples
18
+
19
+ ```
20
+ GoogleSpellChecker.check 'take m to your heatr'
21
+ => "take <em>me</em> to your <em>heart</em>"
22
+ ```
23
+
24
+ If there is no incorrect word, it will output void character.
@@ -0,0 +1,15 @@
1
+ $:.push File.expand_path("../lib",__FILE__)
2
+ require 'google_spell_checker/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'google_spell_checker'
6
+ s.version = GoogleSpellChecker::VERSION
7
+ s.date = '2014-02-18'
8
+ s.summary = 'Google spell checker'
9
+ s.description = 'A simple spell checking gem using google'
10
+ s.authors = ['Michael Ji']
11
+ s.email = 'zilong@gmail.com'
12
+ s.homepage = 'https://github.com/apprentice1988/google_spell_checker.git'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.require_paths = ['lib']
15
+ end
@@ -0,0 +1,16 @@
1
+ module GoogleSpellChecker
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc <<DESC
7
+ Description:
8
+ Copies GoogleSpellChecker configuration file to your application's initializer directory.
9
+ DESC
10
+
11
+ def copy_config_file
12
+ template 'google_spell_checker_config.rb', 'config/initializers/google_spell_checker_config.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ GoogleSpellChecker.configure do |config|
2
+ #if you want to replace google.com using google.com.hk to yield checking result
3
+ #config.using_hk = true
4
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/configurable'
2
+
3
+ module GoogleSpellChecker
4
+
5
+ def self.configure(&block)
6
+ yield @config ||= GoogleSpellChecker::Configuration.new
7
+ end
8
+
9
+ def self.config
10
+ @config
11
+ end
12
+
13
+ class Configuration
14
+ include ActiveSupport::Configurable
15
+ config_accessor :using_hk
16
+ config.using_hk = false
17
+ end
18
+
19
+ def param_name
20
+ config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
21
+ end
22
+
23
+ # define param_name writer (copied from AS::Configurable)
24
+ writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
25
+ singleton_class.class_eval writer, __FILE__, line
26
+ class_eval writer, __FILE__, line
27
+ end
@@ -0,0 +1,3 @@
1
+ module GoogleSpellChecker
2
+ VERSION = '0.1.0'
3
+ end
@@ -1,15 +1,32 @@
1
1
  #encoding: utf-8
2
2
  require 'net/http'
3
- class GoogleSpellChecker
4
- API_BASEURI = "https://www.google.com.hk/search?"
5
- SPELL_EXP = Regexp.new(/(\s|\w)*<em>(\w)*<\/em\>(\s|\w)*/)
6
-
3
+ require 'google_spell_checker/config'
4
+ module GoogleSpellChecker
7
5
  def self.check content
6
+ check_using_hk?
8
7
  params = {:q=> content, :oq=> content}
9
- uri = URI(API_BASEURI)
8
+ uri = URI(@base)
10
9
  uri.query = URI.encode_www_form(params)
11
10
  res = Net::HTTP.get(uri)
12
- matches = res.to_enum(:scan,SPELL_EXP).map{Regexp.last_match}
11
+ matches = res.to_enum(:scan,@regex).map{Regexp.last_match}
13
12
  matches[0,(matches.count/2)].inject(""){|result,match|result + match.to_s}
14
13
  end
14
+
15
+ private
16
+
17
+ def self.check_using_hk?
18
+ if GoogleSpellChecker.config.using_hk
19
+ @base = "https://www.google.com.hk/search?"
20
+ @regex = Regexp.new(/(\s|\w)*<em>(\w)*<\/em\>(\s|\w)*/)
21
+ else
22
+ @base = "https://www.google.com/search?"
23
+ @regex = Regexp.new(/(\s|\w)*<b><i>(\w)*<\/i\><\/b\>(\s|\w)*/)
24
+ end
25
+ end
26
+ end
27
+
28
+ begin
29
+ require 'rails'
30
+ rescue LoadError
31
+ #do nothing
15
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_spell_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Ji
@@ -16,7 +16,14 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - .gitignore
20
+ - README.md
21
+ - google_spell_checker.gemspec
22
+ - lib/generators/google_spell_checker/config_generator.rb
23
+ - lib/generators/google_spell_checker/templates/google_spell_checker_config.rb
19
24
  - lib/google_spell_checker.rb
25
+ - lib/google_spell_checker/config.rb
26
+ - lib/google_spell_checker/version.rb
20
27
  homepage: https://github.com/apprentice1988/google_spell_checker.git
21
28
  licenses: []
22
29
  metadata: {}
@@ -36,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
43
  version: '0'
37
44
  requirements: []
38
45
  rubyforge_project:
39
- rubygems_version: 2.0.3
46
+ rubygems_version: 2.2.2
40
47
  signing_key:
41
48
  specification_version: 4
42
49
  summary: Google spell checker