zhongwen_tools 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36a2e0463a764596b32d674fae73e6d70d5b35b0
4
- data.tar.gz: 0695198696d219b954a7842929f2f9a29c27cb30
3
+ metadata.gz: 0cbbd4c2a34b34b4a989f68c60d95b03581b8c95
4
+ data.tar.gz: 7c5500e886bd0a24733b0cb4822b08a16b88cd28
5
5
  SHA512:
6
- metadata.gz: 4f3910228f09b9ee451c91d102824b69219bc0a37eec00a8cb1199978ac9c6bfd9e6f528b2dc87ec08dcf1a25171e1de1a008ed58aefa756f45b602e228f916e
7
- data.tar.gz: a5e68d15248041507fe3f125f8c2de36e8a60dcd3bf2d16c8a48020b2dbcf770ce3b74ea55b3a68b0e510b1b020c03c006bb0aab4e4b6c765aa09833e8314f9d
6
+ metadata.gz: 208dc99b54380cf448be2c35b2a20bb47a5e2b3b537f18fde291a653962297ce093266739ae8546952e126184b2cea0a3a9b3fbb9eae99383e7f380e2033055b
7
+ data.tar.gz: 1048a0cfbb2077702a99a1582db7576053ac28108326c47d420aabbd5cb934f90278a2c372b01591d544f2e76373539601747fd1b6a62447f82cab056e618585
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.0
6
+ - 2.1.1
7
7
 
8
8
  matrix:
9
9
  include:
data/README.md CHANGED
@@ -11,6 +11,18 @@ Install as a gem
11
11
 
12
12
  $ [sudo] gem install zhongwen_tools
13
13
 
14
+
15
+ Zhongwen Tools is a set of modules that makes working with Chinese
16
+ easier. It includes the following:
17
+
18
+ 1. ZhongwenTools::String - deals with strings that are Chinese or pinyin.
19
+ 2. ZhongwenTools::Numbers - identifies Chinese numbers and converts numbers to and from Chinese.
20
+ 3. ZhongwenTools::Integer - converts integers into Chinese or pinyin.
21
+ 4. ZhongwenTools::Romanization - converts converting between Chinese romanization systems like Pinyin and Wade-Giles.
22
+ 5. ZhongwenTools::Conversion - converts between Chinese scripts.
23
+
24
+
25
+
14
26
  ## Usage
15
27
 
16
28
  Add the ZhongwenTools component you need to your classes as a module.
@@ -22,74 +34,131 @@ Add the ZhongwenTools component you need to your classes as a module.
22
34
  end
23
35
 
24
36
  str = "ni3 hao3" #pinyin with numbers
25
- str.to_pinyin #=> "nǐ hǎo"
26
- str.to_zhuyin_fuhao #=> "ㄋㄧ3 ㄏㄠ3"
37
+ str.to_pinyin
38
+ #=> " hǎo"
39
+
40
+ str.to_zhuyin_fuhao
41
+ #=> "ㄋㄧ3 ㄏㄠ3"
27
42
 
28
43
  mzd = "Mao Tse-tung"
29
- mzd.to_pinyin #=> "Mao Zedong"
44
+ mzd.to_pinyin
45
+ #=> "Mao Zedong"
30
46
 
31
- Or you can require the components you want
47
+ Or require the components you want.
32
48
 
33
49
  require 'zhongwen_tools/numbers'
34
- ZhongwenTools::Numbers.to_pyn '一百二十' #=> 'yi1-bai2-er4-shi2'
35
-
36
- ZhongwenTools includes the following Modules:
37
-
38
- 1. ZhongwenTools::String - methods for dealing with strings with Chinese and pinyin.
39
- 2. ZhongwenTools::Numbers - methods for identifying Chinese numbers and for converting to and from Chinese.
40
- 3. ZhongwenTools::Integer - methods for converting integers into Chinese or pinyin.
41
- 4. ZhongwenTools::Romanization - methods for converting between Chinese romanization systems.
42
- 5. ZhongwenTools::Conversion - methods for converting between Chinese scripts.
43
50
 
