jnum_to_anum 0.1.1 → 0.1.2
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/jnum_to_anum.rb +49 -54
- data/lib/jnum_to_anum/constant.rb +11 -0
- data/lib/jnum_to_anum/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482cd56f8abdcda4a1df36f21643f72c1f865260
|
4
|
+
data.tar.gz: ee5d29e7130d2247607f7135816c4294132dbeea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9692df476ddb7d9807464ba604627c31db5f656ce93122facd2e67f74d266e4c2359505a073d2b71bf0a59026468e74d449ca0d5ae3cc7b82ade6abd04882abc
|
7
|
+
data.tar.gz: f52812ef4f6550c97e4d158445f3362e281d8bbc7aa8cfb9c23cada28153c9459d3bb0d85bf3562d617b0e50bb79a68c999df58c67ce5f3a680b2a4f4895ade1
|
data/lib/jnum_to_anum.rb
CHANGED
@@ -1,63 +1,58 @@
|
|
1
1
|
require "jnum_to_anum/version"
|
2
|
-
|
2
|
+
require "jnum_to_anum/constant"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def kansuji_to_num
|
13
|
-
s = self.tr('一二三四五六七八九〇壱弐参0-9a-zA-Z','12345678901230-9a-zA-Z').gsub(/[,.]+/,"")
|
14
|
-
exception = s.match(/^([0-9]+)(百万|千)\z/)
|
15
|
-
if exception #例外 売り上げなどは1,700百万円などと表記することがある
|
16
|
-
unit = exception[2] == "千" ? 1000 : 1000000
|
17
|
-
return exception[1].to_i * unit
|
18
|
-
end
|
19
|
-
partial_arr = []
|
20
|
-
TRANSMANS.each do |key , value|
|
21
|
-
index = s.index(key.to_s)
|
22
|
-
next unless index
|
23
|
-
partial_arr << s.slice(0..index-1)
|
24
|
-
partial_arr << s[index]
|
25
|
-
s = s.slice(index + 1..-1 )
|
26
|
-
end
|
27
|
-
partial_arr << s unless s.empty?
|
28
|
-
filtered_arr = []
|
29
|
-
partial_arr.each do |partial|
|
30
|
-
unless partial =~ /十|百|千|拾/
|
31
|
-
if partial =~ /兆|億|万/
|
32
|
-
filtered_arr << filtered_arr.pop * TRANSMANS[partial.to_sym]
|
33
|
-
else
|
34
|
-
filtered_arr << partial.to_i
|
35
|
-
end
|
36
|
-
next
|
4
|
+
class String
|
5
|
+
module JnumToAnum
|
6
|
+
def kansuji_to_num
|
7
|
+
s = self.tr('一二三四五六七八九〇壱弐参0-9a-zA-Z','12345678901230-9a-zA-Z').gsub(/[,.]+/,"")
|
8
|
+
exception = s.match(/^([0-9]+)(百万|千)\z/)
|
9
|
+
if exception #例外 売り上げなどは1,700百万円などと表記することがある
|
10
|
+
unit = exception[2] == "千" ? 1000 : 1000000
|
11
|
+
return exception[1].to_i * unit
|
37
12
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
next unless
|
42
|
-
|
43
|
-
|
13
|
+
partial_arr = []
|
14
|
+
TRANSMANS.each do |key , value|
|
15
|
+
index = s.index(key.to_s)
|
16
|
+
next unless index
|
17
|
+
partial_arr << s.slice(0..index-1)
|
18
|
+
partial_arr << s[index]
|
19
|
+
s = s.slice(index + 1..-1 )
|
44
20
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
21
|
+
partial_arr << s unless s.empty?
|
22
|
+
filtered_arr = []
|
23
|
+
partial_arr.each do |partial|
|
24
|
+
unless partial =~ /十|百|千|拾/
|
25
|
+
if partial =~ /兆|億|万/
|
26
|
+
filtered_arr << filtered_arr.pop * TRANSMANS[partial.to_sym]
|
27
|
+
else
|
28
|
+
filtered_arr << partial.to_i
|
29
|
+
end
|
30
|
+
next
|
31
|
+
end
|
32
|
+
ar = []
|
33
|
+
TRANSUNIT.each do |key,value|
|
34
|
+
p_index = partial.index(key.to_s)
|
35
|
+
next unless p_index
|
36
|
+
ar << partial.slice(0..p_index)
|
37
|
+
partial = partial.slice(p_index + 1..-1 )
|
38
|
+
end
|
39
|
+
ar << partial unless partial.empty?
|
40
|
+
sum = 0
|
41
|
+
ar.each do |wo|
|
42
|
+
m_w = wo.match(/([0-9]+)([^0-9]+)/)
|
43
|
+
if m_w
|
44
|
+
return_num = m_w[1].to_i * TRANSUNIT[m_w[2].to_sym]
|
45
|
+
elsif wo.match(/([0-9]+)/)
|
46
|
+
return_num = wo.match(/([0-9]+)/)[1].to_i
|
47
|
+
else
|
48
|
+
return_num = TRANSUNIT[wo.match(/([^0-9]+)/)[1].to_sym]
|
49
|
+
end
|
50
|
+
sum += return_num
|
55
51
|
end
|
56
|
-
|
52
|
+
filtered_arr << sum
|
57
53
|
end
|
58
|
-
filtered_arr
|
54
|
+
return_num = filtered_arr.inject {|sum, n| sum + n }
|
55
|
+
return return_num
|
59
56
|
end
|
60
|
-
return_num = filtered_arr.inject {|sum, n| sum + n }
|
61
|
-
return return_num
|
62
57
|
end
|
63
58
|
end
|
data/lib/jnum_to_anum/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnum_to_anum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NishinoTakuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- bin/setup
|
72
72
|
- jnum_to_anum.gemspec
|
73
73
|
- lib/jnum_to_anum.rb
|
74
|
+
- lib/jnum_to_anum/constant.rb
|
74
75
|
- lib/jnum_to_anum/version.rb
|
75
76
|
homepage: https://github.com/nishinotakuma/jnum_to_anum
|
76
77
|
licenses:
|