gimei 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +30 -14
- data/gimei.gemspec +1 -0
- data/lib/data/names.yml +13725 -16
- data/lib/gimei.rb +82 -33
- data/lib/gimei/version.rb +1 -1
- data/spec/name_spec.rb +56 -2
- metadata +6 -4
data/lib/gimei.rb
CHANGED
@@ -3,45 +3,44 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
class Gimei
|
5
5
|
NAMES = YAML.load_file(File.expand_path(File.join('..', 'data', 'names.yml'), __FILE__))
|
6
|
+
GENDER = [:male, :female].freeze
|
6
7
|
|
7
|
-
class
|
8
|
-
def
|
9
|
-
|
8
|
+
class << self
|
9
|
+
def male
|
10
|
+
new(:male)
|
11
|
+
end
|
12
|
+
|
13
|
+
def female
|
14
|
+
new(:female)
|
10
15
|
end
|
11
16
|
|
12
17
|
def kanji
|
13
|
-
|
18
|
+
name = new
|
19
|
+
"#{name.last.kanji} #{name.first.kanji}"
|
14
20
|
end
|
15
21
|
|
16
22
|
def hiragana
|
17
|
-
|
23
|
+
name = new
|
24
|
+
"#{name.last.hiragana} #{name.first.hiragana}"
|
18
25
|
end
|
19
26
|
|
20
27
|
def katakana
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
class Last
|
26
|
-
def initialize
|
27
|
-
@name = NAMES['last_name'].sample
|
28
|
-
end
|
29
|
-
|
30
|
-
def kanji
|
31
|
-
@name[0]
|
28
|
+
name = new
|
29
|
+
"#{name.last.katakana} #{name.first.katakana}"
|
32
30
|
end
|
33
31
|
|
34
|
-
def
|
35
|
-
|
32
|
+
def first
|
33
|
+
new.first
|
36
34
|
end
|
37
35
|
|
38
|
-
def
|
39
|
-
|
36
|
+
def last
|
37
|
+
new.last
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
|
-
def initialize
|
44
|
-
@
|
41
|
+
def initialize(gender = nil)
|
42
|
+
@gender = gender || GENDER.sample
|
43
|
+
@first = First.new @gender
|
45
44
|
@last = Last.new
|
46
45
|
end
|
47
46
|
|
@@ -57,6 +56,10 @@ class Gimei
|
|
57
56
|
"#{last.katakana} #{first.katakana}"
|
58
57
|
end
|
59
58
|
|
59
|
+
def to_s
|
60
|
+
kanji
|
61
|
+
end
|
62
|
+
|
60
63
|
def first
|
61
64
|
@first
|
62
65
|
end
|
@@ -65,28 +68,74 @@ class Gimei
|
|
65
68
|
@last
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
def male?
|
72
|
+
@gender == :male
|
73
|
+
end
|
74
|
+
|
75
|
+
def female?
|
76
|
+
@gender == :female
|
77
|
+
end
|
78
|
+
|
79
|
+
class First
|
80
|
+
class << self
|
81
|
+
def male
|
82
|
+
new(:male)
|
83
|
+
end
|
84
|
+
|
85
|
+
def female
|
86
|
+
new(:female)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def initialize(gender = nil)
|
91
|
+
@gender = gender || GENDER.sample
|
92
|
+
@name = NAMES['first_name'][@gender.to_s].sample
|
93
|
+
end
|
94
|
+
|
95
|
+
def male?
|
96
|
+
@gender == :male
|
97
|
+
end
|
98
|
+
|
99
|
+
def female?
|
100
|
+
@gender == :female
|
101
|
+
end
|
102
|
+
|
69
103
|
def kanji
|
70
|
-
name
|
71
|
-
"#{name.last.kanji} #{name.first.kanji}"
|
104
|
+
@name[0]
|
72
105
|
end
|
73
106
|
|
74
107
|
def hiragana
|
75
|
-
name
|
76
|
-
"#{name.last.hiragana} #{name.first.hiragana}"
|
108
|
+
@name[1]
|
77
109
|
end
|
78
110
|
|
79
111
|
def katakana
|
80
|
-
name
|
81
|
-
"#{name.last.katakana} #{name.first.katakana}"
|
112
|
+
@name[2]
|
82
113
|
end
|
83
114
|
|
84
|
-
def
|
85
|
-
|
115
|
+
def to_s
|
116
|
+
kanji
|
86
117
|
end
|
118
|
+
end
|
87
119
|
|
88
|
-
|
89
|
-
|
120
|
+
class Last
|
121
|
+
def initialize
|
122
|
+
@name = NAMES['last_name'].sample
|
123
|
+
end
|
124
|
+
|
125
|
+
def kanji
|
126
|
+
@name[0]
|
127
|
+
end
|
128
|
+
|
129
|
+
def hiragana
|
130
|
+
@name[1]
|
131
|
+
end
|
132
|
+
|
133
|
+
def katakana
|
134
|
+
@name[2]
|
135
|
+
end
|
136
|
+
|
137
|
+
def to_s
|
138
|
+
kanji
|
90
139
|
end
|
91
140
|
end
|
92
141
|
end
|
data/lib/gimei/version.rb
CHANGED
data/spec/name_spec.rb
CHANGED
@@ -2,21 +2,41 @@
|
|
2
2
|
require_relative 'spec_helper'
|
3
3
|
|
4
4
|
describe Gimei do
|
5
|
-
|
5
|
+
describe '.male' do
|
6
|
+
before { @name = Gimei.male }
|
7
|
+
|
8
|
+
it '男性の名前が返ること' do
|
9
|
+
@name.male?.must_equal true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.female' do
|
14
|
+
before { @name = Gimei.female }
|
15
|
+
|
16
|
+
it '女性の名前が返ること' do
|
17
|
+
@name.female?.must_equal true
|
18
|
+
end
|
19
|
+
end
|
6
20
|
|
7
21
|
describe '#kanji' do
|
22
|
+
before { @name = Gimei.new }
|
23
|
+
|
8
24
|
it '全角文字とスペースが返ること' do
|
9
25
|
@name.kanji.must_match /\A[#{Moji.zen}\s]+\z/
|
10
26
|
end
|
11
27
|
end
|
12
28
|
|
13
29
|
describe '#hiragana' do
|
30
|
+
before { @name = Gimei.new }
|
31
|
+
|
14
32
|
it 'ひらがなとスペースが返ること' do
|
15
33
|
@name.hiragana.must_match /\A[\p{hiragana}\s]+\z/
|
16
34
|
end
|
17
35
|
end
|
18
36
|
|
19
37
|
describe '#katakana' do
|
38
|
+
before { @name = Gimei.new }
|
39
|
+
|
20
40
|
it 'カタカナとスペースが返ること' do
|
21
41
|
@name.katakana.must_match /\A[\p{katakana}\s]+\z/
|
22
42
|
end
|
@@ -24,25 +44,53 @@ describe Gimei do
|
|
24
44
|
end
|
25
45
|
|
26
46
|
describe Gimei::First do
|
27
|
-
|
47
|
+
describe '.male' do
|
48
|
+
before { @name = Gimei::First.male }
|
49
|
+
|
50
|
+
it '男性の名前が返ること' do
|
51
|
+
@name.male?.must_equal true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.female' do
|
56
|
+
before { @name = Gimei::First.female }
|
57
|
+
|
58
|
+
it '女性の名前が返ること' do
|
59
|
+
@name.female?.must_equal true
|
60
|
+
end
|
61
|
+
end
|
28
62
|
|
29
63
|
describe '#kanji' do
|
64
|
+
before { @name = Gimei::First.new }
|
65
|
+
|
30
66
|
it '全角文字が返ること' do
|
31
67
|
@name.kanji.must_match /\A#{Moji.zen}+\z/
|
32
68
|
end
|
33
69
|
end
|
34
70
|
|
35
71
|
describe '#hiragana' do
|
72
|
+
before { @name = Gimei::First.new }
|
73
|
+
|
36
74
|
it 'ひらがなが返ること' do
|
37
75
|
@name.hiragana.must_match /\A\p{hiragana}+\z/
|
38
76
|
end
|
39
77
|
end
|
40
78
|
|
41
79
|
describe '#katakana' do
|
80
|
+
before { @name = Gimei::First.new }
|
81
|
+
|
42
82
|
it 'カタカナが返ること' do
|
43
83
|
@name.katakana.must_match /\A\p{katakana}+\z/
|
44
84
|
end
|
45
85
|
end
|
86
|
+
|
87
|
+
describe '#to_s' do
|
88
|
+
before { @name = Gimei::First.new }
|
89
|
+
|
90
|
+
it '全角文字が返ること' do
|
91
|
+
@name.to_s.must_match /\A#{Moji.zen}+\z/
|
92
|
+
end
|
93
|
+
end
|
46
94
|
end
|
47
95
|
|
48
96
|
describe Gimei::Last do
|
@@ -65,5 +113,11 @@ describe Gimei::Last do
|
|
65
113
|
@name.katakana.must_match /\A\p{katakana}+\z/
|
66
114
|
end
|
67
115
|
end
|
116
|
+
|
117
|
+
describe '#to_s' do
|
118
|
+
it '全角文字が返ること' do
|
119
|
+
@name.to_s.must_match /\A#{Moji.zen}+\z/
|
120
|
+
end
|
121
|
+
end
|
68
122
|
end
|
69
123
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- willnet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
63
|
- .travis.yml
|
64
|
+
- CHANGELOG.md
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
@@ -72,7 +73,8 @@ files:
|
|
72
73
|
- spec/name_spec.rb
|
73
74
|
- spec/spec_helper.rb
|
74
75
|
homepage: https://github.com/willnet/gimei
|
75
|
-
licenses:
|
76
|
+
licenses:
|
77
|
+
- MIT
|
76
78
|
metadata: {}
|
77
79
|
post_install_message:
|
78
80
|
rdoc_options: []
|
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
version: '0'
|
91
93
|
requirements: []
|
92
94
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.0.
|
95
|
+
rubygems_version: 2.0.3
|
94
96
|
signing_key:
|
95
97
|
specification_version: 4
|
96
98
|
summary: random Japanese name generator. support kanji, hiragana, and katakana
|