51
+ ZhongwenTools::Numbers.to_pyn '一百二十'
52
+ #=> 'yi1-bai2-er4-shi2'
44
53
 
45
54
  ### Using ZhongwenTools::String
55
+ Zhongwen Tools has string methods for detecting different string formats
56
+ and for converting to and from halfwidth, fullwidth, and utf-8 codepoints.
57
+
46
58
  require 'zhongwen_tools/string'
47
- ZhongwenTools::String.ascii? 'hello' #=> true #non-multibyle strings
48
- ZhongwenTools::String.multibyte? '中文' #=> true #multibtye strings
49
- ZhongwenTools::String.halfwidth? 'hello' #=> true
50
- ZhongwenTools::String.fullwidth? 'hello' #=> true
51
- ZhongwenTools::String.to_halfwidth 'hello' #=> 'hello'
52
59
 
53
- ZhongwenTools::String.uri_encode '我太懒' #=> '%E6%88%91%E5%A4%AA%E6%87%92'
54
- ZhongwenTools::String.to_codepoint '中文' #=> '\u4e2d\u6587'
55
- ZhongwenTools::String.from_codepoint '\u4e2d\u6587' #=> '中文' #converts string from a utf-8 codepoint.
60
+ ZhongwenTools::String.ascii? 'hello'
61
+ #=> true #non-multibyle strings
62
+
63
+ ZhongwenTools::String.multibyte? '中文'
64
+ #=> true #multibtye strings
65
+
66
+ ZhongwenTools::String.halfwidth? 'hello'
67
+ #=> true
68
+
69
+ ZhongwenTools::String.fullwidth? 'hello'
70
+ #=> true
71
+
72
+ ZhongwenTools::String.to_halfwidth 'hello'
73
+ #=> 'hello'
56
74
 
57
- ZhongwenTools::String.has_zh? '1月' #=> true
58
- ZhongwenTools::String.zh? '1月' #=> false #(The string can't be mixed.)
75
+ ZhongwenTools::String.uri_encode '我太懒'
76
+ #=> '%E6%88%91%E5%A4%AA%E6%87%92'
59
77
 
60
- ZhongwenTools::String.has_zh_punctuation? '你在哪里?' #=> true
61
- ZhongwenTools::String.strip_zh_punctuation? '你在哪里?' #=> '你在哪里'
78
+ ZhongwenTools::String.to_codepoint '中文'
79
+ #=> '\u4e2d\u6587'
80
+
81
+ ZhongwenTools::String.from_codepoint '\u4e2d\u6587'
82
+ #=> '中文' #converts string from a utf-8 codepoint.
83
+
84
+
85
+ #### Detecting Chinese or Chinese Punctuation.
86
+ Zhongwen Tools can also detect if a string is or has Chinese or Chinese
87
+ punctuation.
88
+
89
+ require 'zhongwen_tools/string'
90
+ ZhongwenTools::String.has_zh? '1月'
91
+ #=> true
92
+
93
+ ZhongwenTools::String.zh? '1月'
94
+ #=> false #(The string can't be mixed.)
95
+
96
+ ZhongwenTools::String.has_zh_punctuation? '你在哪里?'
97
+ #=> true
98
+ ZhongwenTools::String.strip_zh_punctuation? '你在哪里?'
99
+ #=> '你在哪里'
100
+
101
+ #### Converting between Traditional and Simplified Chinese
102
+ By requiring conversion module, ZhongwenTools::String gets some
103
+ convenience methods for converting to and from traditional and
104
+ simplified Chinese.
62
105
 
63
106
  require 'zhongwen_tools/conversion'
64
- ZhongwenTools::String.zhs? '中国' #=> true
65
- ZhongwenTools::String.zht? '中国' #=> false
66
107
 
