hanzi_to_pinyin 0.6.1 → 0.7.0

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.
Files changed (4) hide show
  1. data/README.rdoc +4 -3
  2. data/VERSION +1 -1
  3. data/lib/hanzi_to_pinyin.rb +11 -3
  4. metadata +27 -5
@@ -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.6.0' , require: 'hanzi_to_pinyin'
9
+ $ gem 'hanzi_to_pinyin' , '0.6.1' , 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
@@ -27,12 +27,14 @@ or freeze ref version
27
27
  $ HanziToPinyin.hanzi_2_py("查理Smith") => "cha,zha;li"
28
28
  $ HanziToPinyin.hanzi_2_py("测试1") => "ce;shi;1"
29
29
  $ HanziToPinyin.hanzi_2_py("测_试") => "ce;_;shi"
30
+ $ HanziToPinyin.hanzi_2_py("测-试").should == "ce;-;shi"
30
31
 
31
32
  $ HanziToPinyin.is_number?("1".ord) => true
32
33
  $ HanziToPinyin.is_number?("a".ord) => false
33
34
 
34
35
  $ HanziToPinyin.is_underline?("_".ord).should be_true
35
36
  $ HanziToPinyin.is_underline?("豆豆").should be_false
37
+ $ HanziToPinyin.is_dash?("-".ord).should be_true
36
38
 
37
39
  == Test
38
40
  $ rake spec
@@ -42,5 +44,4 @@ or spec one case
42
44
  == Copyright
43
45
 
44
46
  Copyright (c) 2011 wxianfeng. See LICENSE.txt for
45
- further details.
46
-
47
+ further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -1,5 +1,6 @@
1
1
  # encoding:utf-8
2
- require "json"
2
+ require 'json'
3
+ require 'yaml'
3
4
 
4
5
  class HanziToPinyin
5
6
 
@@ -17,6 +18,9 @@ class HanziToPinyin
17
18
  # 下划线(10进制)
18
19
  @@underline = 95
19
20
 
21
+ # 横线(10进制)
22
+ @@dash = 45
23
+
20
24
  # 汉字 unicode 编码(16进制)
21
25
  @@unicode = YAML.load(IO.read File.expand_path("../data/unicode_to_pinyin.yml",__FILE__))
22
26
  @@py = ::JSON.parse(IO.read File.expand_path("../data/hz2py.json",__FILE__))
@@ -44,7 +48,7 @@ class HanziToPinyin
44
48
  end
45
49
 
46
50
  ##
47
- # 只处理汉字和数字和_ 多音字,分隔 字字之间;分隔
51
+ # 只处理汉字和数字和_,- 多音字,分隔 字字之间;分隔
48
52
  # 查理Smith => "cha,zha;li"
49
53
  # 郭轶 => "guo;yi,die"
50
54
  # 我们 => "wo;men"
@@ -53,7 +57,7 @@ class HanziToPinyin
53
57
  hanzi = hanzi.force_encoding("utf-8")
54
58
  str = ''
55
59
  hanzi.each_char do |hz|
56
- if is_number?(hz.ord) or is_underline?(hz.ord)
60
+ if is_number?(hz.ord) or is_underline?(hz.ord) or is_dash?(hz.ord)
57
61
  if str.length == 0
58
62
  str << hz.chr
59
63
  else
@@ -105,5 +109,9 @@ class HanziToPinyin
105
109
  def self.is_underline?(underline_codepoint)
106
110
  underline_codepoint == @@underline
107
111
  end
112
+
113
+ def self.is_dash?(codepoint)
114
+ codepoint == @@dash
115
+ end
108
116
 
109
117
  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.6.1
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000 +08:00
12
+ date: 2012-04-17 00:00:00.000000000 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ requirement: &87605570 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *87605570
26
+ - !ruby/object:Gem::Dependency
27
+ name: yamler
28
+ requirement: &87604140 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *87604140
15
37
  - !ruby/object:Gem::Dependency
16
38
  name: rspec
17
- requirement: &75722920 !ruby/object:Gem::Requirement
39
+ requirement: &87603270 !ruby/object:Gem::Requirement
18
40
  none: false
19
41
  requirements:
20
42
  - - ! '>='
@@ -22,7 +44,7 @@ dependencies:
22
44
  version: '0'
23
45
  type: :development
24
46
  prerelease: false
25
- version_requirements: *75722920
47
+ version_requirements: *87603270
26
48
  description: chinese hanzi to pinyin , fetch first letter OR full pinyin, written
27
49
  in Ruby.
28
50
  email:
@@ -55,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
77
  version: '0'
56
78
  segments:
57
79
  - 0
58
- hash: 801955645
80
+ hash: -743416909
59
81
  required_rubygems_version: !ruby/object:Gem::Requirement
60
82
  none: false
61
83
  requirements: