chinese_name 0.1.0 → 0.1.1

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: 701aa195a4cd566f1f885ab9e6a7469bda0832e4
4
- data.tar.gz: f105340986e1a9c61fad8bbe12c8a24fe071ddb3
3
+ metadata.gz: a039ded39317622f9783839f83e12e162c9b9132
4
+ data.tar.gz: 77338af02a11908b56ea4439c49b6a1d42dbcc43
5
5
  SHA512:
6
- metadata.gz: 118cd853dc0e19a0350a3e12de319e1cf13968f2a886cd12c6c727b51c30aafa3deda19dcf209b5e7153d30db70f266952e0f3fadb60c05c2b656a47c4d0b47c
7
- data.tar.gz: 9f54bdc9357637549026fe70f4ccea6135293fa7caa5ef3bed44c2147e2e0da10599065d89f480c92e774f69dc86b42509478aafc887032c5f91312eb2f8bb38
6
+ metadata.gz: 04e7846815bd8450924c734639810af31b0d58000974392a72838b7856c3cac38693c0d7a119a247f3412b6219c55d5b75144e788ef721a44eddab6dffe6a698
7
+ data.tar.gz: b4927e478e8a95265ab4551b76664becfbf3d6ac4c5166532b6d8195476726253e35e0c7cbedec097ee404e2b474c429575b4102b2c2b26a9d4c64fdf5fb67d6
data/README.md CHANGED
@@ -39,6 +39,14 @@ require 'chinese_name'
39
39
  => "陈艺天"
40
40
  ```
41
41
 
42
+ by command line
43
+
44
+ ```
45
+ $ rand_chinese_name
46
+ 雷严乒
47
+ ```
48
+
49
+
42
50
  ## Development
43
51
 
44
52
  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.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require File.expand_path('../../lib/chinese_name', __FILE__)
5
+
6
+ STDOUT.puts ChineseName.g
data/lib/chinese_name.rb CHANGED
@@ -26,13 +26,12 @@ class ChineseName
26
26
  end
27
27
 
28
28
  def last_name
29
- @last_name ||= all_last_name[Random.rand(all_last_name.size)]
29
+ @last_name ||= generate_last_name
30
30
  end
31
31
 
32
32
  alias_method :to_s, :full_name
33
33
 
34
34
  private
35
- attr_writer :all_last_name
36
35
 
37
36
  def generate_first_name
38
37
  Random.rand(1..2).times.inject([]) { |arr, val| arr << generate_word }
@@ -43,8 +42,16 @@ class ChineseName
43
42
  [word.to_s(16)].pack('H*').force_encoding('utf-16be').encode('utf-8')
44
43
  end
45
44
 
45
+ def generate_last_name
46
+ rand_name = all_last_name
47
+ rand_name[Random.rand(rand_name.size)]
48
+ end
49
+
46
50
  def all_last_name
47
- filedata = File.dirname(__FILE__) + "/../data/#{LAST_NAME_DATA}"
48
- IO.foreach(filedata).inject([]){ |arr, line| arr << line.strip }
51
+ IO.foreach(file_data).inject([]) { |arr, line| arr << line.strip }
52
+ end
53
+
54
+ def file_data
55
+ File.dirname(__FILE__) + "/../data/#{LAST_NAME_DATA}"
49
56
  end
50
57
  end
@@ -1,3 +1,3 @@
1
1
  class ChineseName
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chinese_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Chen
@@ -64,6 +64,7 @@ files:
64
64
  - README.md
65
65
  - Rakefile
66
66
  - bin/console
67
+ - bin/rand_chinese_name
67
68
  - bin/setup
68
69
  - chinese_name.gemspec
69
70
  - data/last_name.dat