108
+ ZhongwenTools::String.zhs? '中国'
109
+ #=> true
110
+ ZhongwenTools::String.zht? '中国'
111
+ #=> false
112
+
113
+ #### Romanization
114
+ By requiring the romanization module ZhongwenTools::String gets some
115
+ convenience methods for dealing with romanization.
116
+ require 'zhongwen_tools/romanziation'
117
+
118
+ ZhongwenTools::String.to_pinyin 'ni3 hao3'
119
+ #=> "nǐ hǎo"
67
120
 
68
- #### The following capitalization methods work for pinyin.
121
+
122
+ #### Pinyin-safe String Methods
123
+ The following capitalization methods work for pinyin.
69
124
  require 'zhongwen_tools/string'
70
- ZhongwenTools::String.downcase 'Àomén' #=> 'àomén' does pinyin/ lowercase
71
- ZhongwenTools::String.upcase 'àomén' #=> 'ÀOMÉN'
72
- ZhongwenTools::String.capitalize 'àomén' #=> 'Àomén'
125
+
126
+ ZhongwenTools::String.downcase 'Àomén'
127
+ #=> 'àomén' does pinyin/ lowercase
128
+ ZhongwenTools::String.upcase 'àomén'
129
+ #=> 'ÀOMÉN'
130
+ ZhongwenTools::String.capitalize 'àomén'
131
+ #=> 'Àomén'
73
132
 
74
133
  #### Ruby 1.8 safe methods
75
134
  Zhongwen Tools is tested on every ruby since 1.8.7 and lets you deal
76
- with multibyte strings in an simple way.
135
+ with multibyte strings in an simple, consistent fashion regardless of
136
+ which ruby version you are using.
77
137
 
78
138
  require 'zhongwen_tools/string'
79
- ZhongwenTools::String.chars '中文' #=> ['中','文']
80
- ZhongwenTools::String.size '中文' #=> 2
81
- ZhongwenTools::String.reverse '中文' #=> '文中'
82
- ZhongwenTools::String.to_utf8 '\x{D6D0}\x{CEC4}' => '中文'
139
+ ZhongwenTools::String.chars '中文'
140
+ #=> ['','文']
141
+ ZhongwenTools::String.size '中文'
142
+ #=> 2
143
+ ZhongwenTools::String.reverse '中文'
144
+ #=> '文中'
145
+ ZhongwenTools::String.to_utf8 '\x{D6D0}\x{CEC4}'
146
+ #=> '中文'
83
147
 
84
148
 
85
149
  ### Numbers
86
150
  Functions for converting to and from Chinese numbers.
87
151
 
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
152
+ ZhongwenTools::Numbers.number_to_zht :num, 12000
153
+ #=> '一萬二千'
154
+ ZhongwenTools::Numbers.number_to_zhs :num, 42
155
+ #=> '四十二'
156
+ ZhongwenTools::Numbers.number_to_pyn :num, 42
157
+ #=> 'si4-shi2-er4'
158
+ ZhongwenTools::Numbers.zh_number_to_number '四十二'
159
+ #=> 42
160
+ ZhongwenTools::Numbers.number? '四十二'
161
+ #=> true
93
162
 
94
163
  ### Integers
95
164
  Monkey-patch your integers for Chinese.
@@ -98,8 +167,10 @@ Monkey-patch your integers for Chinese.
98
167
  include ZhongwenTools::Integer
99
168
  end
100
169
 
101
- 12.to_pinyin #=> 'shi2-er4'
102
- 12.to_zht #=> '十二'
170
+ 12.to_pinyin
171
+ #=> 'shi2-er4'
172
+ 12.to_zht
173
+ #=> '十二'
103
174
 
104
175
 
105
176
  ### Romanization
