hanzi_to_pinyin 0.9.1 → 1.0.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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/VERSION +1 -1
  3. data/lib/hanzi_to_pinyin.rb +23 -4
  4. metadata +17 -29
  5. data/README.rdoc +0 -49
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50844b280e6a5bb7e7ea9a39d67d6f04a58e47db
4
+ data.tar.gz: d5fc6470bb697db12afa7ae3814898e2c989f991
5
+ SHA512:
6
+ metadata.gz: 7e9490c70456937d21ebd983e4f18b89dbfa9795cedefad807deee9a72b3328b2f49fc91d8b2123dc7fb464a7c05cba755051438fe7d4f12dd52c0120597c793
7
+ data.tar.gz: 7692171618b98bd58c2a12239d76525f5c91d9c3177bc838fa486c1eb53fdfc3a5571151d0846a8f3eae57ce4ceafd2f84c0be7ecea381d7a2b9a3c0dd49a8e8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.1
1
+ 1.0.0
@@ -50,11 +50,11 @@ class HanziToPinyin
50
50
  u_str
51
51
  end
52
52
  class << self
53
- alias_method :hanzi_to_pinyin , :hanzi_2_pinyin
53
+ alias_method :hanzi_to_pinyin, :hanzi_2_pinyin
54
54
  end
55
55
 
56
56
  ##
57
- # 多音字,分隔 字字之间;分隔,字母丢弃
57
+ # 多音字,分隔 字字之间;分隔,字母原样保留
58
58
  # 查理Smith => "cha,zha;li;Smith"
59
59
  # 郭轶 => "guo;yi,die"
60
60
  # 我们 => "wo;men"
@@ -89,7 +89,26 @@ class HanziToPinyin
89
89
  @str
90
90
  end
91
91
  class << self
92
- alias_method :hanzi_to_py , :hanzi_2_py
92
+ alias_method :hanzi_to_py, :hanzi_2_py
93
+ end
94
+
95
+ ##
96
+ # 汉字转化为安全的 url
97
+ def self.hanzi_2_url(hanzi)
98
+ hanzi = hanzi.to_s.force_encoding("utf-8")
99
+ arr = []
100
+ hanzi.each_char do |hz|
101
+ if is_hanzi?(hz.ord)
102
+ value = @@py[hz].first
103
+ else
104
+ value = hz.chr
105
+ end
106
+ arr << value
107
+ end
108
+ CGI.escape arr.join('-')
109
+ end
110
+ class << self
111
+ alias_method :hanzi_to_url, :hanzi_2_url
93
112
  end
94
113
 
95
114
  def self.append(values)
@@ -121,7 +140,7 @@ class HanziToPinyin
121
140
  end
122
141
 
123
142
  def self.is_letter?(codepoint)
124
- codepoint >= @@letter_upcase_start && codepoint <= @@letter_upcase_end or codepoint >= @@letter_downcase_start && codepoint <= @@letter_downcase_end
143
+ codepoint >= @@letter_upcase_start && codepoint <= @@letter_upcase_end or codepoint >= @@letter_downcase_start && codepoint <= @@letter_downcase_end
125
144
  end
126
145
 
127
146
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzi_to_pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - wxianfeng
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-24 00:00:00.000000000 Z
11
+ date: 2014-10-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: yamler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: chinese hanzi to pinyin , fetch first letter OR full pinyin, written
@@ -67,40 +60,35 @@ executables: []
67
60
  extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
70
- - README.rdoc
71
- - VERSION
72
63
  - LICENSE.txt
73
64
  - Rakefile
74
- - lib/hanzi_to_pinyin.rb
75
- - lib/data/unicode_to_pinyin.yml
65
+ - VERSION
76
66
  - lib/data/hz2py.json
67
+ - lib/data/unicode_to_pinyin.yml
68
+ - lib/hanzi_to_pinyin.rb
77
69
  homepage: http://github.com/wxianfeng/hanzi_to_pinyin
78
70
  licenses: []
