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.
@@ -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
@@ -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'