convert_numeral 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/convert_numeral.gemspec +26 -0
- data/lib/convert_numeral.rb +108 -0
- data/lib/convert_numeral/version.rb +3 -0
- data/spec/convert_numeral_spec.rb +135 -0
- data/spec/spec_helper.rb +14 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d65776892bec850a3caac165de5b5c318156e64
|
4
|
+
data.tar.gz: 00a535519691a2831abeea5c0e0c0154c8589ef5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b01698e8e1b18da26c8a356dcfb5b20ad54116b57e44abe680c17dfb796287f3fede604d8e139369a2f7430d1bffa4a703723529c2738b37c6ce02444c1d5942
|
7
|
+
data.tar.gz: 512ea6acbc55c9945e4c19337b6475db484cbc5e0d289c2f1da26e357bc02fb29ea6e6643d80e4f917e3851b0841e8cb4a23bacd349df816582a28926d06d2df
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
convert_numeral (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
convert_numeral!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 masatoshi_moritsuka
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# ConvertNumeral
|
2
|
+
|
3
|
+
This gem convert arabic numeral what is 0 to 9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999_9999 into chinese numeral, and vice versa.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'convert_numeral'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install convert_numeral
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
'零'.to_arabic_numeral
|
25
|
+
# => 0
|
26
|
+
|
27
|
+
'千五百十'.to_arabic_numeral
|
28
|
+
#=> 1510
|
29
|
+
|
30
|
+
'千九百億一千万一千'.to_arabic_numeral
|
31
|
+
#=> 190010001000
|
32
|
+
|
33
|
+
0.to_chinese_numeral
|
34
|
+
#=> "零"
|
35
|
+
|
36
|
+
1510.to_chinese_numeral
|
37
|
+
#=> "千五百十"
|
38
|
+
|
39
|
+
190010001000.to_chinese_numeral
|
40
|
+
#=> "千九百億一千万一千"
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/sanfrecce-osaka/convert_numeral/fork )
|
46
|
+
1. Create your feature branch (git checkout -b my-new-feature)
|
47
|
+
1. Commit your changes (git commit -am 'Add some feature')
|
48
|
+
1. Push to the branch (git push origin my-new-feature)
|
49
|
+
1. Create a new Pull Request
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "convert_numeral"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'convert_numeral/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'convert_numeral'
|
8
|
+
spec.version = ConvertNumeral::VERSION
|
9
|
+
spec.authors = ['masatoshi_moritsuka']
|
10
|
+
spec.email = ['yakiyaki_ikayaki@yahoo.co.jp']
|
11
|
+
|
12
|
+
spec.summary = 'This gem convert numeral.'
|
13
|
+
spec.description = 'This gem convert numeral into Chinese Numeral or full-width numeral.'
|
14
|
+
spec.homepage = 'https://github.com/sanfrecce-osaka/convert_numeral'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0") do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'convert_numeral/version'
|
2
|
+
|
3
|
+
module ConvertNumeral
|
4
|
+
end
|
5
|
+
|
6
|
+
class Integer
|
7
|
+
UNITS_GREATER_THAN_TEN_THOUSAND = [''].concat(%w(万 億 兆 京 垓 𥝱 穣 溝 澗 正 載 極 恒河沙 阿僧祇 那由他 不可思議 無量大数)).map(&:freeze).freeze
|
8
|
+
UNITS_UNTIL_THOUSAND = %w(十 百 千).map(&:freeze).freeze
|
9
|
+
TEN_NUMERALS = %w(零 一 二 三 四 五 六 七 八 九).map(&:freeze).freeze
|
10
|
+
|
11
|
+
def to_chinese_numeral
|
12
|
+
return TEN_NUMERALS[0] if self == 0
|
13
|
+
|
14
|
+
string = self.to_s
|
15
|
+
total_length = string.length
|
16
|
+
|
17
|
+
return convert_separated_by_four_digit(string, total_length) if total_length <= 4
|
18
|
+
|
19
|
+
quo, mod = total_length.divmod(4)
|
20
|
+
limit = (mod == 0) ? quo - 1 : quo
|
21
|
+
separated_numerals_by_four_digit = extract_numerals_separated_by_four_digit(string, limit, mod)
|
22
|
+
|
23
|
+
separated_numerals_by_four_digit
|
24
|
+
.map.with_index do |numeral, index|
|
25
|
+
converted_string = convert_separated_by_four_digit(numeral, numeral.length, index, limit)
|
26
|
+
converted_string.empty? ? '' : converted_string + UNITS_GREATER_THAN_TEN_THOUSAND[index]
|
27
|
+
end
|
28
|
+
.reverse
|
29
|
+
.join
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def convert_separated_by_four_digit(string, char_count, index = 0, limit = 0)
|
35
|
+
(1..char_count).inject('') do |current_string, digit|
|
36
|
+
numeral = string[-digit].to_i
|
37
|
+
thousand_numeral = UNITS_UNTIL_THOUSAND[digit - 2]
|
38
|
+
add_string =
|
39
|
+
if digit == 1
|
40
|
+
numeral > 0 ? TEN_NUMERALS[numeral] : ''
|
41
|
+
elsif digit == 4
|
42
|
+
if index < limit
|
43
|
+
numeral > 0 ? TEN_NUMERALS[numeral] + thousand_numeral : ''
|
44
|
+
else
|
45
|
+
numeral > 1 ? TEN_NUMERALS[numeral] + thousand_numeral : thousand_numeral
|
46
|
+
end
|
47
|
+
else
|
48
|
+
if numeral == 0
|
49
|
+
''
|
50
|
+
elsif numeral == 1
|
51
|
+
thousand_numeral
|
52
|
+
else
|
53
|
+
TEN_NUMERALS[numeral] + thousand_numeral
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
add_string + current_string
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_numerals_separated_by_four_digit(string, limit, mod)
|
62
|
+
(0..limit).map do |index|
|
63
|
+
if index < limit
|
64
|
+
string[-(index * 4 + 4), 4]
|
65
|
+
elsif index == limit
|
66
|
+
if mod == 0
|
67
|
+
string[-(index * 4 + 4), 4]
|
68
|
+
else
|
69
|
+
string[-(index * 4 + mod), mod]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class String
|
77
|
+
UNITS_GREATER_THAN_TEN_THOUSAND = [''].concat(%w(万 億 兆 京 垓 𥝱 穣 溝 澗 正 載 極 恒河沙 阿僧祇 那由他 不可思議 無量大数)).map(&:freeze).freeze
|
78
|
+
TEN_NUMERALS = %w(零 一 二 三 四 五 六 七 八 九).map(&:freeze).freeze
|
79
|
+
|
80
|
+
def to_arabic_numeral
|
81
|
+
sentence_from_one_to_thousand = '(?:[一二三四五六七八九]?千)?(?:[二三四五六七八九]?百)?(?:[二三四五六七八九]?十)?(?:[零一二三四五六七八九])?'
|
82
|
+
sentence = UNITS_GREATER_THAN_TEN_THOUSAND.map { |unit| "(#{sentence_from_one_to_thousand}#{unit})?" }.reverse.join
|
83
|
+
regexp = Regexp.new(sentence)
|
84
|
+
|
85
|
+
first_matches = scan(regexp).first.reverse
|
86
|
+
|
87
|
+
first_matches.each_with_index.inject(0) do |current_total, (first_match, first_match_s_index)|
|
88
|
+
if !first_match.nil?
|
89
|
+
matches = first_match.scan(/([一二三四五六七八九]?千)?([二三四五六七八九]?百)?([二三四五六七八九]?十)?([零一二三四五六七八九])?/).first.reverse
|
90
|
+
sum = matches.each_with_index.inject(0) do |current_sum, (match, index)|
|
91
|
+
numeral = match&.slice(/[零一二三四五六七八九]/)
|
92
|
+
|
93
|
+
if match.nil?
|
94
|
+
current_sum
|
95
|
+
elsif numeral.nil?
|
96
|
+
current_sum + (10 ** (index))
|
97
|
+
else
|
98
|
+
current_sum + ((10 ** (index)) * TEN_NUMERALS.index(numeral))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
current_total + (sum * (10 ** (4 * first_match_s_index)))
|
103
|
+
else
|
104
|
+
current_total
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ConvertNumeral do
|
4
|
+
it 'has a version number' do
|
5
|
+
expect(ConvertNumeral::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe Integer do
|
10
|
+
describe '#to_chinese_numeral' do
|
11
|
+
it 'convert integer into chinese numeral' do
|
12
|
+
expect(0.to_chinese_numeral).to eq '零'
|
13
|
+
expect(1.to_chinese_numeral).to eq '一'
|
14
|
+
expect(2.to_chinese_numeral).to eq '二'
|
15
|
+
expect(10.to_chinese_numeral).to eq '十'
|
16
|
+
expect(13.to_chinese_numeral).to eq '十三'
|
17
|
+
expect(44.to_chinese_numeral).to eq '四十四'
|
18
|
+
expect(100.to_chinese_numeral).to eq '百'
|
19
|
+
expect(605.to_chinese_numeral).to eq '六百五'
|
20
|
+
expect(617.to_chinese_numeral).to eq '六百十七'
|
21
|
+
expect(728.to_chinese_numeral).to eq '七百二十八'
|
22
|
+
expect(1000.to_chinese_numeral).to eq '千'
|
23
|
+
expect(1001.to_chinese_numeral).to eq '千一'
|
24
|
+
expect(1010.to_chinese_numeral).to eq '千十'
|
25
|
+
expect(1025.to_chinese_numeral).to eq '千二十五'
|
26
|
+
expect(1111.to_chinese_numeral).to eq '千百十一'
|
27
|
+
expect(1321.to_chinese_numeral).to eq '千三百二十一'
|
28
|
+
expect(9999.to_chinese_numeral).to eq '九千九百九十九'
|
29
|
+
expect(1_0000.to_chinese_numeral).to eq '一万'
|
30
|
+
expect(1_0001.to_chinese_numeral).to eq '一万一'
|
31
|
+
expect(1_1111.to_chinese_numeral).to eq '一万一千百十一'
|
32
|
+
expect(20_0030.to_chinese_numeral).to eq '二十万三十'
|
33
|
+
expect(1321_1400.to_chinese_numeral).to eq '千三百二十一万一千四百'
|
34
|
+
expect(4567_8629.to_chinese_numeral).to eq '四千五百六十七万八千六百二十九'
|
35
|
+
expect(1_0000_0000.to_chinese_numeral).to eq '一億'
|
36
|
+
expect(1_0000_1000.to_chinese_numeral).to eq '一億一千'
|
37
|
+
expect(1_1000_5000.to_chinese_numeral).to eq '一億一千万五千'
|
38
|
+
expect(1000_0000_0000.to_chinese_numeral).to eq '千億'
|
39
|
+
expect(1_0000_0000_0000.to_chinese_numeral).to eq '一兆'
|
40
|
+
expect(1000_1000_1000_1000.to_chinese_numeral).to eq '千兆一千億一千万一千'
|
41
|
+
expect(1_0000_0000_0000_0000.to_chinese_numeral).to eq '一京'
|
42
|
+
expect(1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千京一千兆一千億一千万一千'
|
43
|
+
expect(1_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一垓'
|
44
|
+
expect(1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千垓一千京一千兆一千億一千万一千'
|
45
|
+
expect(1_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一𥝱'
|
46
|
+
expect(1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千𥝱一千垓一千京一千兆一千億一千万一千'
|
47
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一穣'
|
48
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
49
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一溝'
|
50
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
51
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一澗'
|
52
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
53
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一正'
|
54
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
55
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一載'
|
56
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
57
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一極'
|
58
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
59
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一恒河沙'
|
60
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
61
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一阿僧祇'
|
62
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
63
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一那由他'
|
64
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
65
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一不可思議'
|
66
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千不可思議一千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
67
|
+
expect(1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000.to_chinese_numeral).to eq '一無量大数'
|
68
|
+
expect(1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000.to_chinese_numeral).to eq '千無量大数一千不可思議一千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
RSpec.describe String do
|
74
|
+
describe '#to_arabic_numeral' do
|
75
|
+
it 'convert chinese numeral into integer' do
|
76
|
+
expect('零'.to_arabic_numeral).to eq 0
|
77
|
+
expect('一'.to_arabic_numeral).to eq 1
|
78
|
+
expect('二'.to_arabic_numeral).to eq 2
|
79
|
+
expect('十'.to_arabic_numeral).to eq 10
|
80
|
+
expect('十三'.to_arabic_numeral).to eq 13
|
81
|
+
expect('四十四'.to_arabic_numeral).to eq 44
|
82
|
+
expect('百'.to_arabic_numeral).to eq 100
|
83
|
+
expect('六百五'.to_arabic_numeral).to eq 605
|
84
|
+
expect('六百十七'.to_arabic_numeral).to eq 617
|
85
|
+
expect('七百二十八'.to_arabic_numeral).to eq 728
|
86
|
+
expect('千'.to_arabic_numeral).to eq 1000
|
87
|
+
expect('千一'.to_arabic_numeral).to eq 1001
|
88
|
+
expect('千十'.to_arabic_numeral).to eq 1010
|
89
|
+
expect('千二十五'.to_arabic_numeral).to eq 1025
|
90
|
+
expect('千百十一'.to_arabic_numeral).to eq 1111
|
91
|
+
expect('千三百二十一'.to_arabic_numeral).to eq 1321
|
92
|
+
expect('九千九百九十九'.to_arabic_numeral).to eq 9999
|
93
|
+
expect('一万'.to_arabic_numeral).to eq 1_0000
|
94
|
+
expect('一万一'.to_arabic_numeral).to eq 1_0001
|
95
|
+
expect('一万一千百十一'.to_arabic_numeral).to eq 1_1111
|
96
|
+
expect('二十万三十'.to_arabic_numeral).to eq 20_0030
|
97
|
+
expect('千三百二十一万一千四百'.to_arabic_numeral).to eq 1321_1400
|
98
|
+
expect('四千五百六十七万八千六百二十九'.to_arabic_numeral).to eq 4567_8629
|
99
|
+
expect('一億'.to_arabic_numeral).to eq 1_0000_0000
|
100
|
+
expect('一億一千'.to_arabic_numeral).to eq 1_0000_1000
|
101
|
+
expect('一億一千万五千'.to_arabic_numeral).to eq 1_1000_5000
|
102
|
+
expect('千億'.to_arabic_numeral).to eq 1000_0000_0000
|
103
|
+
expect('一兆'.to_arabic_numeral).to eq 1_0000_0000_0000
|
104
|
+
expect('千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000
|
105
|
+
expect('一京'.to_arabic_numeral).to eq 1_0000_0000_0000_0000
|
106
|
+
expect('千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000
|
107
|
+
expect('一垓'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000
|
108
|
+
expect('千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000
|
109
|
+
expect('一𥝱'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000
|
110
|
+
expect('千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000
|
111
|
+
expect('一穣'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000
|
112
|
+
expect('千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000
|
113
|
+
expect('一溝'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000
|
114
|
+
expect('千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000
|
115
|
+
expect('一澗'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
116
|
+
expect('千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
117
|
+
expect('一正'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
118
|
+
expect('千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
119
|
+
expect('一載'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
120
|
+
expect('千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
121
|
+
expect('一極'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
122
|
+
expect('千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
123
|
+
expect('一恒河沙'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
124
|
+
expect('千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
125
|
+
expect('一阿僧祇'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
126
|
+
expect('千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
127
|
+
expect('一那由他'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
128
|
+
expect('千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
129
|
+
expect('一不可思議'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
130
|
+
expect('千不可思議一千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
131
|
+
expect('一無量大数'.to_arabic_numeral).to eq 1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
|
132
|
+
expect('千無量大数一千不可思議一千那由他一千阿僧祇一千恒河沙一千極一千載一千正一千澗一千溝一千穣一千𥝱一千垓一千京一千兆一千億一千万一千'.to_arabic_numeral).to eq 1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000_1000
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'convert_numeral'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = '.rspec_status'
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: convert_numeral
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- masatoshi_moritsuka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: This gem convert numeral into Chinese Numeral or full-width numeral.
|
56
|
+
email:
|
57
|
+
- yakiyaki_ikayaki@yahoo.co.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- convert_numeral.gemspec
|
73
|
+
- lib/convert_numeral.rb
|
74
|
+
- lib/convert_numeral/version.rb
|
75
|
+
- spec/convert_numeral_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: https://github.com/sanfrecce-osaka/convert_numeral
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.6.14
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: This gem convert numeral.
|
101
|
+
test_files: []
|