zhongwen_tools 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -11
- data/Rakefile +39 -0
- data/lib/zhongwen_tools/romanization/detect.rb +4 -3
- data/lib/zhongwen_tools/romanization.rb +2 -0
- data/lib/zhongwen_tools/version.rb +1 -1
- data/test/test_romanization.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36a2e0463a764596b32d674fae73e6d70d5b35b0
|
4
|
+
data.tar.gz: 0695198696d219b954a7842929f2f9a29c27cb30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f3910228f09b9ee451c91d102824b69219bc0a37eec00a8cb1199978ac9c6bfd9e6f528b2dc87ec08dcf1a25171e1de1a008ed58aefa756f45b602e228f916e
|
7
|
+
data.tar.gz: a5e68d15248041507fe3f125f8c2de36e8a60dcd3bf2d16c8a48020b2dbcf770ce3b74ea55b3a68b0e510b1b020c03c006bb0aab4e4b6c765aa09833e8314f9d
|
data/README.md
CHANGED
@@ -15,13 +15,15 @@ Install as a gem
|
|
15
15
|
|
16
16
|
Add the ZhongwenTools component you need to your classes as a module.
|
17
17
|
|
18
|
+
require 'zhongwen_tools/romanization'
|
19
|
+
|
18
20
|
class String
|
19
21
|
include ZhongwenTools::Romanization
|
20
22
|
end
|
21
23
|
|
22
24
|
str = "ni3 hao3" #pinyin with numbers
|
23
25
|
str.to_pinyin #=> "nǐ hǎo"
|
24
|
-
str.
|
26
|
+
str.to_zhuyin_fuhao #=> "ㄋㄧ3 ㄏㄠ3"
|
25
27
|
|
26
28
|
mzd = "Mao Tse-tung"
|
27
29
|
mzd.to_pinyin #=> "Mao Zedong"
|
@@ -37,7 +39,7 @@ ZhongwenTools includes the following Modules:
|
|
37
39
|
2. ZhongwenTools::Numbers - methods for identifying Chinese numbers and for converting to and from Chinese.
|
38
40
|
3. ZhongwenTools::Integer - methods for converting integers into Chinese or pinyin.
|
39
41
|
4. ZhongwenTools::Romanization - methods for converting between Chinese romanization systems.
|
40
|
-
5. ZhongwenTools::Conversion
|
42
|
+
5. ZhongwenTools::Conversion - methods for converting between Chinese scripts.
|
41
43
|
|
42
44
|
|
43
45
|
### Using ZhongwenTools::String
|
@@ -66,7 +68,7 @@ ZhongwenTools includes the following Modules:
|
|
66
68
|
#### The following capitalization methods work for pinyin.
|
67
69
|
require 'zhongwen_tools/string'
|
68
70
|
ZhongwenTools::String.downcase 'Àomén' #=> 'àomén' does pinyin/ lowercase
|
69
|
-
ZhongwenTools::String.upcase 'àomén' #=>
|
71
|
+
ZhongwenTools::String.upcase 'àomén' #=> 'ÀOMÉN'
|
70
72
|
ZhongwenTools::String.capitalize 'àomén' #=> 'Àomén'
|
71
73
|
|
72
74
|
#### Ruby 1.8 safe methods
|
@@ -83,11 +85,11 @@ with multibyte strings in an simple way.
|
|
83
85
|
### Numbers
|
84
86
|
Functions for converting to and from Chinese numbers.
|
85
87
|
|
86
|
-
ZhongwenTools::
|
87
|
-
ZhongwenTools::
|
88
|
-
ZhongwenTools::
|
89
|
-
ZhongwenTools::
|
90
|
-
ZhongwenTools::
|
88
|
+
ZhongwenTools::Numbers.number_to_zht :num, 12000 #=> '一萬二千'
|
89
|
+
ZhongwenTools::Numbers.number_to_zhs :num, 42 #=> '四十二'
|
90
|
+
ZhongwenTools::Numbers.number_to_pyn :num, 42 #=> 'si4-shi2-er4'
|
91
|
+
ZhongwenTools::Numbers.zh_number_to_number '四十二' #=> 42
|
92
|
+
ZhongwenTools::Numbers.number? '四十二' #=> true
|
91
93
|
|
92
94
|
### Integers
|
93
95
|
Monkey-patch your integers for Chinese.
|
@@ -113,7 +115,6 @@ scripts. It **does not convert Chinese characters to pinyin** (see ZhongwenTools
|
|
113
115
|
|
114
116
|
|
115
117
|
str = "ni3 hao3"
|
116
|
-
romanization_system = "pyn" #pyn|wg|yale|bpmf|zhyfh|wade-giles|bopomofo
|
117
118
|
|
118
119
|
str.to_pinyin #=> "nǐ hǎo"
|
119
120
|
str.to_py #=> "nǐ hǎo"
|
@@ -129,12 +130,12 @@ scripts. It **does not convert Chinese characters to pinyin** (see ZhongwenTools
|
|
129
130
|
|
130
131
|
### Conversion
|
131
132
|
Functions for converting between scripts (e.g. traditional Chinese to
|
132
|
-
simplified Chinese) and [TODO] between
|
133
|
+
simplified Chinese) and [TODO] between Chinese and romanization systems (e.g.
|
133
134
|
Chinese to pinyin).
|
134
135
|
Conversion methods must be required explicitly.
|
135
136
|
|
136
137
|
gem 'zhongwen_tools'
|
137
|
-
require 'zhongwen_tools/
|
138
|
+
require 'zhongwen_tools/conversion'
|
138
139
|
|
139
140
|
ZhongwenTools::Conversion.to_zhs '華語' #=> '华语'
|
140
141
|
ZhongwenTools::Conversion.to_zht '华语' #=> '華語'
|
data/Rakefile
CHANGED
@@ -12,3 +12,42 @@ end
|
|
12
12
|
|
13
13
|
desc "Run tests"
|
14
14
|
task :default => :test
|
15
|
+
|
16
|
+
|
17
|
+
def setup_18
|
18
|
+
commands = [
|
19
|
+
'cp Gemfile Gemfile.bak',
|
20
|
+
'mv .ruby-version-1.8.7 .ruby-version',
|
21
|
+
'cp Gemfile.1.8.7 Gemfile',
|
22
|
+
'bundle install --local',
|
23
|
+
]
|
24
|
+
|
25
|
+
commands.each{ |c| `#{ c }` }
|
26
|
+
end
|
27
|
+
|
28
|
+
def teardown_18
|
29
|
+
commands = [
|
30
|
+
'mv .ruby-version .ruby-version-1.8.7 ',
|
31
|
+
'cp Gemfile.bak Gemfile && rm Gemfile.bak',
|
32
|
+
'bundle install --local'
|
33
|
+
]
|
34
|
+
|
35
|
+
commands.each{ |c|
|
36
|
+
`#{ c }`
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
namespace :ruby_18 do
|
42
|
+
desc "Switch to 1.8.7"
|
43
|
+
task :setup do
|
44
|
+
setup_18 if File.exist?('.ruby-version-1.8.7')
|
45
|
+
puts 'Using Ruby 1.8.7'
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Teardown to 1.8.7"
|
49
|
+
task :teardown do
|
50
|
+
teardown_18 unless File.exist?('.ruby-version-1.8.7')
|
51
|
+
puts 'Using Ruby 2.1.0'
|
52
|
+
end
|
53
|
+
end
|
@@ -37,13 +37,14 @@ module ZhongwenTools
|
|
37
37
|
# wg?('pin1-yin1')
|
38
38
|
# # => false
|
39
39
|
# There are some situations where wg == pyn, but there's no way to differentiate the two.
|
40
|
-
def wg?(str = nil)
|
40
|
+
def wg?(str = nil, type = :pyn)
|
41
41
|
#it shouldn't be pyn, but it should be able to conver to pyn
|
42
42
|
str ||= self
|
43
43
|
#easy ones.. is it py? pyn? zyfh? gyrm?
|
44
44
|
#harder ones: is it typy, msp2, yale, wg
|
45
|
-
wg =
|
46
|
-
|
45
|
+
wg = ZhongwenTools::Romanization.to_wade_giles(str, type)
|
46
|
+
# TODO: need to convert string to pyn.
|
47
|
+
pyn = str
|
47
48
|
wg != pyn && wg.gsub(/[1-5]/,'')
|
48
49
|
end
|
49
50
|
end
|
data/test/test_romanization.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zhongwen_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Daniels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|