79
- post_install_message: ! " hanzi_to_pinyin is a tool for chinese hanzi to pinyin ,fetch
71
+ metadata: {}
72
+ post_install_message: " hanzi_to_pinyin is a tool for chinese hanzi to pinyin ,fetch
80
73
  first letter OR full pinyin, writen in Ruby.\n \n http://github.com/wxianfeng/hanzi_to_pinyin\n\n
81
74
  \ Enjoy!\n\n wxianfeng (wang.fl1429@gmail.com)\n\n"
82
75
  rdoc_options: []
83
76
  require_paths:
84
77
  - lib
85
78
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
79
  requirements:
88
- - - ! '>='
80
+ - - ">="
89
81
  - !ruby/object:Gem::Version
90
82
  version: '0'
91
- segments:
92
- - 0
93
- hash: -725265272691574212
94
83
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
84
  requirements:
97
- - - ! '>='
85
+ - - ">="
98
86
  - !ruby/object:Gem::Version
99
87
  version: 1.3.6
100
88
  requirements: []
101
89
  rubyforge_project:
102
- rubygems_version: 1.8.24
90
+ rubygems_version: 2.2.2
103
91
  signing_key:
104
- specification_version: 3
92
+ specification_version: 4
105
93
  summary: chinese hanzi to pinyin , fetch first letter OR full pinyin
106
94
  test_files: []
@@ -1,49 +0,0 @@
1
- = hanzi_to_pinyin
2
-
3
- translate chinese to pinyin, fetch first letter OR full pinyin
4
-
5
- == Install
6
-
7
- rails3
8
-
9
- $ gem 'hanzi_to_pinyin', '0.9.0', require: 'hanzi_to_pinyin'
10
- or latest develop version
11
- $ gem 'hanzi_to_pinyin', git: 'git://github.com/wxianfeng/hanzi_to_pinyin.git'
12
- or freeze ref version
13
- $ gem 'hanzi_to_pinyin', git: 'git://github.com/wxianfeng/hanzi_to_pinyin.git', ref: 5fa43b0
14
-
15
- == Usage
16
-
17
- $ HanziToPinyin.hanzi_to_pinyin("中华人民共和国") => "zhrmghg"
18
- $ HanziToPinyin.hanzi_2_pinyin("中华人民共和国") => "zhrmghg"
19
- $ HanziToPinyin.hanzi_to_pinyin("喜欢Ruby") => "xhruby"
20
- $ HanziToPinyin.hanzi_2_pinyin("喜欢Ruby") => "xhruby"
21
-
22
- $ HanziToPinyin.is_hanzi?("你") => true
23
- $ HanziToPinyin.is_hanzi?("a") => false
24
-
25
- # 多音字,分隔 字字之间;分隔,字母数字保留不变
26
- $ HanziToPinyin.hanzi_2_py("我们") => "wo;men"
27
- $ HanziToPinyin.hanzi_2_py("yyf") => "yyf"
28
- $ HanziToPinyin.hanzi_2_py("查理Smith") => "cha,zha;li;Smith"
29
- $ HanziToPinyin.hanzi_2_py("测试1") => "ce;shi;1"
30
- $ HanziToPinyin.hanzi_2_py("测_试") => "ce;_;shi"
31
- $ HanziToPinyin.hanzi_2_py("测-试") => "ce;-;shi"
32
- $ HanziToPinyin.hanzi_2_py(2).should == "2"
33
-
34
- $ HanziToPinyin.is_number?("1".ord) => true
35
- $ HanziToPinyin.is_number?("a".ord) => false
36
-
37
- $ HanziToPinyin.is_underline?("_".ord) => true
38
- $ HanziToPinyin.is_underline?("豆豆") => false
39
- $ HanziToPinyin.is_dash?("-".ord) => true
40
-
41
- == Test
42
- $ rake spec
43
- or spec one case
44
- $ rspec spec/hanzi_to_pinyin/hanzi_to_pinyin_spec.rb -l 21
45
-
46
- == Copyright
47
-
48
- Copyright (c) 2011 wxianfeng. See LICENSE.txt for
49
- further details.