chinese_pinyin 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5befef40dd0b38603ff0ac39ff517b9a953420a9
4
- data.tar.gz: 38697ba8b4544a80090af513de50b9d987c0be22
3
+ metadata.gz: a9f52834ca02f14942f04d417cd8b2ca6d85122c
4
+ data.tar.gz: 9ef90e6814d79ff3d64aa689c83470ecc3a43b32
5
5
  SHA512:
6
- metadata.gz: 0ba7873f62fee5316bcc8ef12f790dffa8b103f93610dbff79a76c8302ae94294394b56186850dc3eea6658909d3c2dbfe8c821953ed8c5321aae531f94f7b2a
7
- data.tar.gz: 854f9df857c1951e732f1ea43a5514a672885482287ce582bf5c02c186509774147ba7de4c825ad0dfaa9b2aaddbd38bc5c64cb82b7e7876b73a61705d7469c7
6
+ metadata.gz: f7cb52230fd8925c6890a29cd66f6f83efc556620ba1fce0ba350a71ee2d3486b85d93b5f33cd651a188f09e9cd36f1ec533c7a2d36d8f2ced02dd32addb4fa9
7
+ data.tar.gz: 5f2aedc8e48604305fad99266729c9aed4aff66ae589c31522c35e2409060df6eff57892e785d3450a8b1d4373c7a41a43f4a2a0f15e4da64e12a7de381fb6d5
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ chinese_pinyin
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/README.md CHANGED
@@ -17,9 +17,10 @@ Usage
17
17
  require 'chinese_pinyin'
18
18
 
19
19
  Pinyin.t('中国') => "zhong guo"
20
- Pinyin.t('中国', '-') => "zhong-guo"
21
- Pinyin.t('中国', '') => "zhongguo"
22
20
  Pinyin.t('你好world') => "ni hao world"
21
+ Pinyin.t('中国', splitter: '-') => "zhong-guo"
22
+ Pinyin.t('中国', splitter: '') => "zhongguo"
23
+ Pinyin.t('中国', tone: true) => "zhong1 guo2"
23
24
 
24
25
  Polyphone Issue
25
26
  ---------------
@@ -32,7 +33,7 @@ by default
32
33
 
33
34
  add file Words.dat
34
35
 
35
- 广州|guang zhou
36
+ 广州|guang3 zhou1
36
37
 
37
38
  set ENV['WORDS_FILE'] for Words.dat
38
39
 
data/data/Mandarin.dat CHANGED
@@ -6534,7 +6534,7 @@
6534
6534
  53F3 YOU4
6535
6535
  53F4 QIU2
6536
6536
  53F5 PO3
6537
- 53F6 XIE2 YE4 SHE4
6537
+ 53F6 YE4 XIE2 SHE4
6538
6538
  53F7 HAO4 HAO2
6539
6539
  53F8 SI1
6540
6540
  53F9 TAN4
@@ -31,7 +31,10 @@ class Pinyin
31
31
  end
32
32
  end
33
33
 
34
- def translate(chars, splitter = ' ')
34
+ def translate(chars, options={})
35
+ splitter = options[:splitter] || ' '
36
+ tone = options[:tone] || false
37
+
35
38
  init_word_table
36
39
  return @words_table[chars].gsub(' ', splitter) if @words_table[chars]
37
40
 
@@ -42,7 +45,9 @@ class Pinyin
42
45
  key = sprintf("%X", char.unpack("U").first)
43
46
  if @table[key]
44
47
  results << splitter if is_english
45
- results << @table[key].chomp.split(' ', 2)[0].slice(0..-2).downcase
48
+ pinyin = @table[key].chomp.split(' ', 2)[0].downcase
49
+ pinyin.chop! unless tone
50
+ results << pinyin
46
51
  results << splitter
47
52
  is_english = false
48
53
  else
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ChinesePinyin
3
- VERSION = "0.4.2"
3
+ VERSION = "0.5.0"
4
4
  end
@@ -6,12 +6,17 @@ ENV["WORDS_FILE"] = File.dirname(__FILE__) + '/Words.dat'
6
6
  class PinyinTest < Test::Unit::TestCase
7
7
  def test_t
8
8
  assert_equal("zhong guo", Pinyin.t('中国'))
9
- assert_equal("zhong-guo", Pinyin.t('中国', '-'))
10
-
11
- assert_equal("huangzhimin", Pinyin.t('黄志敏', ''))
12
-
13
9
  assert_equal("zhong guo english ri", Pinyin.t('中国english日'))
10
+ end
11
+
12
+ def test_t_with_splitter
13
+ assert_equal("zhong-guo", Pinyin.t('中国', splitter: '-'))
14
+ assert_equal("huangzhimin", Pinyin.t('黄志敏', splitter: ''))
15
+ assert_equal("guang-zhou", Pinyin.t('广州', splitter: '-'))
16
+ end
14
17
 
15
- assert_equal("guang-zhou", Pinyin.t('广州', '-'))
18
+ def test_t_with_tone
19
+ assert_equal("zhong1 guo2", Pinyin.t('中国', tone: true))
20
+ assert_equal("huang2 zhi4 min3", Pinyin.t('黄志敏', tone: true))
16
21
  end
17
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chinese_pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-01 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: translate chinese hanzi to pinyin.
14
14
  email:
@@ -18,6 +18,8 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - .gitignore
21
+ - .ruby-gemset
22
+ - .ruby-version
21
23
  - Gemfile
22
24
  - MIT-LICENSE
23
25
  - README.md
@@ -48,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  version: 1.3.6
49
51
  requirements: []
50
52
  rubyforge_project:
51
- rubygems_version: 2.0.0
53
+ rubygems_version: 2.0.3
52
54
  signing_key:
53
55
  specification_version: 4
54
56
  summary: translate chinese hanzi to pinyin.