japanese_names 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/japanese_names/parser.rb +8 -4
- data/lib/japanese_names/version.rb +1 -1
- data/spec/unit/parser_spec.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Y2RiZjRlZTEzMDQ4NjJhZmQyMTg4YmI5ZjE0M2IyNGU5MGRlNGU1YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWVlN2EzY2NmYWNiMzA1ZThjZGQxYjUxY2MwZTE2YzRhZGZiNDU5ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmViZDBkNzFhNjU5OGE0NGNlZDAzMzUzMTAwZjBmOWI3OWE3ZjdhZjYwYTI4
|
10
|
+
MDZlODJkNTA2ZjQ5ZTU2M2E2YjEwNzY1Mjk2MDVlOWMyNWU4NzA4ZTlkNmFl
|
11
|
+
MTlkZjdhNjhhY2NiZDQ3MTU3MjQ3MTMzMmVjMTE2YTg5NmM4YzM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTVmZWI4ZGUxNDQ5ZDA5ZTZhYjRkZjcxMzU3ZDQxNmQ2YTYwMmQyZTk3Njgz
|
14
|
+
NzUxYzdlOThkNTgwM2I4NGQxODY5OWMxNGM3OGIwODViYmU1ZjZjYmIzZWNi
|
15
|
+
YjhhOWIzMDM2ZjFhNDhlMjZlM2I3MjFjYjdlNGYxYmU0NzM0NGE=
|
@@ -18,6 +18,8 @@ module JapaneseNames
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def split_giv(kanji, kana)
|
21
|
+
return nil unless kanji && kana
|
22
|
+
kanji, kana = kanji.strip, kana.strip
|
21
23
|
dict = Enamdict.match(kanji: window_right(kanji))
|
22
24
|
dict.sort!{|x,y| y[0].size <=> x[0].size}
|
23
25
|
kana_match = nil
|
@@ -27,6 +29,8 @@ module JapaneseNames
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def split_fam(kanji, kana)
|
32
|
+
return nil unless kanji && kana
|
33
|
+
kanji, kana = kanji.strip, kana.strip
|
30
34
|
dict = Enamdict.match(kanji: window_left(kanji))
|
31
35
|
dict.sort!{|x,y| y[0].size <=> x[0].size}
|
32
36
|
kana_match = nil
|
@@ -61,16 +65,16 @@ module JapaneseNames
|
|
61
65
|
|
62
66
|
# Given a String, returns an array of progressively smaller substrings anchored on the left side.
|
63
67
|
#
|
64
|
-
# Example: window_left("
|
68
|
+
# Example: window_left("abcd") #=> ["abcd", "abc", "ab", "a"]
|
65
69
|
def window_left(str)
|
66
|
-
(0
|
70
|
+
(0...str.size).to_a.reverse.map{|i| str[0..i]}
|
67
71
|
end
|
68
72
|
|
69
73
|
# Given a String, returns an array of progressively smaller substrings anchored on the right side.
|
70
74
|
#
|
71
|
-
# Example: window_right("
|
75
|
+
# Example: window_right("abcd") #=> ["abcd", "bcd", "cd", "d"]
|
72
76
|
def window_right(str)
|
73
|
-
(
|
77
|
+
(0...str.size).map{|i| str[i..-1]}
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
data/spec/unit/parser_spec.rb
CHANGED
@@ -32,11 +32,22 @@ describe JapaneseNames::Parser do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
[['XXX','XXX','XXX',
|
35
|
+
[['XXX','XXX','XXX','XXX']].each do |kanji_fam, kanji_giv, kana_fam, kana_giv|
|
36
36
|
it "should return nil for invalid name #{kanji_fam+kanji_giv} #{kana_fam+kana_giv}" do
|
37
37
|
result = subject.split(kanji_fam+kanji_giv, kana_fam+kana_giv)
|
38
38
|
result.should be_nil
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
it 'should strip leading/trailing whitespace' do
|
43
|
+
subject.split(' 上原望 ', ' ウエハラノゾミ ').should eq [['上原','望'],['ウエハラ','ノゾミ']]
|
44
|
+
subject.split_giv(' 上原望 ', ' ウエハラノゾミ ').should eq [['上原','望'],['ウエハラ','ノゾミ']]
|
45
|
+
subject.split_fam(' 上原望 ', ' ウエハラノゾミ ').should eq [['上原','望'],['ウエハラ','ノゾミ']]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should return nil for nil input' do
|
49
|
+
subject.split(nil, 'ウエハラノゾミ').should be_nil
|
50
|
+
subject.split('上原望', nil).should be_nil
|
51
|
+
end
|
41
52
|
end
|
42
53
|
end
|