japanese_names 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmIzYzM1YThjMjlkZGNmMWM4Y2NjNmZkZWY2Y2EzMWQ3MmQyMTkyNg==
4
+ Y2RiZjRlZTEzMDQ4NjJhZmQyMTg4YmI5ZjE0M2IyNGU5MGRlNGU1YQ==
5
5
  data.tar.gz: !binary |-
6
- NzRkNTIxOWIzZDY4NzA2MmQyYjIxNmExMTI5ZmY0ZWUxMGNlMTdjNw==
6
+ OWVlN2EzY2NmYWNiMzA1ZThjZGQxYjUxY2MwZTE2YzRhZGZiNDU5ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTdlMGM4OGRmOGNiMTQzNWFiMDkxZmFkZDQ1MzJhZmI5YjEzZmIzZTgxMDIw
10
- ZWU5OWU0N2NjMWUxYTQwMzBiYTc3N2QyNThhZDM1NmYwZjk1MDc1ODhkODA2
11
- MWIyM2ZlMjIzOGFjNTA2NWNiYmExMTUxNGRmZGE4ZTcwMmQ0ODU=
9
+ YmViZDBkNzFhNjU5OGE0NGNlZDAzMzUzMTAwZjBmOWI3OWE3ZjdhZjYwYTI4
10
+ MDZlODJkNTA2ZjQ5ZTU2M2E2YjEwNzY1Mjk2MDVlOWMyNWU4NzA4ZTlkNmFl
11
+ MTlkZjdhNjhhY2NiZDQ3MTU3MjQ3MTMzMmVjMTE2YTg5NmM4YzM=
12
12
  data.tar.gz: !binary |-
13
- MmQ0MGJiNDA0OGJmNDk1ZmNmNmIyYjNmM2Q1NjYxN2JmNjBiOWZiZjRkMDBj
14
- YmVhYTdkNDQ1NGNhNDIyMDgyODU4YTFlYWJiOTlhZjM3ODEwOGJlOGI3ZWFi
15
- ODhkODc4ZWM2MWExZmZkYmJhYzk2Y2RlNGM5ZGE0N2YxZDc1Mzg=
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("abcde") #=> ["abcd", "abc", "ab", "a"]
68
+ # Example: window_left("abcd") #=> ["abcd", "abc", "ab", "a"]
65
69
  def window_left(str)
66
- (0..str.size-2).to_a.reverse.map{|i| str[0..i]}
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("abcde") #=> ["bcde", "cde", "de", "e"]
75
+ # Example: window_right("abcd") #=> ["abcd", "bcd", "cd", "d"]
72
76
  def window_right(str)
73
- (1..str.size-1).map{|i| str[i..-1]}
77
+ (0...str.size).map{|i| str[i..-1]}
74
78
  end
75
79
  end
76
80
  end
@@ -2,5 +2,5 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  module JapaneseNames
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -32,11 +32,22 @@ describe JapaneseNames::Parser do
32
32
  end
33
33
  end
34
34
 
35
- [['XXX','XXX','XXX', 'XXX']].each do |kanji_fam, kanji_giv, kana_fam, kana_giv|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: japanese_names
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnny Shields