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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a061f27293e75c37ceba3128635cbebb21e7e61
4
- data.tar.gz: f89d80120b7881490efe80e7a6521060cf94bf19
3
+ metadata.gz: 31aada2f9ae453c74209c7b55306c8cbec12ed0f
4
+ data.tar.gz: 8eec5574768243b4ace3592889d2e1ce801a5f45
5
5
  SHA512:
6
- metadata.gz: 0c5a941fac1bc9b221d374af810b26302b0a3c34d5b14c8ccd572aac149b193510f89446626f2fe8a49b8bf7c80d5c86552cc22833c7c47080133511c973ad9a
7
- data.tar.gz: fb54a206c2df82a5aabde5f657bdf32d7b7496e63d016bd62ace913ccfa8c5a526e48c40466fd19bc573b5b4c6a71be01d9faea92ec59910e4e2c2d151c21c49
6
+ metadata.gz: 982dee7f936c5e4d3eff1594a41f71b466cc9d44fa5eae9d78641f289b2da71ac3ae287f357594d2d0d7890379454120a0a53956308083da8afd5522d3b0b993
7
+ data.tar.gz: 0a41da6507aaa85a5226a200e91e00abe06f8732c5dd5e1ddbe5406c38dab7289eaf31b2dea37c11a826dc38c53f52febb1c82c3183cec8dbc8da8a265c61788
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/numerals_jp.svg)](https://badge.fury.io/rb/numerals_jp)
4
4
  [![Build Status](https://travis-ci.org/paralleltree/numerals_jp.svg?branch=master)](https://travis-ci.org/paralleltree/numerals_jp)
5
5
 
6
- A numerals library for japanese.
6
+ A numerals library for Japanese
7
7
 
8
- This library converts between arabic numerals and japanese numerals
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 japanese numerals
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 japanese numerals with arabic numerals.
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 japanese numerals.
59
+ * Support converting from integer to Japanese numerals.
60
60
 
61
61
  Pending:
62
62
 
63
- * Support converting from japanese numerals without factor units.
64
- * Support converting from arabic numerals with japanese factor units.
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
  [![Code Climate](https://codeclimate.com/github/paralleltree/numerals_jp/badges/gpa.svg)](https://codeclimate.com/github/paralleltree/numerals_jp)
69
69
  [![Coverage Status](https://coveralls.io/repos/paralleltree/numerals_jp/badge.svg?branch=master&service=github)](https://coveralls.io/github/paralleltree/numerals_jp?branch=master)
70
+ [![Inline docs](http://inch-ci.org/github/paralleltree/numerals_jp.svg?branch=master)](http://inch-ci.org/github/paralleltree/numerals_jp)
70
71
 
71
72
  ## Contributing
72
73
 
@@ -5,5 +5,6 @@ require "numerals_jp/integer_converter"
5
5
  require "numerals_jp/extension/string"
6
6
  require "numerals_jp/extension/integer"
7
7
 
8
+ # Represents a root of the Gem.
8
9
  module NumeralsJp
9
10
  end
@@ -1,3 +1,4 @@
1
+ # Represents common constant variables.
1
2
  module NumeralsJp::Constant
2
3
  NUMERALS = "一二三四五六七八九"
3
4
  SMALL_FACTORS = {
@@ -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("Argument out of range.") unless i > 0 && i < 10 ** 16
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|
@@ -1,3 +1,3 @@
1
1
  module NumeralsJp
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -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 japanese.}
13
- spec.description = %q{Number conversion between arabic numerals and japanese numerals.}
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.0
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-15 00:00:00.000000000 Z
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 arabic numerals and japanese numerals.
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 japanese.
114
+ summary: A numerals library for Japanese
115
115
  test_files: []
116
+ has_rdoc: