numerals_jp 0.1.2 → 0.2.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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +28 -6
- data/lib/numerals_jp/constant.rb +13 -0
- data/lib/numerals_jp/extension/integer.rb +5 -0
- data/lib/numerals_jp/extension/string.rb +2 -2
- data/lib/numerals_jp/integer_converter.rb +34 -0
- data/lib/numerals_jp/{converter.rb → string_converter.rb} +4 -13
- data/lib/numerals_jp/version.rb +1 -1
- data/lib/numerals_jp.rb +4 -1
- data/numerals_jp.gemspec +1 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a061f27293e75c37ceba3128635cbebb21e7e61
|
4
|
+
data.tar.gz: f89d80120b7881490efe80e7a6521060cf94bf19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c5a941fac1bc9b221d374af810b26302b0a3c34d5b14c8ccd572aac149b193510f89446626f2fe8a49b8bf7c80d5c86552cc22833c7c47080133511c973ad9a
|
7
|
+
data.tar.gz: fb54a206c2df82a5aabde5f657bdf32d7b7496e63d016bd62ace913ccfa8c5a526e48c40466fd19bc573b5b4c6a71be01d9faea92ec59910e4e2c2d151c21c49
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# numerals_jp
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/numerals_jp)
|
4
|
+
[](https://travis-ci.org/paralleltree/numerals_jp)
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
A numerals library for japanese.
|
7
|
+
|
8
|
+
This library converts between arabic numerals and japanese numerals
|
9
|
+
which are often used(i.e., from 1 to 9,999,999,999,999,999).
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
|
@@ -29,22 +32,41 @@ require 'numerals_jp'
|
|
29
32
|
|
30
33
|
### Convert from japanese numerals
|
31
34
|
```ruby
|
32
|
-
"三十六".
|
35
|
+
"三十六".jp_to_num
|
33
36
|
# => "36"
|
34
37
|
```
|
35
38
|
|
36
39
|
This method just replaces japanese numerals with arabic numerals.
|
37
40
|
|
38
41
|
```ruby
|
39
|
-
"十二月三十一日".
|
42
|
+
"十二月三十一日".jp_to_num
|
40
43
|
# => "12月31日"
|
41
44
|
```
|
42
45
|
|
46
|
+
### Convert to Japanese numerals
|
47
|
+
```ruby
|
48
|
+
106.to_jp
|
49
|
+
# => "百六"
|
50
|
+
|
51
|
+
19937.to_jp
|
52
|
+
# => "一万九千九百三十七"
|
53
|
+
```
|
54
|
+
|
43
55
|
## Roadmap
|
44
56
|
|
57
|
+
Done:
|
58
|
+
|
59
|
+
* Support converting from integer to japanese numerals.
|
60
|
+
|
61
|
+
Pending:
|
62
|
+
|
45
63
|
* Support converting from japanese numerals without factor units.
|
46
64
|
* Support converting from arabic numerals with japanese factor units.
|
47
|
-
|
65
|
+
|
66
|
+
## Other Integrations
|
67
|
+
|
68
|
+
[](https://codeclimate.com/github/paralleltree/numerals_jp)
|
69
|
+
[](https://coveralls.io/github/paralleltree/numerals_jp?branch=master)
|
48
70
|
|
49
71
|
## Contributing
|
50
72
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module NumeralsJp::IntegerConverter
|
2
|
+
include NumeralsJp::Constant
|
3
|
+
|
4
|
+
module_function
|
5
|
+
def to_jp(i)
|
6
|
+
raise ArgumentError.new("Argument out of range.") unless i > 0 && i < 10 ** 16
|
7
|
+
|
8
|
+
if i < 10000
|
9
|
+
split_digits(i, 1)
|
10
|
+
.zip([nil] + SMALL_FACTORS.keys)
|
11
|
+
.reject { |num, factor| num == 0 }
|
12
|
+
.map { |num, factor| "#{num if num != 1 || factor.nil?}#{factor}" }
|
13
|
+
.reverse
|
14
|
+
.join
|
15
|
+
.tr("1-9", NUMERALS)
|
16
|
+
else
|
17
|
+
split_digits(i, 4)
|
18
|
+
.zip([nil] + LARGE_FACTORS.keys)
|
19
|
+
.reject { |num, factor| num == 0 }
|
20
|
+
.map { |num, factor| "#{num.to_jp}#{factor}" }
|
21
|
+
.reverse
|
22
|
+
.join
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def split_digits(i, limit)
|
27
|
+
[].tap do |arr|
|
28
|
+
while i > 0
|
29
|
+
arr << i % 10 ** limit
|
30
|
+
i /= 10 ** limit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -1,21 +1,12 @@
|
|
1
|
-
module NumeralsJp::
|
2
|
-
|
3
|
-
|
4
|
-
"十" => 10,
|
5
|
-
"百" => 100,
|
6
|
-
"千" => 1000
|
7
|
-
}.freeze
|
8
|
-
LARGE_FACTORS = {
|
9
|
-
"万" => 10 ** 4,
|
10
|
-
"億" => 10 ** 8,
|
11
|
-
"兆" => 10 ** 12
|
12
|
-
}.freeze
|
1
|
+
module NumeralsJp::StringConverter
|
2
|
+
include NumeralsJp::Constant
|
3
|
+
|
13
4
|
DETECT_PATTERN = /([#{NUMERALS}#{SMALL_FACTORS.keys.join}]+[#{LARGE_FACTORS.keys.join}]?)+/
|
14
5
|
LARGE_EXTRACT_PATTERN = /([#{NUMERALS}#{SMALL_FACTORS.keys.join}]+)([#{LARGE_FACTORS.keys.join}])?/
|
15
6
|
SMALL_EXTRACT_PATTERN = /(([#{NUMERALS}])?([#{SMALL_FACTORS.keys.join}])?)/
|
16
7
|
|
17
8
|
module_function
|
18
|
-
def
|
9
|
+
def jp_to_num(str)
|
19
10
|
str.gsub(DETECT_PATTERN) do |s|
|
20
11
|
s.scan(LARGE_EXTRACT_PATTERN).map { |m|
|
21
12
|
m.first.scan(SMALL_EXTRACT_PATTERN).reject { |m| m.first.empty? }.map { |m|
|
data/lib/numerals_jp/version.rb
CHANGED
data/lib/numerals_jp.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "numerals_jp/version"
|
2
|
-
require "numerals_jp/
|
2
|
+
require "numerals_jp/constant"
|
3
|
+
require "numerals_jp/string_converter"
|
4
|
+
require "numerals_jp/integer_converter"
|
3
5
|
require "numerals_jp/extension/string"
|
6
|
+
require "numerals_jp/extension/integer"
|
4
7
|
|
5
8
|
module NumeralsJp
|
6
9
|
end
|
data/numerals_jp.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numerals_jp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- paralleltree
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
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'
|
55
69
|
description: Number conversion between arabic numerals and japanese numerals.
|
56
70
|
email:
|
57
71
|
- paralleltree@outlook.com
|
@@ -67,8 +81,11 @@ files:
|
|
67
81
|
- README.md
|
68
82
|
- Rakefile
|
69
83
|
- lib/numerals_jp.rb
|
70
|
-
- lib/numerals_jp/
|
84
|
+
- lib/numerals_jp/constant.rb
|
85
|
+
- lib/numerals_jp/extension/integer.rb
|
71
86
|
- lib/numerals_jp/extension/string.rb
|
87
|
+
- lib/numerals_jp/integer_converter.rb
|
88
|
+
- lib/numerals_jp/string_converter.rb
|
72
89
|
- lib/numerals_jp/version.rb
|
73
90
|
- numerals_jp.gemspec
|
74
91
|
homepage: https://github.com/paralleltree/numerals_jp
|