numerals_jp 0.2.0 → 0.2.1
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/README.md +8 -7
- data/lib/numerals_jp.rb +1 -0
- data/lib/numerals_jp/constant.rb +1 -0
- data/lib/numerals_jp/extension/integer.rb +8 -0
- data/lib/numerals_jp/extension/string.rb +7 -0
- data/lib/numerals_jp/integer_converter.rb +21 -1
- data/lib/numerals_jp/string_converter.rb +9 -0
- data/lib/numerals_jp/version.rb +1 -1
- data/numerals_jp.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31aada2f9ae453c74209c7b55306c8cbec12ed0f
|
4
|
+
data.tar.gz: 8eec5574768243b4ace3592889d2e1ce801a5f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 982dee7f936c5e4d3eff1594a41f71b466cc9d44fa5eae9d78641f289b2da71ac3ae287f357594d2d0d7890379454120a0a53956308083da8afd5522d3b0b993
|
7
|
+
data.tar.gz: 0a41da6507aaa85a5226a200e91e00abe06f8732c5dd5e1ddbe5406c38dab7289eaf31b2dea37c11a826dc38c53f52febb1c82c3183cec8dbc8da8a265c61788
|
data/README.md
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
[](https://badge.fury.io/rb/numerals_jp)
|
4
4
|
[](https://travis-ci.org/paralleltree/numerals_jp)
|
5
5
|
|
6
|
-
A numerals library for
|
6
|
+
A numerals library for Japanese
|
7
7
|
|
8
|
-
This library converts between
|
8
|
+
This library converts between Arabic numerals and Japanese numerals
|
9
9
|
which are often used(i.e., from 1 to 9,999,999,999,999,999).
|
10
10
|
|
11
11
|
## Installation
|
@@ -30,13 +30,13 @@ Or install it yourself as:
|
|
30
30
|
require 'numerals_jp'
|
31
31
|
```
|
32
32
|
|
33
|
-
### Convert from
|
33
|
+
### Convert from Japanese numerals
|
34
34
|
```ruby
|
35
35
|
"三十六".jp_to_num
|
36
36
|
# => "36"
|
37
37
|
```
|
38
38
|
|
39
|
-
This method just replaces
|
39
|
+
This method just replaces Japanese numerals with Arabic numerals.
|
40
40
|
|
41
41
|
```ruby
|
42
42
|
"十二月三十一日".jp_to_num
|
@@ -56,17 +56,18 @@ This method just replaces japanese numerals with arabic numerals.
|
|
56
56
|
|
57
57
|
Done:
|
58
58
|
|
59
|
-
* Support converting from integer to
|
59
|
+
* Support converting from integer to Japanese numerals.
|
60
60
|
|
61
61
|
Pending:
|
62
62
|
|
63
|
-
* Support converting from
|
64
|
-
* Support converting from
|
63
|
+
* Support converting from Japanese numerals without factor units.
|
64
|
+
* Support converting from Arabic numerals with Japanese factor units.
|
65
65
|
|
66
66
|
## Other Integrations
|
67
67
|
|
68
68
|
[](https://codeclimate.com/github/paralleltree/numerals_jp)
|
69
69
|
[](https://coveralls.io/github/paralleltree/numerals_jp?branch=master)
|
70
|
+
[](http://inch-ci.org/github/paralleltree/numerals_jp)
|
70
71
|
|
71
72
|
## Contributing
|
72
73
|
|
data/lib/numerals_jp.rb
CHANGED
data/lib/numerals_jp/constant.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
# Extensions of Integer class
|
1
2
|
class Integer
|
3
|
+
# Converts positive integer which is less than 10^16 to Japanese numerals.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# 106.to_jp # => "百六"
|
7
|
+
#
|
8
|
+
# @return [String] the converted string
|
9
|
+
# @raise [ArgumentError] if the integer is not positive or less than 10^16
|
2
10
|
def to_jp
|
3
11
|
NumeralsJp::IntegerConverter.to_jp(self)
|
4
12
|
end
|
@@ -1,4 +1,11 @@
|
|
1
|
+
# Extensions of String class
|
1
2
|
class String
|
3
|
+
# Replaces Japanese numerals with Arabic numerals in the string.
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# "三十六".jp_to_num # => "36"
|
7
|
+
#
|
8
|
+
# @return [String] the converted string
|
2
9
|
def jp_to_num
|
3
10
|
NumeralsJp::StringConverter.jp_to_num(self)
|
4
11
|
end
|
@@ -1,9 +1,19 @@
|
|
1
|
+
# Represents conversions from Integer.
|
1
2
|
module NumeralsJp::IntegerConverter
|
2
3
|
include NumeralsJp::Constant
|
3
4
|
|
4
5
|
module_function
|
6
|
+
|
7
|
+
# Converts positive integer which is less than 10^16 to Japanese numerals.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# to_jp(106) # => "百六"
|
11
|
+
#
|
12
|
+
# @param i [Integer] the integer to convert
|
13
|
+
# @return [String] the converted string
|
14
|
+
# @raise [ArgumentError] if the integer is not positive or less than 10^16
|
5
15
|
def to_jp(i)
|
6
|
-
raise ArgumentError.new("
|
16
|
+
raise ArgumentError.new("the integer out of range") unless i > 0 && i < 10 ** 16
|
7
17
|
|
8
18
|
if i < 10000
|
9
19
|
split_digits(i, 1)
|
@@ -23,6 +33,16 @@ module NumeralsJp::IntegerConverter
|
|
23
33
|
end
|
24
34
|
end
|
25
35
|
|
36
|
+
# Splits the given integer into specified digits from lower digits.
|
37
|
+
#
|
38
|
+
# @example split each digit
|
39
|
+
# split_digits(1234, 1) # => [4, 3, 2, 1]
|
40
|
+
# @example split 4 digits each
|
41
|
+
# split_digits(1234567, 4) # => [4567, 123]
|
42
|
+
#
|
43
|
+
# @param i [Integer] the integer to split
|
44
|
+
# @param limit [Integer] the number of digits to split each
|
45
|
+
# @return [Array<Integer>] an Array of split integers
|
26
46
|
def split_digits(i, limit)
|
27
47
|
[].tap do |arr|
|
28
48
|
while i > 0
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# Represents conversions from String.
|
1
2
|
module NumeralsJp::StringConverter
|
2
3
|
include NumeralsJp::Constant
|
3
4
|
|
@@ -6,6 +7,14 @@ module NumeralsJp::StringConverter
|
|
6
7
|
SMALL_EXTRACT_PATTERN = /(([#{NUMERALS}])?([#{SMALL_FACTORS.keys.join}])?)/
|
7
8
|
|
8
9
|
module_function
|
10
|
+
|
11
|
+
# Replaces Japanese numerals with Arabic numerals in given string.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# jp_to_num("三十六") # => "36"
|
15
|
+
#
|
16
|
+
# @param str [String] the string to convert
|
17
|
+
# @return [String] the converted string
|
9
18
|
def jp_to_num(str)
|
10
19
|
str.gsub(DETECT_PATTERN) do |s|
|
11
20
|
s.scan(LARGE_EXTRACT_PATTERN).map { |m|
|
data/lib/numerals_jp/version.rb
CHANGED
data/numerals_jp.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["paralleltree"]
|
10
10
|
spec.email = ["paralleltree@outlook.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{A numerals library for
|
13
|
-
spec.description = %q{Number conversion between
|
12
|
+
spec.summary = %q{A numerals library for Japanese}
|
13
|
+
spec.description = %q{Number conversion between Arabic numerals and Japanese numerals}
|
14
14
|
spec.homepage = "https://github.com/paralleltree/numerals_jp"
|
15
15
|
spec.license = "MIT"
|
16
16
|
spec.required_ruby_version = '~> 2.0'
|
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.2.
|
4
|
+
version: 0.2.1
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Number conversion between
|
69
|
+
description: Number conversion between Arabic numerals and Japanese numerals
|
70
70
|
email:
|
71
71
|
- paralleltree@outlook.com
|
72
72
|
executables: []
|
@@ -111,5 +111,6 @@ rubyforge_project:
|
|
111
111
|
rubygems_version: 2.4.5
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
|
-
summary: A numerals library for
|
114
|
+
summary: A numerals library for Japanese
|
115
115
|
test_files: []
|
116
|
+
has_rdoc:
|