chinese_pinyin 0.6.1.1 → 0.7.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -0
- data/README.md +1 -0
- data/lib/chinese_pinyin.rb +21 -3
- data/lib/chinese_pinyin/version.rb +1 -1
- data/test/chinese_pinyin_test.rb +5 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 536820144ef1284e973430e684d7511a5f4a21b5
|
|
4
|
+
data.tar.gz: 235adb7c959a9c0a01e3d2234ac1abf75fefc79a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fcf06b8a4f831aac76d9ecd772b972f05b855e70fab14fca2d40aa5f6504fdd4045a56bc5a84dc22e1bb0cf857d72b6e6f0ce8133f37d95dae78f2f05e360330
|
|
7
|
+
data.tar.gz: 526585ebbd8b4ecc987f31d5c591cbc8352708df9af9601f1a01c8ae8bb22f06da2da73e6017f2fbbd6f8b71e747009e16f2a6c88b0c0d215fe61c4222268b95
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-2.
|
|
1
|
+
ruby-2.2.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/lib/chinese_pinyin.rb
CHANGED
|
@@ -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
|
|
44
|
-
|
|
45
|
-
|
|
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
|
data/test/chinese_pinyin_test.rb
CHANGED
|
@@ -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.
|
|
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:
|
|
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.
|
|
56
|
+
rubygems_version: 2.4.5
|
|
57
57
|
signing_key:
|
|
58
58
|
specification_version: 4
|
|
59
59
|
summary: translate chinese hanzi to pinyin.
|