chinese_name 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/chinese_name.gemspec +35 -0
- data/data/last_name.dat +434 -0
- data/lib/chinese_name/version.rb +3 -0
- data/lib/chinese_name.rb +50 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 701aa195a4cd566f1f885ab9e6a7469bda0832e4
|
4
|
+
data.tar.gz: f105340986e1a9c61fad8bbe12c8a24fe071ddb3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 118cd853dc0e19a0350a3e12de319e1cf13968f2a886cd12c6c727b51c30aafa3deda19dcf209b5e7153d30db70f266952e0f3fadb60c05c2b656a47c4d0b47c
|
7
|
+
data.tar.gz: 9f54bdc9357637549026fe70f4ccea6135293fa7caa5ef3bed44c2147e2e0da10599065d89f480c92e774f69dc86b42509478aafc887032c5f91312eb2f8bb38
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# ChineseName
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chinese_name`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'chinese_name'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install chinese_name
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```
|
26
|
+
require 'chinese_name'
|
27
|
+
|
28
|
+
2.4.0 :001 > g = ChineseName.generate
|
29
|
+
=> #<ChineseName:0x007feed28f8220 @last_name="陈", @first_name="艺天", @full_name="陈艺天">
|
30
|
+
2.4.0 :002 > g.last_name
|
31
|
+
=> "陈"
|
32
|
+
2.4.0 :003 > g.first_name
|
33
|
+
=> "艺天"
|
34
|
+
2.4.0 :004 > g.full_name
|
35
|
+
=> "陈艺天"
|
36
|
+
2.4.0 :005 > g.to_s
|
37
|
+
=> "陈艺天"
|
38
|
+
2.4.0 :006 > "#{g}"
|
39
|
+
=> "陈艺天"
|
40
|
+
```
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/graysonchen/chinese_name.
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chinese_name"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chinese_name/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chinese_name"
|
8
|
+
spec.version = ChineseName::VERSION
|
9
|
+
spec.authors = ["Grayson Chen"]
|
10
|
+
spec.email = ["cgg5207@sina.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generate a Random Chinese Name}
|
13
|
+
spec.description = %q{Generate a Random Chinese Name.}
|
14
|
+
spec.homepage = "https://github.com/graysonchen/chinese_name"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
end
|
data/data/last_name.dat
ADDED
@@ -0,0 +1,434 @@
|
|
1
|
+
艾
|
2
|
+
安
|
3
|
+
敖
|
4
|
+
巴
|
5
|
+
柏
|
6
|
+
白
|
7
|
+
班
|
8
|
+
鲍
|
9
|
+
包
|
10
|
+
暴
|
11
|
+
贝
|
12
|
+
贲
|
13
|
+
毕
|
14
|
+
边
|
15
|
+
卞
|
16
|
+
别
|
17
|
+
邴
|
18
|
+
卜
|
19
|
+
步
|
20
|
+
蔡
|
21
|
+
苍
|
22
|
+
曹
|
23
|
+
岑
|
24
|
+
曾
|
25
|
+
查
|
26
|
+
柴
|
27
|
+
单于
|
28
|
+
常
|
29
|
+
昌
|
30
|
+
巢
|
31
|
+
晁
|
32
|
+
车
|
33
|
+
陈
|
34
|
+
成
|
35
|
+
程
|
36
|
+
池
|
37
|
+
充
|
38
|
+
仇
|
39
|
+
储
|
40
|
+
淳于
|
41
|
+
从
|
42
|
+
崔
|
43
|
+
逮
|
44
|
+
戴
|
45
|
+
单
|
46
|
+
党
|
47
|
+
邓
|
48
|
+
狄
|
49
|
+
刁
|
50
|
+
丁
|
51
|
+
东方
|
52
|
+
董
|
53
|
+
东
|
54
|
+
都
|
55
|
+
钭
|
56
|
+
窦
|
57
|
+
堵
|
58
|
+
杜
|
59
|
+
段
|
60
|
+
鄂
|
61
|
+
范
|
62
|
+
樊
|
63
|
+
房
|
64
|
+
方
|
65
|
+
费
|
66
|
+
酆
|
67
|
+
丰
|
68
|
+
冯
|
69
|
+
凤
|
70
|
+
封
|
71
|
+
伏
|
72
|
+
傅
|
73
|
+
富
|
74
|
+
扶
|
75
|
+
符
|
76
|
+
干
|
77
|
+
甘
|
78
|
+
郜
|
79
|
+
高
|
80
|
+
葛
|
81
|
+
戈
|
82
|
+
耿
|
83
|
+
贡
|
84
|
+
龚
|
85
|
+
公
|
86
|
+
宫
|
87
|
+
巩
|
88
|
+
弓
|
89
|
+
公孙
|
90
|
+
公羊
|
91
|
+
公冶
|
92
|
+
勾
|
93
|
+
谷
|
94
|
+
顾
|
95
|
+
古
|
96
|
+
关
|
97
|
+
管
|
98
|
+
广
|
99
|
+
桂
|
100
|
+
郭
|
101
|
+
国
|
102
|
+
韩
|
103
|
+
杭
|
104
|
+
郝
|
105
|
+
贺
|
106
|
+
何
|
107
|
+
和
|
108
|
+
盍
|
109
|
+
赫连
|
110
|
+
衡
|
111
|
+
弘
|
112
|
+
洪
|
113
|
+
红
|
114
|
+
侯
|
115
|
+
后
|
116
|
+
胡
|
117
|
+
扈
|
118
|
+
花
|
119
|
+
华
|
120
|
+
滑
|
121
|
+
怀
|
122
|
+
宦
|
123
|
+
桓
|
124
|
+
皇甫
|
125
|
+
黄
|
126
|
+
惠
|
127
|
+
霍
|
128
|
+
蓟
|
129
|
+
计
|
130
|
+
冀
|
131
|
+
吉
|
132
|
+
姬
|
133
|
+
季
|
134
|
+
嵇
|
135
|
+
暨
|
136
|
+
汲
|
137
|
+
籍
|
138
|
+
纪
|
139
|
+
贾
|
140
|
+
家
|
141
|
+
简
|
142
|
+
蒋
|
143
|
+
姜
|
144
|
+
江
|
145
|
+
焦
|
146
|
+
解
|
147
|
+
金
|
148
|
+
靳
|
149
|
+
荆
|
150
|
+
井
|
151
|
+
景
|
152
|
+
鞠
|
153
|
+
居
|
154
|
+
阚
|
155
|
+
康
|
156
|
+
柯
|
157
|
+
孔
|
158
|
+
空
|
159
|
+
寇
|
160
|
+
蒯
|
161
|
+
匡
|
162
|
+
夔
|
163
|
+
赖
|
164
|
+
蓝
|
165
|
+
郎
|
166
|
+
劳
|
167
|
+
乐
|
168
|
+
雷
|
169
|
+
冷
|
170
|
+
郦
|
171
|
+
黎
|
172
|
+
利
|
173
|
+
历
|
174
|
+
李
|
175
|
+
连
|
176
|
+
廉
|
177
|
+
梁
|
178
|
+
廖
|
179
|
+
蔺
|
180
|
+
林
|
181
|
+
令狐
|
182
|
+
凌
|
183
|
+
刘
|
184
|
+
柳
|
185
|
+
隆
|
186
|
+
龙
|
187
|
+
娄
|
188
|
+
路
|
189
|
+
陆
|
190
|
+
鲁
|
191
|
+
卢
|
192
|
+
禄
|
193
|
+
栾
|
194
|
+
骆
|
195
|
+
罗
|
196
|
+
吕
|
197
|
+
马
|
198
|
+
麻
|
199
|
+
满
|
200
|
+
茅
|
201
|
+
毛
|
202
|
+
梅
|
203
|
+
蒙
|
204
|
+
孟
|
205
|
+
宓
|
206
|
+
米
|
207
|
+
糜
|
208
|
+
苗
|
209
|
+
乜
|
210
|
+
闵
|
211
|
+
明
|
212
|
+
缪
|
213
|
+
莫
|
214
|
+
万俟
|
215
|
+
慕
|
216
|
+
牧
|
217
|
+
穆
|
218
|
+
慕容
|
219
|
+
那
|
220
|
+
能
|
221
|
+
倪
|
222
|
+
聂
|
223
|
+
宁
|
224
|
+
钮
|
225
|
+
牛
|
226
|
+
农
|
227
|
+
欧
|
228
|
+
欧阳
|
229
|
+
潘
|
230
|
+
逄
|
231
|
+
庞
|
232
|
+
裴
|
233
|
+
蓬
|
234
|
+
彭
|
235
|
+
皮
|
236
|
+
平
|
237
|
+
蒲
|
238
|
+
浦
|
239
|
+
溥
|
240
|
+
濮
|
241
|
+
濮阳
|
242
|
+
齐
|
243
|
+
戚
|
244
|
+
祁
|
245
|
+
钱
|
246
|
+
强
|
247
|
+
乔
|
248
|
+
秦
|
249
|
+
裘
|
250
|
+
邱
|
251
|
+
秋
|
252
|
+
屈
|
253
|
+
曲
|
254
|
+
璩
|
255
|
+
瞿
|
256
|
+
全
|
257
|
+
权
|
258
|
+
阙
|
259
|
+
却
|
260
|
+
冉
|
261
|
+
饶
|
262
|
+
任
|
263
|
+
荣
|
264
|
+
融
|
265
|
+
容
|
266
|
+
戎
|
267
|
+
茹
|
268
|
+
阮
|
269
|
+
芮
|
270
|
+
桑
|
271
|
+
沙
|
272
|
+
山
|
273
|
+
上官
|
274
|
+
尚
|
275
|
+
邵
|
276
|
+
韶
|
277
|
+
厍
|
278
|
+
莘
|
279
|
+
慎
|
280
|
+
沈
|
281
|
+
申
|
282
|
+
申屠
|
283
|
+
盛
|
284
|
+
史
|
285
|
+
师
|
286
|
+
施
|
287
|
+
时
|
288
|
+
石
|
289
|
+
寿
|
290
|
+
舒
|
291
|
+
束
|
292
|
+
殳
|
293
|
+
双
|
294
|
+
水
|
295
|
+
司
|
296
|
+
司空
|
297
|
+
司马
|
298
|
+
司徒
|
299
|
+
宋
|
300
|
+
松
|
301
|
+
苏
|
302
|
+
宿
|
303
|
+
孙
|
304
|
+
索
|
305
|
+
邰
|
306
|
+
太叔
|
307
|
+
谈
|
308
|
+
谭
|
309
|
+
澹台
|
310
|
+
唐
|
311
|
+
汤
|
312
|
+
陶
|
313
|
+
滕
|
314
|
+
田
|
315
|
+
通
|
316
|
+
童
|
317
|
+
屠
|
318
|
+
万
|
319
|
+
汪
|
320
|
+
王
|
321
|
+
蔚
|
322
|
+
隗
|
323
|
+
韦
|
324
|
+
魏
|
325
|
+
卫
|
326
|
+
危
|
327
|
+
闻
|
328
|
+
文
|
329
|
+
温
|
330
|
+
闻人
|
331
|
+
翁
|
332
|
+
沃
|
333
|
+
邬
|
334
|
+
乌
|
335
|
+
伍
|
336
|
+
吴
|
337
|
+
巫
|
338
|
+
武
|
339
|
+
毋
|
340
|
+
郗
|
341
|
+
习
|
342
|
+
奚
|
343
|
+
席
|
344
|
+
夏侯
|
345
|
+
夏
|
346
|
+
咸
|
347
|
+
项
|
348
|
+
向
|
349
|
+
相
|
350
|
+
萧
|
351
|
+
谢
|
352
|
+
辛
|
353
|
+
邢
|
354
|
+
幸
|
355
|
+
熊
|
356
|
+
胥
|
357
|
+
许
|
358
|
+
须
|
359
|
+
徐
|
360
|
+
徐离
|
361
|
+
宣
|
362
|
+
轩辕
|
363
|
+
薛
|
364
|
+
荀
|
365
|
+
阎
|
366
|
+
颜
|
367
|
+
严
|
368
|
+
晏
|
369
|
+
燕
|
370
|
+
阳
|
371
|
+
仰
|
372
|
+
养
|
373
|
+
杨
|
374
|
+
羊
|
375
|
+
姚
|
376
|
+
叶
|
377
|
+
伊
|
378
|
+
易
|
379
|
+
益
|
380
|
+
羿
|
381
|
+
印
|
382
|
+
尹
|
383
|
+
殷
|
384
|
+
应
|
385
|
+
雍
|
386
|
+
尤
|
387
|
+
游
|
388
|
+
尉迟
|
389
|
+
虞
|
390
|
+
郁
|
391
|
+
鱼
|
392
|
+
于
|
393
|
+
余
|
394
|
+
俞
|
395
|
+
喻
|
396
|
+
庾
|
397
|
+
禹
|
398
|
+
宇文
|
399
|
+
袁
|
400
|
+
元
|
401
|
+
越
|
402
|
+
云
|
403
|
+
宰
|
404
|
+
昝
|
405
|
+
臧
|
406
|
+
翟
|
407
|
+
詹
|
408
|
+
湛
|
409
|
+
张
|
410
|
+
章
|
411
|
+
长孙
|
412
|
+
赵
|
413
|
+
甄
|
414
|
+
郑
|
415
|
+
支
|
416
|
+
钟
|
417
|
+
仲
|
418
|
+
终
|
419
|
+
仲孙
|
420
|
+
周
|
421
|
+
诸葛
|
422
|
+
褚
|
423
|
+
诸
|
424
|
+
朱
|
425
|
+
祝
|
426
|
+
竺
|
427
|
+
庄
|
428
|
+
卓
|
429
|
+
訾
|
430
|
+
宗
|
431
|
+
宗政
|
432
|
+
邹
|
433
|
+
祖
|
434
|
+
左
|
data/lib/chinese_name.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "chinese_name/version"
|
2
|
+
|
3
|
+
class ChineseName
|
4
|
+
LAST_NAME_DATA = 'last_name.dat'.freeze
|
5
|
+
|
6
|
+
attr_reader :full_name, :first_name, :last_name
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def generate
|
10
|
+
new
|
11
|
+
end
|
12
|
+
alias_method :g, :generate
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
full_name
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def full_name
|
21
|
+
@full_name ||= "#{last_name}#{first_name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def first_name
|
25
|
+
@first_name ||= generate_first_name.join
|
26
|
+
end
|
27
|
+
|
28
|
+
def last_name
|
29
|
+
@last_name ||= all_last_name[Random.rand(all_last_name.size)]
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_method :to_s, :full_name
|
33
|
+
|
34
|
+
private
|
35
|
+
attr_writer :all_last_name
|
36
|
+
|
37
|
+
def generate_first_name
|
38
|
+
Random.rand(1..2).times.inject([]) { |arr, val| arr << generate_word }
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_word
|
42
|
+
word = (19968..20901).to_a.sample
|
43
|
+
[word.to_s(16)].pack('H*').force_encoding('utf-16be').encode('utf-8')
|
44
|
+
end
|
45
|
+
|
46
|
+
def all_last_name
|
47
|
+
filedata = File.dirname(__FILE__) + "/../data/#{LAST_NAME_DATA}"
|
48
|
+
IO.foreach(filedata).inject([]){ |arr, line| arr << line.strip }
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chinese_name
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grayson Chen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-23 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Generate a Random Chinese Name.
|
56
|
+
email:
|
57
|
+
- cgg5207@sina.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- bin/console
|
67
|
+
- bin/setup
|
68
|
+
- chinese_name.gemspec
|
69
|
+
- data/last_name.dat
|
70
|
+
- lib/chinese_name.rb
|
71
|
+
- lib/chinese_name/version.rb
|
72
|
+
homepage: https://github.com/graysonchen/chinese_name
|
73
|
+
licenses: []
|
74
|
+
metadata:
|
75
|
+
allowed_push_host: https://rubygems.org
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.6.8
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Generate a Random Chinese Name
|
96
|
+
test_files: []
|