Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.

Commit 47d7b78

Browse files
committed
First commit.
1 parent 688b7f4 commit 47d7b78

File tree

6 files changed

+122
-2
lines changed

6 files changed

+122
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'http://ruby.taobao.org'
2+
gemspec

Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PATH
2+
remote: .
3+
specs:
4+
auto-space (0.0.1)
5+
6+
GEM
7+
remote: http://ruby.taobao.org/
8+
specs:
9+
10+
PLATFORMS
11+
ruby
12+
13+
DEPENDENCIES
14+
auto-space!

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
auto-space
2-
==========
1+
# auto-space
32

43
自动给中文英文之间加入合理的空格
4+
5+
## 例如
6+
7+
```
8+
关于 SSH连接的Permission denied (publickey).
9+
怎样追踪一个 repo的新feature 和进展呢?
10+
vps上sessions不生效,但在本地的环境是ok的,why?
11+
bootstrap control-group对齐问题
12+
貌似github又down了
13+
```
14+
15+
将会成为
16+
17+
```
18+
关于 SSH 连接的 Permission denied (publickey).
19+
怎样追踪一个 Repo 的新 Feature 和进展呢?
20+
VPS 上 sessions 不生效,但在本地的环境是 OK 的,why?
21+
Bootstrap control-group 对齐问题
22+
```

auto-space.gemspec

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding: utf-8
2+
$:.push File.expand_path("../lib", __FILE__)
3+
4+
Gem::Specification.new do |s|
5+
s.name = "auto-space"
6+
s.version = "0.0.1"
7+
s.platform = Gem::Platform::RUBY
8+
s.authors = ["Luikore","Jason Lee"]
9+
10+
s.homepage = "https://github.com/huacnlee/auto-space"
11+
s.summary = %q{自动给中文英文之间加入合理的空格}
12+
s.description = %q{自动给中文英文之间加入合理的空格}
13+
s.files = Dir.glob("lib/**/*") + %w(README.md)
14+
s.require_path = 'lib'
15+
end

lib/auto-space.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class String
2+
def auto_space!
3+
self.gsub! /((?![年月日])\p{Han})([a-zA-Z0-9@#\/])/u do
4+
"#$1 #$2"
5+
end
6+
self.gsub! /([a-zA-Z0-9@#!\/]|[\d[年月日]])((?![年月日])\p{Han})/u do
7+
"#$1 #$2"
8+
end
9+
self
10+
end
11+
end

spec/text_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
require "auto-space"
2+
3+
describe "AutoSpace" do
4+
it "should work with simple" do
5+
"部署到heroku有问题网页不能显示".auto_space!.should == "部署到 heroku 有问题网页不能显示"
6+
end
7+
8+
it "should with () or []" do
9+
"[北京]美企聘site/web大型应用开发高手-Ruby(Java/PHP/Python也可)".auto_space!.should == "[北京]美企聘 site/web 大型应用开发高手-Ruby(Java/PHP/Python 也可)"
10+
"[成都](团800)招聘Rails工程师".auto_space!.should == "[成都](团 800)招聘 Rails 工程师"
11+
end
12+
13+
it "should with . !" do
14+
"Teahour.fm第18期发布".auto_space!.should == "Teahour.fm 第 18 期发布"
15+
"Yes!升级到了Rails 4".auto_space!.should == "Yes! 升级到了 Rails 4"
16+
"delete!方法是做什么的".auto_space!.should == "delete! 方法是做什么的"
17+
"到了!升级到了Rails 4".auto_space!.should == "到了! 升级到了 Rails 4"
18+
end
19+
20+
it "should with URL" do
21+
"http://sourceforge.net/解禁了".auto_space!.should == "http://sourceforge.net/ 解禁了"
22+
end
23+
24+
it "should with #" do
25+
"个人信息显示公开记事本,记事本显示阅读次数#149".auto_space!.should == "个人信息显示公开记事本,记事本显示阅读次数 #149"
26+
end
27+
28+
it "should with @" do
29+
"里面用@foo符号的话后面的变量名会被替换成userN".auto_space!.should == "里面用 @foo 符号的话后面的变量名会被替换成 userN"
30+
end
31+
32+
it 'should with \ /' do
33+
"我/解禁了".auto_space!.should == "我 / 解禁了"
34+
"WWDC上讲到的Objective C/LLVM改进".auto_space!.should == "WWDC 上讲到的 Objective C/LLVM 改进"
35+
end
36+
37+
it "should with number" do
38+
"在Ubuntu11.10 64位系统安装newrelic出错".auto_space!.should == "在 Ubuntu11.10 64 位系统安装 newrelic 出错"
39+
"升级了10.9 附遇到的bug".auto_space!.should == "升级了 10.9 附遇到的 bug"
40+
"喜欢暗黑2却对D3不满意的可以看看这个。。".auto_space!.should == "喜欢暗黑 2 却对 D3 不满意的可以看看这个。。"
41+
"在做ROR 3.2 Tutorial第Chapter 9.4.2遇到一个问题求助!".auto_space!.should == "在做 ROR 3.2 Tutorial 第 Chapter 9.4.2 遇到一个问题求助!"
42+
end
43+
44+
it "should with other cases" do
45+
"创建一篇article,但是却爆了ActionDispatch::Cookies::CookieOverflow的异常".auto_space!.should == "创建一篇 article,但是却爆了 ActionDispatch::Cookies::CookieOverflow 的异常"
46+
"Mac安装软件新方法:Homebrew-cask".auto_space!.should == "Mac 安装软件新方法:Homebrew-cask"
47+
"Mac安装软件新方法: Homebrew-cask".auto_space!.should == "Mac 安装软件新方法: Homebrew-cask"
48+
"Gitlab怎么集成GitlabCI.".auto_space!.should == "Gitlab 怎么集成 GitlabCI."
49+
end
50+
51+
it "should with 年月日" do
52+
"5天的活动".auto_space!.should == "5 天的活动"
53+
"我10岁的时候".auto_space!.should == "我 10 岁的时候"
54+
"再过3天我们就去".auto_space!.should == "再过 3 天我们就去"
55+
"于3月10日开始".auto_space!.should == "于 3月10日 开始"
56+
"于3月开始".auto_space!.should == "于 3月 开始"
57+
"于2009年开始".auto_space!.should == "于 2009年 开始"
58+
"2013年3月10日-Ruby Saturday活动召集".auto_space!.should == "2013年3月10日-Ruby Saturday 活动召集"
59+
end
60+
end

0 commit comments

Comments
 (0)