number_to_cn 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +7 -0
- data/README.md +17 -1
- data/lib/.DS_Store +0 -0
- data/lib/ext/float_ext.rb +5 -0
- data/lib/ext/integer_ext.rb +1 -1
- data/lib/number_to_cn/methods.rb +47 -31
- data/lib/number_to_cn/version.rb +1 -1
- data/lib/number_to_cn.rb +2 -1
- data/spec/number_to_cn_spec.rb +12 -1
- metadata +6 -3
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
so simple to use:
|
22
|
+
|
23
|
+
require 'number_to_cn'
|
24
|
+
|
25
|
+
123.to_cn_words #=>
|
26
|
+
|
27
|
+
123.to_cn_clearly #=>
|
28
|
+
|
29
|
+
0.1.to_cn_words #=>
|
30
|
+
|
31
|
+
0.to_cn_words #=>
|
22
32
|
|
23
33
|
## Contributing
|
24
34
|
|
@@ -27,3 +37,9 @@ TODO: Write usage instructions here
|
|
27
37
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
39
|
5. Create new Pull Request
|
40
|
+
=======
|
41
|
+
number_to_cn
|
42
|
+
============
|
43
|
+
|
44
|
+
transfer number into chinese characters
|
45
|
+
>>>>>>> 6447d6a2f58a576d6d94a6ed5896b33cf1a43204
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/ext/integer_ext.rb
CHANGED
data/lib/number_to_cn/methods.rb
CHANGED
@@ -1,43 +1,59 @@
|
|
1
1
|
#encoding:utf-8
|
2
2
|
module NumberToCn
|
3
|
-
|
4
3
|
CN_T_TRANS = [ "", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" ]
|
4
|
+
CN_T_TRANS_WITH_ZERO = [ "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾" ]
|
5
5
|
CN_T_POSITION = [ "", "拾", "佰", "仟" ]
|
6
|
-
CN_T_BIG = [ "", "萬", "亿"]
|
6
|
+
CN_T_BIG = [ "", "萬", "亿", "萬"]
|
7
7
|
|
8
8
|
def to_cn_words
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
9
|
+
if self.class == Fixnum
|
10
|
+
return "零" if self == 0
|
11
|
+
num_arr = self.to_s.split("").reverse
|
12
|
+
rst_arr = []
|
13
|
+
|
14
|
+
writable = -1
|
15
|
+
#1:0是需要写的。
|
16
|
+
#0:0不需要写;
|
17
|
+
#-1:全不需要写;
|
18
|
+
|
19
|
+
num_arr.each_with_index do |value, index|
|
20
|
+
writable = -1 if index%4 == 0
|
21
|
+
|
22
|
+
cc = (index % 4 == 0) ? CN_T_BIG[index/4] : ""
|
23
|
+
aa = CN_T_TRANS[value.to_i]
|
24
|
+
|
25
|
+
if value.to_i == 0
|
26
|
+
writable = (writable == 1) ? 0 : -1
|
27
|
+
else
|
28
|
+
writable = 1
|
29
|
+
end
|
30
|
+
|
31
|
+
if writable == 1
|
32
|
+
bb = CN_T_POSITION[index%4]
|
33
|
+
elsif writable == -1
|
34
|
+
bb = ""
|
35
|
+
else
|
36
|
+
bb = "零"
|
37
|
+
end
|
38
|
+
|
39
|
+
rst_arr << aa + bb + cc
|
27
40
|
end
|
28
41
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
bb = "零"
|
35
|
-
end
|
36
|
-
|
37
|
-
rst_arr << aa + bb + cc
|
42
|
+
rst_arr.reverse.join
|
43
|
+
elsif self.class == Float
|
44
|
+
before_point = self.to_s.split(".")[0]
|
45
|
+
after_point = self.to_s.split(".")[1]
|
46
|
+
"#{before_point.to_i.to_cn_words}点#{after_point.to_i.to_cn_clearly}"
|
38
47
|
end
|
39
|
-
|
40
|
-
rst_arr.reverse.join
|
41
48
|
end
|
42
49
|
|
50
|
+
def to_cn_clearly
|
51
|
+
digits_arr = self.to_s.split('')
|
52
|
+
rst = ""
|
53
|
+
digits_arr.map do |d|
|
54
|
+
rst << CN_T_TRANS_WITH_ZERO[d.to_i]
|
55
|
+
end
|
56
|
+
rst
|
57
|
+
end
|
58
|
+
|
43
59
|
end
|
data/lib/number_to_cn/version.rb
CHANGED
data/lib/number_to_cn.rb
CHANGED
data/spec/number_to_cn_spec.rb
CHANGED
@@ -3,7 +3,18 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe NumberToCn do
|
5
5
|
it "should go works" do
|
6
|
-
(2203.to_cn_words).should
|
6
|
+
(2203.to_cn_words).should eq("贰仟贰佰零叁")
|
7
7
|
end
|
8
|
+
|
9
|
+
it "worked for zero" do
|
10
|
+
(0.to_cn_words).should eq("零")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "worked for float" do
|
14
|
+
((33.0).to_cn_words).should eq("叁拾叁点零")
|
15
|
+
end
|
8
16
|
|
17
|
+
it "works in clear transfer" do
|
18
|
+
(203.to_cn_clearly).should eq("贰零叁")
|
19
|
+
end
|
9
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: number_to_cn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: simply gem for put digits number into cn.
|
15
15
|
email:
|
@@ -18,11 +18,14 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- .DS_Store
|
21
22
|
- .gitignore
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE
|
24
25
|
- README.md
|
25
26
|
- Rakefile
|
27
|
+
- lib/.DS_Store
|
28
|
+
- lib/ext/float_ext.rb
|
26
29
|
- lib/ext/integer_ext.rb
|
27
30
|
- lib/number_to_cn.rb
|
28
31
|
- lib/number_to_cn/methods.rb
|
@@ -50,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
53
|
version: '0'
|
51
54
|
requirements: []
|
52
55
|
rubyforge_project:
|
53
|
-
rubygems_version: 1.8.
|
56
|
+
rubygems_version: 1.8.24
|
54
57
|
signing_key:
|
55
58
|
specification_version: 3
|
56
59
|
summary: ! '123.to_cn_words #'
|