hanzi_to_pinyin 0.2.0 → 0.3.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.
- metadata +14 -18
- data/.gitignore +0 -20
- data/Gemfile +0 -5
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -24
- data/Rakefile +0 -13
- data/VERSION +0 -1
- data/hanzi_to_pinyin.gemspec +0 -36
- data/lib/data/unicode_to_pinyin.yml +0 -25478
- data/lib/hanzi_to_pinyin.rb +0 -32
- data/spec/spec_helper.rb +0 -13
data/lib/hanzi_to_pinyin.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class HanziToPinyin
|
2
|
-
|
3
|
-
# Unicode中汉字开始点
|
4
|
-
@@hanzi_unicode_start=19968
|
5
|
-
# Unicode中汉字的结束点
|
6
|
-
@@hanzi_unicode_end=40869
|
7
|
-
# 汉字 unicode 编码(16进制)
|
8
|
-
@@unicode = YAML.load(IO.read File.expand_path("../data/unicode_to_pinyin.yml",__FILE__))
|
9
|
-
|
10
|
-
def self.hanzi_2_pinyin(hanzi)
|
11
|
-
hanzi = hanzi.force_encoding("utf-8")
|
12
|
-
u_str = ''
|
13
|
-
hanzi.each_codepoint { |c|
|
14
|
-
if is_hanzi?(c)
|
15
|
-
unicode = c.to_s(16).upcase
|
16
|
-
u_str << @@unicode[unicode]
|
17
|
-
else
|
18
|
-
if c == 45 # -
|
19
|
-
u_str << "_"
|
20
|
-
else
|
21
|
-
u_str << c.chr.downcase
|
22
|
-
end
|
23
|
-
end
|
24
|
-
}
|
25
|
-
u_str
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.is_hanzi?(hanzi_codepoint)
|
29
|
-
hanzi_codepoint>=@@hanzi_unicode_start&&hanzi_codepoint<=@@hanzi_unicode_end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
|
11
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
12
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
-
require 'hanzi_to_pinyin'
|