hanzi_to_pinyin 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +9 -7
  2. data/VERSION +1 -1
  3. data/lib/hanzi_to_pinyin.rb +10 -4
  4. metadata +3 -3
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ translate chinese to pinyin, fetch first letter OR full pinyin
6
6
 
7
7
  rails3
8
8
 
9
- $ gem 'hanzi_to_pinyin', '0.8.0', require: 'hanzi_to_pinyin'
9
+ $ gem 'hanzi_to_pinyin', '0.9.0', require: 'hanzi_to_pinyin'
10
10
  or latest develop version
11
11
  $ gem 'hanzi_to_pinyin', git: 'git://github.com/wxianfeng/hanzi_to_pinyin.git'
12
12
  or freeze ref version
@@ -22,19 +22,21 @@ or freeze ref version
22
22
  $ HanziToPinyin.is_hanzi?("你") => true
23
23
  $ HanziToPinyin.is_hanzi?("a") => false
24
24
 
25
- # 多音字,分隔 字字之间;分隔,字母丢弃
25
+ # 多音字,分隔 字字之间;分隔,字母数字保留不变
26
26
  $ HanziToPinyin.hanzi_2_py("我们") => "wo;men"
27
- $ HanziToPinyin.hanzi_2_py("查理Smith") => "cha,zha;li"
27
+ $ HanziToPinyin.hanzi_2_py("yyf") => "yyf"
28
+ $ HanziToPinyin.hanzi_2_py("查理Smith") => "cha,zha;li;Smith"
28
29
  $ HanziToPinyin.hanzi_2_py("测试1") => "ce;shi;1"
29
30
  $ HanziToPinyin.hanzi_2_py("测_试") => "ce;_;shi"
30
- $ HanziToPinyin.hanzi_2_py("测-试").should == "ce;-;shi"
31
+ $ HanziToPinyin.hanzi_2_py("测-试") => "ce;-;shi"
32
+ $ HanziToPinyin.hanzi_2_py(2).should == "2"
31
33
 
32
34
  $ HanziToPinyin.is_number?("1".ord) => true
33
35
  $ HanziToPinyin.is_number?("a".ord) => false
34
36
 
35
- $ HanziToPinyin.is_underline?("_".ord).should be_true
36
- $ HanziToPinyin.is_underline?("豆豆").should be_false
37
- $ HanziToPinyin.is_dash?("-".ord).should be_true
37
+ $ HanziToPinyin.is_underline?("_".ord) => true
38
+ $ HanziToPinyin.is_underline?("豆豆") => false
39
+ $ HanziToPinyin.is_dash?("-".ord) => true
38
40
 
39
41
  == Test
40
42
  $ rake spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.9.0
@@ -55,30 +55,36 @@ class HanziToPinyin
55
55
 
56
56
  ##
57
57
  # 多音字,分隔 字字之间;分隔,字母丢弃
58
- # 查理Smith => "cha,zha;li"
58
+ # 查理Smith => "cha,zha;li;Smith"
59
59
  # 郭轶 => "guo;yi,die"
60
60
  # 我们 => "wo;men"
61
61
  # 宗志强 => "zong;zhi;qiang,jiang"
62
62
  def self.hanzi_2_py(hanzi)
63
- hanzi = hanzi.force_encoding("utf-8")
63
+ hanzi = hanzi.to_s.force_encoding("utf-8")
64
64
  @str = ''
65
+ index = 0
65
66
  hanzi.each_char do |hz|
66
67
  if is_hanzi?(hz.ord)
67
68
  values = @@py[hz]
68
69
  append(values)
69
- elsif is_letter?(hz.ord)
70
- next
71
70
  else
72
71
  if @str.length == 0
73
72
  @str << hz.chr
74
73
  else
75
74
  if @str[-1] == ";"
76
75
  @str << hz.chr
76
+ elsif @str[-1] =~ /[a-z]/i
77
+ if is_hanzi?(hanzi[index-1].ord)
78
+ @str << ";#{hz.chr}"
79
+ else
80
+ @str << hz.chr
81
+ end
77
82
  else
78
83
  @str << ";#{hz.chr}"
79
84
  end
80
85
  end
81
86
  end
87
+ index += 1
82
88
  end
83
89
  @str
84
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzi_to_pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-14 00:00:00.000000000 Z
12
+ date: 2012-12-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  segments:
92
92
  - 0
93
- hash: 292557973814545694
93
+ hash: -4254974955912349874
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements: