hz2py 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/hz2py.gemspec +1 -1
- data/lib/elvuel/hz2py.rb +13 -5
- data/spec/hz2py_spec.rb +11 -0
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -33,6 +33,8 @@
|
|
33
33
|
Hz2py.do("你好") => "ni hao"
|
34
34
|
TraditionalAndSimplified.conv_t2s("鳳凰") => "凤凰"
|
35
35
|
TraditionalAndSimplified.conv_s2t("无心插柳柳成阴") => "無心插柳柳成陰"
|
36
|
+
Hz2py.do("你好", :join_with => '-') => "ni-hao"
|
37
|
+
Hz2py.do("愛你", :join_with => '-', :to_simplified => true) => "ai-ni"
|
36
38
|
|
37
39
|
== Test
|
38
40
|
|
data/hz2py.gemspec
CHANGED
data/lib/elvuel/hz2py.rb
CHANGED
@@ -459,14 +459,21 @@ module Elvuel
|
|
459
459
|
"UNKNOWN"
|
460
460
|
end
|
461
461
|
|
462
|
-
def do(s)
|
462
|
+
def do(s, options={})
|
463
463
|
return "" if s.to_s.empty?
|
464
|
-
|
465
|
-
|
466
|
-
|
464
|
+
str = s.to_s
|
465
|
+
delimiter = ' '
|
466
|
+
to_simplified = false
|
467
|
+
if options.is_a?(Hash)
|
468
|
+
delimiter = ' '
|
469
|
+
delimiter = options[:join_with] if options[:join_with]
|
470
|
+
delimiter = ' ' if delimiter.length > 1
|
471
|
+
to_simplified = options[:to_simplified]
|
472
|
+
end
|
473
|
+
str = ::TraditionalAndSimplified.conv_t2s(str) if to_simplified
|
467
474
|
result = ""
|
468
475
|
chrs = []
|
469
|
-
diff_uni_asc(
|
476
|
+
diff_uni_asc(str){ |out| chrs << out }
|
470
477
|
chrs.each_with_index do |item, index|
|
471
478
|
if item.is_a? Array
|
472
479
|
utf8chr = item.collect { |n| n.to_s(16) }.join("")
|
@@ -478,6 +485,7 @@ module Elvuel
|
|
478
485
|
result << item.chr
|
479
486
|
end
|
480
487
|
end
|
488
|
+
result[-1] = "" if result[-1].chr == delimiter
|
481
489
|
result.strip
|
482
490
|
end
|
483
491
|
|
data/spec/hz2py_spec.rb
CHANGED
@@ -37,5 +37,16 @@ describe "Simplified Chinese(简体中文) characters into Chinese pinyin." do
|
|
37
37
|
it "mix all" do
|
38
38
|
Hz2py.do("釹kelv魜瀦汉字,English有意义瀦綉$").should == "UNKNOWN kelv UNKNOWN UNKNOWN han zi ,English you yi yi UNKNOWN UNKNOWN $"
|
39
39
|
end
|
40
|
+
|
41
|
+
it "with specify delimiter" do
|
42
|
+
Hz2py.do("你好", :join_with => '-').should == "ni-hao"
|
43
|
+
Hz2py.do("你好").should == "ni hao"
|
44
|
+
Hz2py.do("黑空寻光", :join_with => '|').should == "hei|kong|xun|guang"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "with Chinese Traditional to Simplified" do
|
48
|
+
Hz2py.do("你好愛", :join_with => '-', :to_simplified => true).should == "ni-hao-ai"
|
49
|
+
Hz2py.do("擔你檳好", :join_with => ' ', :to_simplified => true).should == "dan ni bing hao"
|
50
|
+
end
|
40
51
|
|
41
52
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- elvuel
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-19 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|