zhongwen_tools 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zhongwen_tools/romanization.rb +5 -2
- data/lib/zhongwen_tools/version.rb +1 -1
- data/test/test_romanization.rb +5 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 922f41394b5974c16b42521d9a203ac31876272e
|
4
|
+
data.tar.gz: 8390da15a9a05b60703c661ec117b77da2a52edb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b14a2962e68f69dfa4fbeb20731ed1c067f0110eefd7711c09f4bce2f4450a71fbad9912eb68154415ea106a263c4b79a173f68c142da66bffae52f6e9cb5a
|
7
|
+
data.tar.gz: c5d4b6cfe2d3be093b6852d89fecfbf6b995818f6f134341b920372cbb8c9d93d604fff9df2c2cfd49694238ec6ba991304b38960c7c1d29ab275072f61a9e17
|
@@ -80,11 +80,12 @@ module ZhongwenTools
|
|
80
80
|
def _to_romanization str, to, from
|
81
81
|
convert_to = _set_type to
|
82
82
|
convert_from = _set_type from
|
83
|
-
tokens = str.split(
|
83
|
+
tokens = str.split(/[ \-]/).uniq
|
84
84
|
replacements = tokens.collect do |t|
|
85
85
|
# non_romanization = t.match(/[1-5](.*)/)[-1]
|
86
86
|
search = t.gsub(/[1-5].*/,'')
|
87
87
|
begin
|
88
|
+
capitalized = t.downcase != t
|
88
89
|
if from.nil? || convert_from.nil?
|
89
90
|
replace = ROMANANIZATIONS_TABLE.find{|x| x.values.include? t.downcase.gsub(/[1-5].*/,'')}[convert_to.to_sym]
|
90
91
|
else
|
@@ -93,6 +94,8 @@ module ZhongwenTools
|
|
93
94
|
rescue => e#rescue when the converter meets something it doesn't recognize
|
94
95
|
replace = search
|
95
96
|
end
|
97
|
+
|
98
|
+
replace = replace.capitalize if capitalized
|
96
99
|
str = str.gsub(search, replace)
|
97
100
|
end
|
98
101
|
str
|
@@ -112,7 +115,7 @@ module ZhongwenTools
|
|
112
115
|
#need to convert pinyin to pyn
|
113
116
|
raise NotImplementedError, 'method not implemented'
|
114
117
|
end
|
115
|
-
_to_romanization
|
118
|
+
_to_romanization(str, to, from).gsub('-','')
|
116
119
|
else
|
117
120
|
if from == :pyn
|
118
121
|
_to_romanization str, to, from
|
data/test/test_romanization.rb
CHANGED
@@ -31,15 +31,15 @@ class TestRomanization < Minitest::Test
|
|
31
31
|
assert_equal 'ㄋㄧ3 ㄏㄠ3', @str.to_bopomofo
|
32
32
|
assert_equal 'ㄋㄧ3 ㄏㄠ3', @str.to_zhuyin
|
33
33
|
assert_equal 'ㄇㄠ2 ㄗㄜ2 ㄉㄨㄥ1', @mzd.to_zhuyin_fuhao
|
34
|
-
|
35
|
-
|
34
|
+
assert_equal 'ㄑㄧㄥ3 ㄏㄨㄟ2ㄉㄚ2 ㄨㄛ3 ㄉㄜ5 ㄨㄣ4ㄊㄧ2 .', @sent.to_zhuyin
|
35
|
+
assert_equal 'ㄇㄠ2 ㄗㄜ2ㄉㄨㄥ1', @mzd2.to_zhuyin_fuhao
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_wade_giles
|
39
39
|
assert_equal 'kuo1', 'guo1'.to_wg
|
40
40
|
assert_equal 'chung1 kuo2', 'zhong1 guo2'.to_wg
|
41
|
-
|
42
|
-
|
41
|
+
assert_equal 'Mao2 Tse2 tung1', @mzd.to_wg
|
42
|
+
assert_equal 'Mao2 Tse2-tung1', @mzd2.to_wade_giles
|
43
43
|
end
|
44
44
|
|
45
45
|
#def test_mspy2
|
@@ -71,5 +71,6 @@ class TestRomanization < Minitest::Test
|
|
71
71
|
@mzd = 'Mao2 Ze2 dong1'
|
72
72
|
@mzd2 = 'Mao2 Ze2-dong1'
|
73
73
|
@py = 'nǐ hǎo'
|
74
|
+
@sent = 'Qing3 hui2-da2 wo3 de5 wen4-ti2 .'
|
74
75
|
end
|
75
76
|
end
|