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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 557fdda463643973beb6a606bdbd29d2268a1296
4
- data.tar.gz: 05ba98f8f190f888485ca7dbf7adca9fc56990a0
3
+ metadata.gz: 482cd56f8abdcda4a1df36f21643f72c1f865260
4
+ data.tar.gz: ee5d29e7130d2247607f7135816c4294132dbeea
5
5
  SHA512:
6
- metadata.gz: 726f34153832a6149aab726af640a3f289fca36451ff890eea7c2d7221c1e69b3e509fb0cc4524a232a68e8c461afca0dada62b864baefc57de20a03f32755a7
7
- data.tar.gz: 253f95b0e61460113b3d55f65fc32033bf13d09e029b1dde373351ddac379193be5abb1f4633487b433fced2a84d29d2ab0680a666bd5d21d9e81f67fbca68e5
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
- class String
2
+ require "jnum_to_anum/constant"
3
3
 
4
- TRANSMANS = {'兆': 1000000000000,
5
- '億': 100000000,
6
- '万': 10000}
7
- TRANSUNIT = {'': 1000,
8
- '百': 100,
9
- '拾': 10,
10
- '十': 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
- ar = []
39
- TRANSUNIT.each do |key,value|
40
- p_index = partial.index(key.to_s)
41
- next unless p_index
42
- ar << partial.slice(0..p_index)
43
- partial = partial.slice(p_index + 1..-1 )
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
- ar << partial unless partial.empty?
46
- sum = 0
47
- ar.each do |wo|
48
- m_w = wo.match(/([0-9]+)([^0-9]+)/)
49
- if m_w
50
- return_num = m_w[1].to_i * TRANSUNIT[m_w[2].to_sym]
51
- elsif wo.match(/([0-9]+)/)
52
- return_num = wo.match(/([0-9]+)/)[1].to_i
53
- else
54
- return_num = TRANSUNIT[wo.match(/([^0-9]+)/)[1].to_sym]
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
- sum += return_num
52
+ filtered_arr << sum
57
53
  end
58
- filtered_arr << sum
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
@@ -0,0 +1,11 @@
1
+ class String
2
+ module JnumToAnum
3
+ TRANSMANS = {'兆': 1000000000000,
4
+ '億': 100000000,
5
+ '万': 10000}
6
+ TRANSUNIT = {'千': 1000,
7
+ '百': 100,
8
+ '拾': 10,
9
+ '十': 10}
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module JnumToAnum
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-21 00:00:00.000000000 Z
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: