chinese_pinyin 0.6.1.1 → 0.7.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: b715ff1242e797d9c74fa97c6f171c399f011fe5
4
- data.tar.gz: 3ede774cf53500643729e4437d1dbdc27bf133f7
3
+ metadata.gz: 536820144ef1284e973430e684d7511a5f4a21b5
4
+ data.tar.gz: 235adb7c959a9c0a01e3d2234ac1abf75fefc79a
5
5
  SHA512:
6
- metadata.gz: 952ef367abdd377365510ef7e9f7d80d0fddd475cf32c0311e06ab5177507a5e5e0d6852da3ac4d9ec0e301882b33c8aeb82c6f2a503a04c1c4a2e51010fc2d3
7
- data.tar.gz: e5c52df59b7ca6650696ae98f02e459ede81e9edc79d80f3974e0240490445d82a9278e7529ad35f6fa181c6ebd4faaf04f5f3561ca0d793a82d26d4117c0e01
6
+ metadata.gz: fcf06b8a4f831aac76d9ecd772b972f05b855e70fab14fca2d40aa5f6504fdd4045a56bc5a84dc22e1bb0cf857d72b6e6f0ce8133f37d95dae78f2f05e360330
7
+ data.tar.gz: 526585ebbd8b4ecc987f31d5c591cbc8352708df9af9601f1a01c8ae8bb22f06da2da73e6017f2fbbd6f8b71e747009e16f2a6c88b0c0d215fe61c4222268b95
@@ -1 +1 @@
1
- ruby-2.0.0
1
+ ruby-2.2.0
data/Gemfile CHANGED
@@ -3,3 +3,4 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rake'
6
+ gem 'test-unit' # ruby 2.1.5以后版本的标准库中不包含'test-unit'
data/README.md CHANGED
@@ -21,6 +21,7 @@ Usage
21
21
  Pinyin.t('中国', splitter: '-') => "zhong-guo"
22
22
  Pinyin.t('中国', splitter: '') => "zhongguo"
23
23
  Pinyin.t('中国', tone: true) => "zhong1 guo2"
24
+ Pinyin.t('中国', tonemarks: true) => "zhōng guó"
24
25
 
25
26
  Polyphone Issue
26
27
  ---------------
@@ -4,6 +4,16 @@ $KCODE = 'u' if RUBY_VERSION =~ /1\.8/
4
4
  require 'chinese_pinyin/version'
5
5
 
6
6
  class Pinyin
7
+
8
+ TONE_MARK = {
9
+ a: %w(a ā á ǎ à),
10
+ o: %w(o ō ó ǒ ò),
11
+ e: %w(e ē é ě è),
12
+ i: %w(i ī í ǐ ì),
13
+ u: %w(u ū ú ǔ ù),
14
+ v: %w(ü ǖ ǘ ǚ ǜ)
15
+ }
16
+
7
17
  class <<self
8
18
  attr_accessor :table
9
19
  attr_accessor :ruby2
@@ -40,9 +50,10 @@ class Pinyin
40
50
  end
41
51
 
42
52
  def translate(chars, options={})
43
- splitter = options.fetch(:splitter, ' ')
44
- tone = options.fetch(:tone, false)
45
- camel = options.fetch(:camelcase, false)
53
+ splitter = options.fetch(:splitter, ' ')
54
+ tonemarks = options.fetch(:tonemarks, false)
55
+ tone = options.fetch(:tone, false || tonemarks)
56
+ camel = options.fetch(:camelcase, false)
46
57
 
47
58
  init_word_table
48
59
  results = @words_table[chars]
@@ -71,6 +82,13 @@ class Pinyin
71
82
  pinyin.downcase! unless @ruby2
72
83
  pinyin.chop! unless tone
73
84
  pinyin.capitalize! if camel
85
+ if tonemarks
86
+ tone_index = pinyin[-1].to_i
87
+ pinyin = pinyin[0...-1]
88
+ %w(a o e i u v).each { |v|
89
+ break if pinyin.tr! v, TONE_MARK[v.to_sym][tone_index]
90
+ }
91
+ end
74
92
 
75
93
  results << pinyin
76
94
  results << splitter
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ChinesePinyin
3
- VERSION = "0.6.1.1"
3
+ VERSION = "0.7.0"
4
4
  end
@@ -38,4 +38,9 @@ class PinyinTest < Test::Unit::TestCase
38
38
  def test_t_with_chinese_punctuation
39
39
  assert_equal("ce-shi-yi-xia-Think-diff", Pinyin.t('测试一下,Think diff', splitter: '-'))
40
40
  end
41
+
42
+ def test_t_with_tonemarks
43
+ assert_equal('zhōng guó', Pinyin.t('中国', tonemarks: true))
44
+ assert_equal('běi jīng', Pinyin.t('北京', tonemarks: true))
45
+ end
41
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chinese_pinyin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-24 00:00:00.000000000 Z
12
+ date: 2015-03-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: translate chinese hanzi to pinyin.
15
15
  email:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: 1.3.6
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.2.0.rc.1
56
+ rubygems_version: 2.4.5
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: translate chinese hanzi to pinyin.