Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stevendaniels committed Mar 3, 2014
2 parents 206bd2f + 4b2fda6 commit c14cc68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/zhongwen_tools/romanization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ def _to_pinyin str
def _to_romanization str, to, from
convert_to = _set_type to
convert_from = _set_type from
tokens = str.split(' ').uniq
tokens = str.split(/[ \-]/).uniq
replacements = tokens.collect do |t|
# non_romanization = t.match(/[1-5](.*)/)[-1]
search = t.gsub(/[1-5].*/,'')
begin
capitalized = t.downcase != t
if from.nil? || convert_from.nil?
replace = ROMANANIZATIONS_TABLE.find{|x| x.values.include? t.downcase.gsub(/[1-5].*/,'')}[convert_to.to_sym]
else
Expand All @@ -93,6 +94,8 @@ def _to_romanization str, to, from
rescue => e#rescue when the converter meets something it doesn't recognize
replace = search
end

replace = replace.capitalize if capitalized
str = str.gsub(search, replace)
end
str
Expand All @@ -112,7 +115,7 @@ def _convert_romanization str, to, from
#need to convert pinyin to pyn
raise NotImplementedError, 'method not implemented'
end
_to_romanization str, to, from
_to_romanization(str, to, from).gsub('-','')
else
if from == :pyn
_to_romanization str, to, from
Expand Down
2 changes: 1 addition & 1 deletion lib/zhongwen_tools/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ZhongwenTools
VERSION = "0.3.4"
VERSION = "0.3.5"
end
9 changes: 5 additions & 4 deletions test/test_romanization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def test_zhuyin_fuhao
assert_equal 'ㄋㄧ3 ㄏㄠ3', @str.to_bopomofo
assert_equal 'ㄋㄧ3 ㄏㄠ3', @str.to_zhuyin
assert_equal 'ㄇㄠ2 ㄗㄜ2 ㄉㄨㄥ1', @mzd.to_zhuyin_fuhao
#skip
#assert_equal 'ㄇㄠ2 ㄗㄜ2ㄉㄨㄥ1', @mzd2.to_zhuyin_fuhao
assert_equal 'ㄑㄧㄥ3 ㄏㄨㄟ2ㄉㄚ2 ㄨㄛ3 ㄉㄜ5 ㄨㄣ4ㄊㄧ2 .', @sent.to_zhuyin
assert_equal 'ㄇㄠ2 ㄗㄜ2ㄉㄨㄥ1', @mzd2.to_zhuyin_fuhao
end

def test_wade_giles
assert_equal 'kuo1', 'guo1'.to_wg
assert_equal 'chung1 kuo2', 'zhong1 guo2'.to_wg
#assert_equal 'Mao2 Tse2 tung1', @mzd.to_wg
#assert_equal 'Mao2 Tse2 tung1', @mzd.to_wade_giles
assert_equal 'Mao2 Tse2 tung1', @mzd.to_wg
assert_equal 'Mao2 Tse2-tung1', @mzd2.to_wade_giles
end

#def test_mspy2
Expand Down Expand Up @@ -71,5 +71,6 @@ def setup
@mzd = 'Mao2 Ze2 dong1'
@mzd2 = 'Mao2 Ze2-dong1'
@py = 'nǐ hǎo'
@sent = 'Qing3 hui2-da2 wo3 de5 wen4-ti2 .'
end
end

0 comments on commit c14cc68

Please sign in to comment.