auto-correct 0.1.0.pre0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 764ae2dccd3a0b65e9e5b071a3568620ade98d52
4
+ data.tar.gz: 01a7ea3ed26327875a22530df5722af6a5253f14
5
+ SHA512:
6
+ metadata.gz: 8253513e4b424534a08ef122023b2d7c03c1f1fe518f4028bd0658e87884eee5bba95e9f002b0dd915c0f57bf08e8fc7f06c6710c15cd3a1020ec8f55a0ef494
7
+ data.tar.gz: 00fb083fcf99ddfbd779a57ad0a847ffc41e7dbff551ada550a35ba6a8118d50290af6c880897e97c549f2bb0425a56b54a44de7b14b356114990014863205cf
@@ -0,0 +1,62 @@
1
+ # auto-correct
2
+
3
+ 自动纠正中文英文混排是一些不够好的写法,纠正错误的名词大小写。
4
+
5
+ Before
6
+
7
+ ```
8
+ [经验之谈]转行做ruby程序员的8个月, mysql 经验
9
+ ```
10
+
11
+ After
12
+
13
+ ```
14
+ [经验之谈] 转行做 Ruby 程序员的 8 个月, MySQL 经验
15
+ ```
16
+
17
+ [![Gem Version](https://badge.fury.io/rb/auto-space.png)](https://rubygems.org/gems/auto-space) [![Build
18
+ Status](https://secure.travis-ci.org/huacnlee/auto-space.png?branch=master&.png)](http://travis-ci.org/huacnlee/auto-space)
19
+
20
+ ## 使用说明
21
+
22
+ ```irb
23
+ irb> require 'auto-correct'
24
+ true
25
+
26
+ irb> "关于SSH连接的Permission denied(publickey).".auto_space!
27
+ 关于 SSH 连接的 Permission denied (publickey).
28
+
29
+ irb> "怎样追踪一个repo的新feature 和进展呢?".auto_space!
30
+ 怎样追踪一个 repo 的新 feature 和进展呢?
31
+
32
+ irb> "vps上sessions不生效,但在本地的环境是ok的,why?".auto_space!
33
+ vps 上 sessions 不生效,但在本地的环境是 OK 的,why?
34
+
35
+ irb> "bootstrap control-group对齐问题".auto_space!
36
+ bootstrap control-group 对齐问
37
+ ```
38
+
39
+ ## 性能
40
+
41
+ 详见 Rakefile
42
+
43
+ ```
44
+ $ rake benchmark
45
+ user system total real
46
+ 100 times 0.000000 0.000000 0.000000 ( 0.002223)
47
+ 1000 times 0.030000 0.000000 0.030000 ( 0.024711)
48
+ 10000 times 0.230000 0.000000 0.230000 ( 0.240850)
49
+ ```
50
+
51
+ ## TODO
52
+
53
+ * 'Foo'的"Bar" -> 'Foo' 的 "Bar"
54
+ * 什么,时候 -> 什么, 时候 -> 什么,时候
55
+
56
+ ## 应用案例
57
+
58
+ * [Ruby China](http://ruby-china.org) - 目前整站的标题都做了自动转换处理。
59
+
60
+ ## 参考内容
61
+
62
+ * [Chinese Copywriting Guidelines](https://github.com/sparanoid/chinese-copywriting-guidelines)
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ require "auto-correct/dicts"
3
+
4
+ class String
5
+ def auto_space!
6
+ self.gsub! /((?![年月日号])\p{Han})([a-zA-Z0-9+$@#\[\(\/‘“])/u do
7
+ "#$1 #$2"
8
+ end
9
+
10
+ self.gsub! /([a-zA-Z0-9+$’”\]\)@#!\/]|[\d[年月日]]{2,})((?![年月日号])\p{Han})/u do
11
+ "#$1 #$2"
12
+ end
13
+
14
+ # Fix () [] near the English and number
15
+ self.gsub! /([a-zA-Z0-9]+)([\[\(‘“])/u do
16
+ "#$1 #$2"
17
+ end
18
+
19
+ self.gsub! /([\)\]’”])([a-zA-Z0-9]+)/u do
20
+ "#$1 #$2"
21
+ end
22
+
23
+ self
24
+ end
25
+
26
+ def auto_correct!
27
+ self.auto_space!
28
+
29
+ self.gsub! /([\d\p{Han}]|\s|^)([a-zA-Z\d\-\_\.]+)([\d\p{Han}]|\s|$)/u do
30
+ key = "#$2".downcase
31
+ if AutoCorrect::DICTS.has_key?(key)
32
+ ["#$1",AutoCorrect::DICTS[key],"#$3"].join("")
33
+ else
34
+ "#$1#$2#$3"
35
+ end
36
+ end
37
+
38
+ self
39
+ end
40
+ end
@@ -0,0 +1,103 @@
1
+ module AutoCorrect
2
+ DICTS = {
3
+ # Ruby
4
+ "ruby" => "Ruby",
5
+ "rails" => "Rails",
6
+ "rubygems" => "RubyGems",
7
+ "ror" => "Ruby on Rails",
8
+ "rubyconf" => "RubyConf",
9
+ "railsconf" => "RailsConf",
10
+ "rubytuesday" => "Ruby Tuesday",
11
+ "jruby" => "JRuby",
12
+ "mruby" => "mRuby",
13
+ "rvm" => "RVM",
14
+ "rbenv" => "rbenv",
15
+ "yard" => "YARD",
16
+ "rdoc" => "RDoc",
17
+ "rspec" => "RSpec",
18
+ "minitest" => "MiniTest",
19
+ "coffeescript" => "CoffeeScript",
20
+ "scss" => "SCSS",
21
+ "sass" => "Sass",
22
+ "sidekiq" => "Sidekiq",
23
+ "railscasts" => "RailsCasts",
24
+ "execjs" => "ExecJS",
25
+
26
+ # Python
27
+
28
+ # Node.js
29
+ "nodejs" => "Node.js",
30
+
31
+ # Go
32
+
33
+ # Cocoa
34
+ "reactivecocoa" => "ReactiveCocoa",
35
+
36
+ # Programming
37
+ "ssh" => "SSH",
38
+ "css" => "CSS",
39
+ "html" => "HTML",
40
+ "javascript" => "JavaScript",
41
+ "js" => "JS",
42
+ "png" => "PNG",
43
+ "dsl" => "DSL",
44
+ "tdd" => "TDD",
45
+ "bdd" => "BDD",
46
+
47
+ # Sites
48
+ "github" => "GitHub",
49
+ "gist" => "Gist",
50
+ "ruby_china" => "Ruby China",
51
+ "ruby-china" => "Ruby China",
52
+ "rubychina" => "Ruby China",
53
+ "v2ex" => "V2EX",
54
+ "heroku" => "Heroku",
55
+ "stackoverflow" => "Stack Overflow",
56
+ "stackexchange" => "StackExchange",
57
+
58
+
59
+ # Databases
60
+ "mysql" => "MySQL",
61
+ "postgresql" => "PostgreSQL",
62
+ "sqlite" => "SQLite",
63
+ "mongodb" => "MongoDB",
64
+ "rethinkdb" => "RethinkDB",
65
+ "elasticsearch" => "Elasticsearch",
66
+ "sphinx" => "Sphinx",
67
+
68
+ # OpenSource Projects
69
+ "gitlab" => "GitLab",
70
+ "gitlabci" => "GitLab CI",
71
+ "fontawsome" => "FontAwsome",
72
+ "bootstrap" => "Bootstrap",
73
+ "less" => "Less",
74
+ "jquery" => "jQuery",
75
+ "requirejs" => "RequireJS",
76
+ "underscore" => "Underscore",
77
+ "backbone" => "Backbone",
78
+ "seajs" => "SeaJS",
79
+ "imagemagick" => "ImageMagick",
80
+
81
+ # Tools
82
+ "vim" => "VIM",
83
+ "emacs" => "Emacs",
84
+ "textmate" => "TextMate",
85
+ "sublime" => "Sublime",
86
+ "rubymine" => "RubyMine",
87
+ "sequelpro" => "Sequel Pro",
88
+ "virtualbox" => "VirtualBox",
89
+ "safari" => "Safari",
90
+ "chrome" => "Chrome",
91
+ "ie" => "IE",
92
+
93
+ # Misc
94
+ "ios" => "iOS",
95
+ "iphone" => "iPhone",
96
+ "android" => "Android",
97
+ "osx" => "OS X",
98
+ "mac" => "Mac",
99
+ "api" => "API",
100
+ "wi-fi" => "Wi-Fi",
101
+ "wifi" => "Wi-Fi"
102
+ }
103
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto-correct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre0
5
+ platform: ruby
6
+ authors:
7
+ - Luikore
8
+ - Jason Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">"
19
+ - !ruby/object:Gem::Version
20
+ version: 3.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">"
26
+ - !ruby/object:Gem::Version
27
+ version: 3.0.0
28
+ description: "自动给中文英文之间加入合理的空格"
29
+ email:
30
+ - usurffx@gmail.com
31
+ - huacnlee@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - README.md
37
+ - lib/auto-correct.rb
38
+ - lib/auto-correct/dicts.rb
39
+ homepage: https://github.com/huacnlee/auto-correct
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">"
54
+ - !ruby/object:Gem::Version
55
+ version: 1.3.1
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.2.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: "自动给中文英文之间加入合理的空格"
62
+ test_files: []
63
+ has_rdoc: