numeja 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +35 -0
- data/.travis.yml +9 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +22 -0
- data/lib/numeja/version.rb +3 -0
- data/lib/numeja.rb +246 -0
- data/numeja.gemspec +31 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 520ab7906a5d82346ed2ee353f58cae06fd9b1c0
|
4
|
+
data.tar.gz: b8c3922301bd727522750c49ee8d83cdf5991da5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '097c234b903715bfd8ca46d8e2b9b7582f23f05606834c5ef2114d70ae2bd6b8502cd89c56c4b562ee10623fb46f7a3eb501a0aa19a010ef549cfcd84722f32d'
|
7
|
+
data.tar.gz: 139724b38040b64f8742876a713e678435e2acc2da6695049c31c68044e2bc0741448499233f5d015889c60296116b52a291c1660d314e7593130ae46ed1b2a9
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'vendor/**/*'
|
4
|
+
- 'test/fixtures/**/*'
|
5
|
+
- 'tmp/**/*'
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/ModuleLength:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/ClassLength:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 50
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 150
|
21
|
+
|
22
|
+
Style/CaseEquality:
|
23
|
+
Exclude:
|
24
|
+
- 'test/**/*'
|
25
|
+
|
26
|
+
Style/AsciiComments:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Naming/ConstantName:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Naming/UncommunicativeMethodParamName:
|
33
|
+
Exclude:
|
34
|
+
- 'test/**/*'
|
35
|
+
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "numeja Documentation" --protected
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
numeja (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
docile (1.3.0)
|
12
|
+
json (2.1.0)
|
13
|
+
method_source (0.9.0)
|
14
|
+
parallel (1.12.1)
|
15
|
+
parser (2.5.1.0)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
power_assert (1.1.1)
|
18
|
+
powerpack (0.1.1)
|
19
|
+
pry (0.11.3)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
rainbow (3.0.0)
|
23
|
+
rake (10.5.0)
|
24
|
+
rr (1.2.1)
|
25
|
+
rubocop (0.56.0)
|
26
|
+
parallel (~> 1.10)
|
27
|
+
parser (>= 2.5)
|
28
|
+
powerpack (~> 0.1)
|
29
|
+
rainbow (>= 2.2.2, < 4.0)
|
30
|
+
ruby-progressbar (~> 1.7)
|
31
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
32
|
+
ruby-progressbar (1.9.0)
|
33
|
+
simplecov (0.16.1)
|
34
|
+
docile (~> 1.1)
|
35
|
+
json (>= 1.8, < 3)
|
36
|
+
simplecov-html (~> 0.10.0)
|
37
|
+
simplecov-html (0.10.2)
|
38
|
+
test-unit (3.2.8)
|
39
|
+
power_assert
|
40
|
+
test-unit-context (0.5.1)
|
41
|
+
test-unit (>= 2.4.0)
|
42
|
+
test-unit-full (0.0.5)
|
43
|
+
test-unit
|
44
|
+
test-unit-context
|
45
|
+
test-unit-notify
|
46
|
+
test-unit-rr
|
47
|
+
test-unit-runner-tap
|
48
|
+
test-unit-notify (1.0.4)
|
49
|
+
test-unit (>= 2.4.9)
|
50
|
+
test-unit-rr (1.0.5)
|
51
|
+
rr (>= 1.1.1)
|
52
|
+
test-unit (>= 2.5.2)
|
53
|
+
test-unit-runner-tap (1.1.2)
|
54
|
+
test-unit
|
55
|
+
unicode-display_width (1.3.2)
|
56
|
+
yard (0.9.12)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bundler
|
63
|
+
numeja!
|
64
|
+
pry
|
65
|
+
rake
|
66
|
+
rubocop
|
67
|
+
simplecov
|
68
|
+
test-unit-full
|
69
|
+
yard
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
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,36 @@
|
|
1
|
+
# Numeja [![Gem Version](https://badge.fury.io/rb/numeja.svg)](https://badge.fury.io/rb/numeja) [![Build Status](https://travis-ci.org/rike422/numeja.svg?branch=master)](https://travis-ci.org/rike422/numeja) [![Code Climate](https://codeclimate.com/github/rike422/numeja/badges/gpa.svg)](https://codeclimate.com/github/rike422/numeja) [![Coverage Status](https://coveralls.io/repos/github/rike422/numeja/badge.svg?branch=master)](https://coveralls.io/github/rike422/numeja?branch=master)
|
2
|
+
|
3
|
+
Parse numbers in japanese numerals from String
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'numeja'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ima
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'numeja'
|
25
|
+
|
26
|
+
Numeja.numerize('二千三百八十一億九千四百八十七万六千三百十一') # => 238_194_876_311
|
27
|
+
Numeja.numerize('弐阡參佰捌拾壱億九千四百八十七万六千三百十一') # => 238_194_876_311
|
28
|
+
Numeja.numerize('9876億5432万1千2百3十4') # => 987_654_321_234)
|
29
|
+
Numeja.numerize('9876億5432万1千2百3十4') # => 987_654_321_234
|
30
|
+
Numeja.numerize('玖阡捌陌漆拾陸億伍仟肆佰參十貳万壹千弐百卅4') # => 987_654_321_234
|
31
|
+
Numeja.numerize('505') # => 505
|
32
|
+
Numeja.numerize('九八七六五四三二一零') # => 9_876_543_210
|
33
|
+
Numeja.numerize('九分八厘七毛六糸五忽四微三繊二沙零塵一埃') # => 0.9876543201
|
34
|
+
Numeja.numerize('九割八分七厘六毛五糸四忽三微二繊零沙一塵') # => 0.9876543201
|
35
|
+
|
36
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'bundler/setup'
|
8
|
+
rescue LoadError => e
|
9
|
+
abort e.message
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new do |test|
|
13
|
+
test.libs << 'test'
|
14
|
+
test.pattern = 'test/**/test_*.rb'
|
15
|
+
test.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'yard'
|
19
|
+
YARD::Rake::YardocTask.new
|
20
|
+
task doc: :yard
|
21
|
+
|
22
|
+
task default: %i[test yard]
|
data/lib/numeja.rb
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
require 'numeja/version'
|
2
|
+
|
3
|
+
module Numeja
|
4
|
+
JA_大字 = {
|
5
|
+
'零' => '〇',
|
6
|
+
'壱' => '一',
|
7
|
+
'壹' => '一',
|
8
|
+
'弌' => '一',
|
9
|
+
'弐' => '二',
|
10
|
+
'貳' => '二',
|
11
|
+
'參' => '三',
|
12
|
+
'貮' => '二',
|
13
|
+
'弎' => '三',
|
14
|
+
'参' => '三',
|
15
|
+
'肆' => '四',
|
16
|
+
'伍' => '五',
|
17
|
+
'陸' => '六',
|
18
|
+
'柒' => '七',
|
19
|
+
'漆' => '七',
|
20
|
+
'捌' => '八',
|
21
|
+
'玖' => '九',
|
22
|
+
'拾' => '十',
|
23
|
+
'廿' => '二十',
|
24
|
+
'卄' => '二十',
|
25
|
+
'卅' => '三十',
|
26
|
+
'丗' => '三十',
|
27
|
+
'卌' => '四十',
|
28
|
+
'陌' => '百',
|
29
|
+
'佰' => '百',
|
30
|
+
'阡' => '千',
|
31
|
+
'仟' => '千',
|
32
|
+
'萬' => '万'
|
33
|
+
}.freeze
|
34
|
+
|
35
|
+
JA_数字 = {
|
36
|
+
'〇' => 0,
|
37
|
+
'一' => 1,
|
38
|
+
'二' => 2,
|
39
|
+
'三' => 3,
|
40
|
+
'四' => 4,
|
41
|
+
'五' => 5,
|
42
|
+
'六' => 6,
|
43
|
+
'七' => 7,
|
44
|
+
'八' => 8,
|
45
|
+
'九' => 9
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
JA_下数 = {
|
49
|
+
'十' => 10**1,
|
50
|
+
'百' => 10**2,
|
51
|
+
'千' => 10**3
|
52
|
+
}.freeze
|
53
|
+
|
54
|
+
JA_上数 = {
|
55
|
+
'万' => 10**4,
|
56
|
+
'億' => 10**8,
|
57
|
+
'兆' => 10**12,
|
58
|
+
'京' => 10**16,
|
59
|
+
# '垓': 10 ** 20,
|
60
|
+
# '秭': 10 ** 24,
|
61
|
+
# '𥝱': 10 ** 24,
|
62
|
+
# '穰': 10 ** 28,
|
63
|
+
# '溝': 10 ** 32,
|
64
|
+
# '澗': 10 ** 36,
|
65
|
+
# '正': 10 ** 40,
|
66
|
+
# '載': 10 ** 44,
|
67
|
+
# '極': 10 ** 48,
|
68
|
+
# '恒河沙': 10 ** 52,
|
69
|
+
# '阿僧祇': 10 ** 56,
|
70
|
+
# '那由他': 10 ** 60,
|
71
|
+
# '不可思議': 10 ** 64,
|
72
|
+
# '無量大数': 10 ** 68
|
73
|
+
}.freeze
|
74
|
+
|
75
|
+
JA_小数 = {
|
76
|
+
'分' => 10**-1,
|
77
|
+
'厘' => 10**-2,
|
78
|
+
'毛' => 10**-3,
|
79
|
+
'糸' => 10**-4,
|
80
|
+
'忽' => 10**-5,
|
81
|
+
'微' => 10**-6,
|
82
|
+
'繊' => 10**-7,
|
83
|
+
'沙' => 10**-8,
|
84
|
+
'塵' => 10**-9,
|
85
|
+
'埃' => 10**-10
|
86
|
+
}.freeze
|
87
|
+
|
88
|
+
JA_割合用小数 = {
|
89
|
+
'割' => 10**-1,
|
90
|
+
'分' => 10**-2,
|
91
|
+
'厘' => 10**-3,
|
92
|
+
'毛' => 10**-4,
|
93
|
+
'糸' => 10**-5,
|
94
|
+
'忽' => 10**-6,
|
95
|
+
'微' => 10**-7,
|
96
|
+
'繊' => 10**-8,
|
97
|
+
'沙' => 10**-9,
|
98
|
+
'塵' => 10**-10
|
99
|
+
}.freeze
|
100
|
+
REGEXP_旧字 = Regexp.new(Numeja::JA_大字.keys.join('|').to_s, 'g').freeze
|
101
|
+
REGEXP_数字 = Regexp.new(Numeja::JA_数字.keys.join('|').to_s, 'g').freeze
|
102
|
+
|
103
|
+
class << self
|
104
|
+
# Return a numeric of the parsed japanese numerals string
|
105
|
+
#
|
106
|
+
# @param input [String] Japanese numerals(KanSuuji)
|
107
|
+
#
|
108
|
+
# @return [Integer, Float] the parsed Japanese numerals
|
109
|
+
#
|
110
|
+
# @since 0.0.1
|
111
|
+
#
|
112
|
+
# @example
|
113
|
+
# require 'numeja'
|
114
|
+
#
|
115
|
+
# Numeja.numerize('二千三百八十一億九千四百八十七万六千三百十一') => 238_194_876_311
|
116
|
+
# Numeja.numerize('弐阡參佰捌拾壱億九千四百八十七万六千三百十一') => 238_194_876_311
|
117
|
+
# Numeja.numerize('9876億5432万1千2百3十4') => 987_654_321_234)
|
118
|
+
# Numeja.numerize('9876億5432万1千2百3十4') => 987_654_321_234
|
119
|
+
# Numeja.numerize('玖阡捌陌漆拾陸億伍仟肆佰參十貳万壹千弐百卅4') => 987_654_321_234
|
120
|
+
# Numeja.numerize('505') => 505
|
121
|
+
# Numeja.numerize('九八七六五四三二一零') => 9_876_543_210
|
122
|
+
# Numeja.numerize('九分八厘七毛六糸五忽四微三繊二沙零塵一埃') => 0.9876543201)
|
123
|
+
# Numeja.numerize('九割八分七厘六毛五糸四忽三微二繊零沙一塵') => 0.9876543201)
|
124
|
+
def numerize(str)
|
125
|
+
nomarized = nomarize(str)
|
126
|
+
units = parse_large_numbers(nomarized)
|
127
|
+
units.reduce(0) do |t, unit|
|
128
|
+
large_prefix = JA_上数[unit[:digit]]
|
129
|
+
if large_prefix.nil?
|
130
|
+
integer_part, decimal_part = split_digit(unit[:unit])
|
131
|
+
int = integer_part.nil? ? 0 : parse_integer_part(integer_part)
|
132
|
+
decimal = decimal_part.nil? ? 0 : parse_decimal_part(decimal_part)
|
133
|
+
t += int + decimal
|
134
|
+
else
|
135
|
+
integer = parse_integer_part(unit[:unit])
|
136
|
+
t += integer * large_prefix
|
137
|
+
end
|
138
|
+
t
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
# Return numerals parts
|
145
|
+
#
|
146
|
+
# @return [Array<String>]
|
147
|
+
#
|
148
|
+
# @api private
|
149
|
+
# @since 0.0.1
|
150
|
+
def split_digit(str)
|
151
|
+
i = str.index(/.分|.割/)
|
152
|
+
if i.nil?
|
153
|
+
[str]
|
154
|
+
elsif i.zero?
|
155
|
+
[nil, str]
|
156
|
+
else
|
157
|
+
[str[0..i - 1], str[i..-1]]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Return nomarized Kansuuji
|
162
|
+
#
|
163
|
+
# @return [::String]
|
164
|
+
#
|
165
|
+
# @api private
|
166
|
+
# @since 0.0.1
|
167
|
+
def nomarize(str)
|
168
|
+
str
|
169
|
+
.tr('0-9', '0-9')
|
170
|
+
.gsub(REGEXP_旧字, JA_大字)
|
171
|
+
.gsub(REGEXP_数字, JA_数字)
|
172
|
+
end
|
173
|
+
|
174
|
+
# Return nomarized Kansuuji
|
175
|
+
#
|
176
|
+
# @return [::String]
|
177
|
+
#
|
178
|
+
# @api private
|
179
|
+
# @since 0.0.1
|
180
|
+
def parse_integer_part(input)
|
181
|
+
total = 0
|
182
|
+
tmp = 0
|
183
|
+
return input.to_i if input =~ /^[0-9]+$/
|
184
|
+
input.gsub(REGEXP_数字, JA_数字).each_char do |s|
|
185
|
+
unit_prefix = JA_下数[s]
|
186
|
+
unless unit_prefix.nil?
|
187
|
+
if tmp > 0
|
188
|
+
total += tmp * unit_prefix
|
189
|
+
tmp = 0
|
190
|
+
else
|
191
|
+
total += unit_prefix
|
192
|
+
end
|
193
|
+
end
|
194
|
+
tmp += s.to_i
|
195
|
+
end
|
196
|
+
total + tmp
|
197
|
+
end
|
198
|
+
|
199
|
+
# Return parsed decimal part
|
200
|
+
#
|
201
|
+
# @return [Integer, Float]
|
202
|
+
#
|
203
|
+
# @api private
|
204
|
+
# @since 0.0.1
|
205
|
+
def parse_decimal_part(str)
|
206
|
+
map = if str.index('割')
|
207
|
+
Numeja::JA_割合用小数
|
208
|
+
else
|
209
|
+
Numeja::JA_小数
|
210
|
+
end
|
211
|
+
keys = map.keys()
|
212
|
+
keys.reduce(0) do |t, ja_digit|
|
213
|
+
index = str.index(ja_digit)
|
214
|
+
break t if index.nil?
|
215
|
+
unit = str.slice!(0, index)
|
216
|
+
str.slice!(0, 1)
|
217
|
+
t += (unit.to_f * map[ja_digit])
|
218
|
+
t
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Return large number parts
|
223
|
+
#
|
224
|
+
# @return [::Hash]
|
225
|
+
#
|
226
|
+
# @api private
|
227
|
+
# @since 0.0.1
|
228
|
+
def parse_large_numbers(str)
|
229
|
+
# (?<year>(.*)億)(?<oku>(.*)万)
|
230
|
+
splited = Numeja::JA_上数.keys.reverse.map do |ja_digit|
|
231
|
+
index = str.index(ja_digit)
|
232
|
+
next if index.nil?
|
233
|
+
unit = str.slice!(0, index)
|
234
|
+
digit = str.slice!(0, 1)
|
235
|
+
{
|
236
|
+
digit: digit,
|
237
|
+
unit: unit
|
238
|
+
}
|
239
|
+
end
|
240
|
+
splited.push(
|
241
|
+
digit: '',
|
242
|
+
unit: str
|
243
|
+
).compact
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
data/numeja.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'numeja/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'numeja'
|
8
|
+
spec.version = Numeja::VERSION
|
9
|
+
spec.authors = ['Akira Takahashi']
|
10
|
+
spec.email = ['rike422@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Parse numbers in japanese numerals from String.'
|
13
|
+
spec.description = 'Parse numbers in japanese numerals from String.'
|
14
|
+
spec.homepage = 'https://github.com/rike422/numeja'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
28
|
+
spec.add_development_dependency 'simplecov'
|
29
|
+
spec.add_development_dependency 'test-unit-full'
|
30
|
+
spec.add_development_dependency 'yard'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: numeja
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Akira Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-16 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: test-unit-full
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Parse numbers in japanese numerals from String.
|
112
|
+
email:
|
113
|
+
- rike422@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".travis.yml"
|
121
|
+
- ".yardopts"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- lib/numeja.rb
|
129
|
+
- lib/numeja/version.rb
|
130
|
+
- numeja.gemspec
|
131
|
+
homepage: https://github.com/rike422/numeja
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.6.11
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Parse numbers in japanese numerals from String.
|
155
|
+
test_files: []
|