law_number_switch 0.0.10 → 0.0.17
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.
- checksums.yaml +4 -4
- data/lib/law_number_switch.rb +22 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad8e0cca43174c63459f6343b01d41fdfdf606a
|
4
|
+
data.tar.gz: 2ca9fab8b41549c2ce4fd1af309dc7d8c0bfc669
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b183fbf7f903bfc8e0d201b68f77fe55c634aa16a1e00ee5c9ebd01ad1f6840c48ff895236b2441d9995bcb2c2b279faca5eb37d9adf2d733a96ff6d83bd92
|
7
|
+
data.tar.gz: aef3eeffd4e2b0c0318dd2dc297107b1bbb36c5de65d38e249a47b2d3ccce3079c9c8d09c00ad74fa2ea8fa5858d20af92b20c9b6ad3f205e1c77eae3f240b93
|
data/lib/law_number_switch.rb
CHANGED
@@ -78,7 +78,7 @@ module LawNumberSwitch
|
|
78
78
|
output = ''
|
79
79
|
string = ''
|
80
80
|
self.scan(/./) do |c|
|
81
|
-
if CN_NUMS_MAP[c] || CN_DECS_MAP[c]
|
81
|
+
if CN_NUMS_MAP[c] || CN_DECS_MAP[c] || c == '之'
|
82
82
|
string += c
|
83
83
|
else
|
84
84
|
c = string.to_number_case + c unless string.empty?
|
@@ -92,22 +92,40 @@ module LawNumberSwitch
|
|
92
92
|
|
93
93
|
def to_number_case
|
94
94
|
string = self
|
95
|
+
no_unit = 0
|
96
|
+
string = string.gsub(/(?:○|〇)/, "零").gsub(/(?:零|○|〇)(?:十|拾)/, "一十")
|
97
|
+
.gsub(/廿/, "二十").gsub(/卅/, "三十")
|
95
98
|
CN_DECS.each do |d|
|
96
99
|
no_ten = d + '十'
|
97
100
|
one_ten = d + '一' + '十'
|
98
101
|
if string =~ Regexp.new(no_ten)
|
99
102
|
string = self.gsub(Regexp.new(no_ten), one_ten)
|
100
103
|
end
|
104
|
+
if string !~ Regexp.new(d)
|
105
|
+
no_unit += 1
|
106
|
+
end
|
101
107
|
end
|
102
|
-
|
103
|
-
.
|
104
|
-
|
108
|
+
if no_unit == CN_DECS.length
|
109
|
+
string.to_number_only
|
110
|
+
elsif string =~ /之/
|
105
111
|
string.dash_number
|
106
112
|
else
|
107
113
|
string.int_number
|
108
114
|
end
|
109
115
|
end
|
110
116
|
|
117
|
+
def to_number_only
|
118
|
+
number_only = ''
|
119
|
+
self.scan(/./) do |c|
|
120
|
+
if c == '之'
|
121
|
+
number_only += "-"
|
122
|
+
else
|
123
|
+
number_only += CN_NUMS_MAP[c].to_s
|
124
|
+
end
|
125
|
+
end
|
126
|
+
number_only
|
127
|
+
end
|
128
|
+
|
111
129
|
def int_number
|
112
130
|
num_str = ''
|
113
131
|
last = nil
|