@@ -116,17 +187,25 @@ scripts. It **does not convert Chinese characters to pinyin** (see ZhongwenTools
116
187
 
117
188
  str = "ni3 hao3"
118
189
 
119
- str.to_pinyin #=> "nǐ hǎo"
120
- str.to_py #=> "nǐ hǎo"
121
- str.to_pyn #=> "ni3 hao3"
122
-
123
- str.to_wg #=> "ni3 hao3" #Wade-Giles
124
- str.to_bpmf #=> "ㄋㄧ3 ㄏㄠ3" #Zhuyin Fuhao, a.k.a. Bopomofo
125
- str.to_yale #=> "ni3 hau3"
190
+ str.to_pinyin
191
+ #=> "nǐ hǎo"
192
+ str.to_py
193
+ #=> "nǐ hǎo"
194
+ str.to_pyn
195
+ #=> "ni3 hao3"
196
+
197
+ str.to_wg
198
+ #=> "ni3 hao3" #Wade-Giles
199
+ str.to_bpmf
200
+ #=> "ㄋㄧ3 ㄏㄠ3" #Zhuyin Fuhao, a.k.a. Bopomofo
201
+ str.to_yale
202
+ #=> "ni3 hau3"
126
203
  str.to_typy
127
204
 
128
- str.pyn? #=> true
129
- str.wg? #=> true #(There can be overlap between Wade-Giles and Pinyin)
205
+ str.pyn?
206
+ #=> true
207
+ str.wg?
208
+ #=> true #(There can be overlap between Wade-Giles and Pinyin)
130
209
 
131
210
  ### Conversion
132
211
  Functions for converting between scripts (e.g. traditional Chinese to
@@ -137,11 +216,16 @@ Conversion methods must be required explicitly.
137
216
  gem 'zhongwen_tools'
138
217
  require 'zhongwen_tools/conversion'
139
218
 
140
- ZhongwenTools::Conversion.to_zhs '華語' #=> '华语'
141
- ZhongwenTools::Conversion.to_zht '华语' #=> '華語'
142
- ZhongwenTools::Conversion.to_zhtw '方便面' #=> '泡麵'
143
- ZhongwenTools::Conversion.to_zhhk '方便面' #=> '即食麵'
144
- ZhongwenTools::Conversion.to_zhcn '即食麵' #=> '方便面'
219
+ ZhongwenTools::Conversion.to_zhs '華語'
220
+ #=> '华语'
221
+ ZhongwenTools::Conversion.to_zht '华语'
222
+ #=> '華語'
223
+ ZhongwenTools::Conversion.to_zhtw '方便面'
224
+ #=> '泡麵'
225
+ ZhongwenTools::Conversion.to_zhhk '方便面'
226
+ #=> '即食麵'
227
+ ZhongwenTools::Conversion.to_zhcn '即食麵'
228
+ #=> '方便面'
145
229
 
146
230
 
147
231
  ## TODO
@@ -1,6 +1,7 @@
1
1
  #encoding: utf-8
2
2
  module ZhongwenTools
3
3
  module Numbers
4
+ extend self
4
5
 
5
6
  NUMBER_MULTIPLES = '拾十百佰千仟仟万萬亿億'
6
7
 
@@ -1,3 +1,3 @@
1
1
  module ZhongwenTools
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
data/test/test_numbers.rb CHANGED
@@ -12,11 +12,16 @@ class TestNumbers < Minitest::Test
12
12
  #your function sucks dick man
13
13
  @numbers.each do |num|
14
14
  number = zh_number_to_number num[:zh]
15
- binding.pry if num[:en] != number
16
15
  assert_equal num[:en], number
17
16
  end
18
17
  end
19
18
 
19
+ def test_class_methods
20
+ i = rand @numbers.length
21
+ number = @numbers[i]
22
+ assert_equal number[:en], ZhongwenTools::Numbers.zh_number_to_number(number[:zh])
23
+ end
24
+
20
25
  def test_convert_to_traditional_number
21
26
  zhs = @numbers[0][:zh]
22
27
  zht = number_to_zht :zht, zhs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhongwen_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Daniels