law_number_switch 0.0.6 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/law_number_switch.rb +28 -17
- 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: dd1e84ac20704a5a62c43dc2881055a5cb1725ec
|
4
|
+
data.tar.gz: 7370f86b8adfdd952bd2ab7da4cfb3117155a324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa35045b82933263c9b37c5928b35e25a25d28017d3c6830043b3974b17d5c4e2fe38b3b335a53fb7b7fc43d823d727595131dd6fa5d0bd0967230e8a1bab3c3
|
7
|
+
data.tar.gz: 96216c2b988dcdf918ca9fc67bf6eeb8fa607f6acdca8b860cfd4c8fb7057c237dafa848a2618288cf49c9623ac4c849c192b36335bfb49562623b87e3aa4006
|
data/lib/law_number_switch.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module LawNumberSwitch
|
2
2
|
CN_NUMBER = ["", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ]
|
3
3
|
CN_UNIT = ["", "十", "百", "千" ]
|
4
|
-
CN_UNIT_BIG = ["", "萬", "億" ]
|
4
|
+
CN_UNIT_BIG = ["", "萬", "億", "兆" ]
|
5
5
|
|
6
6
|
def to_cn_number
|
7
7
|
string = self.to_cn_number_oneten
|
@@ -47,7 +47,6 @@ module LawNumberSwitch
|
|
47
47
|
|
48
48
|
rst_arr << number + unit + unit_big
|
49
49
|
end
|
50
|
-
|
51
50
|
rst_arr.reverse.join
|
52
51
|
end
|
53
52
|
|
@@ -68,12 +67,30 @@ module LawNumberSwitch
|
|
68
67
|
end
|
69
68
|
|
70
69
|
CN_NUMS = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"]
|
71
|
-
CN_DECS = ["十", "百", "千", "萬", "億"]
|
72
|
-
CN_NUMS_MAP = {'〇' => 0, '一' => 1, '二' => 2, '三' => 3, '四' => 4, '五' => 5,
|
73
|
-
'六' => 6, '七' => 7, '八' => 8, '九' => 9, '零' => 0
|
74
|
-
|
70
|
+
CN_DECS = ["十", "百", "千", "萬", "億", "兆", "拾", "佰", '仟']
|
71
|
+
CN_NUMS_MAP = {'〇' => 0, '一' => 1, '二' => 2, '兩' => 2, '三' => 3, '四' => 4, '五' => 5,
|
72
|
+
'六' => 6, '七' => 7, '八' => 8, '九' => 9, '零' => 0, '壹' => 1, '貳' => 2,
|
73
|
+
'參' => 3, '肆' => 4, '伍' => 5, '陸' => 6, '柒' => 7, '捌' => 8, '玖' => 9, '○' => 0}
|
74
|
+
CN_DECS_MAP = {'個' => 1, '十' => 10, '百' => 100, '千' => 1000, '萬' => 10000,
|
75
|
+
'億' => 100000000, '兆' => 100000000000, '拾' => 10, '佰' => 100, '仟' => 1000}
|
75
76
|
|
76
77
|
def to_number
|
78
|
+
output = ''
|
79
|
+
string = ''
|
80
|
+
self.scan(/./) do |c|
|
81
|
+
if CN_NUMS_MAP[c] || CN_DECS_MAP[c]
|
82
|
+
string += c
|
83
|
+
else
|
84
|
+
c = string.to_number_case + c unless string.empty?
|
85
|
+
output += c
|
86
|
+
string = ''
|
87
|
+
end
|
88
|
+
end
|
89
|
+
output += string.to_number_case unless string.empty?
|
90
|
+
output
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_number_case
|
77
94
|
string = self
|
78
95
|
CN_DECS.each do |d|
|
79
96
|
no_ten = d + '十'
|
@@ -82,17 +99,12 @@ module LawNumberSwitch
|
|
82
99
|
string = self.gsub(Regexp.new(no_ten), one_ten)
|
83
100
|
end
|
84
101
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
def to_number_oneten
|
92
|
-
if self =~ /之/
|
93
|
-
dash_number
|
102
|
+
string = string.gsub(/(?:○|〇)/, "零").gsub(/(?:零|○|〇)(?:十|拾)/, "一十")
|
103
|
+
.gsub(/廿/, "二十").gsub(/卅/, "三十")
|
104
|
+
if string =~ /之/
|
105
|
+
string.dash_number
|
94
106
|
else
|
95
|
-
int_number
|
107
|
+
string.int_number
|
96
108
|
end
|
97
109
|
end
|
98
110
|
|
@@ -158,7 +170,6 @@ module LawNumberSwitch
|
|
158
170
|
w_arr << b_w
|
159
171
|
w_arr.join
|
160
172
|
end
|
161
|
-
|
162
173
|
end
|
163
174
|
|
164
175
|
String.include LawNumberSwitch
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: law_number_switch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GaussJay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Swith chinese law number string and arabic numerals string to each other.
|
14
14
|
email:
|