ya_kansuji 1.0.0 → 1.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 +4 -4
- data/ChangeLog +7 -0
- data/README.md +6 -2
- data/lib/ya_kansuji/core_ext/integer.rb +10 -0
- data/lib/ya_kansuji/core_ext/string.rb +16 -0
- data/lib/ya_kansuji/core_ext.rb +2 -21
- data/lib/ya_kansuji/version.rb +1 -1
- data/lib/ya_kansuji.rb +6 -3
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ae15d72bf1414795e2fc0b0c8b31b292dde3fec64183ad0c8407b561a27dcc0
|
|
4
|
+
data.tar.gz: b5a101d4e735075625e4190be2bd6e4a57d2ce419a80312ce256a427fe17dd55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc79795e352c88129045537e093d76fb59169f2424faa0416a2cf9d829e8a6763ba0fa2a06e1e31e8c1032ed04c0fdb96e54e5677216ca355955f622f67e1c76
|
|
7
|
+
data.tar.gz: 4fd9683d6c48f51ba18bee9e47fa8e393f150a4f0471ddd0c98e5886dda6a52a99a39d34c9e8383b0e7285465d11fd7f51fc3b7f65b1da3507fcfa7e525c51c3
|
data/ChangeLog
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
2026-07-13 Tatsuki Sugiura <sugi@nemui.org>
|
|
2
|
+
|
|
3
|
+
* Version: 1.1.0
|
|
4
|
+
* Support leading "マイナス" for negative numbers on parsing
|
|
5
|
+
* Fix regexp construction bug for single-character units
|
|
6
|
+
* CI maintenance (update ruby versions, tolerate Coveralls failure)
|
|
7
|
+
|
|
1
8
|
2025-03-09 Tatsuki Sugiura <sug@nemui.org>
|
|
2
9
|
|
|
3
10
|
* Version: 1.0.0
|
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# YaKansuji - もう一つの (やりすぎ) ruby 漢数字ライブラリ
|
|
2
2
|
|
|
3
3
|
[<img src="https://badge.fury.io/rb/ya_kansuji.svg" alt="Gem Version" />](https://badge.fury.io/rb/ya_kansuji)
|
|
4
|
-
[<img src="https://
|
|
5
|
-
[<img src="https://coveralls.io/repos/sugi/ya_kansuji/badge.svg?branch=master
|
|
4
|
+
[<img src="https://github.com/sugi/ya_kansuji/actions/workflows/ruby.yml/badge.svg" alt="Build Status" />](https://github.com/sugi/ya_kansuji/actions/workflows/ruby.yml)
|
|
5
|
+
[<img src="https://coveralls.io/repos/github/sugi/ya_kansuji/badge.svg?branch=master" alt="Coverage Status" />](https://coveralls.io/github/sugi/ya_kansuji?branch=master)
|
|
6
6
|
[](https://codeclimate.com/github/sugi/ya_kansuji/maintainability)
|
|
7
7
|
[](https://app.codacy.com/gh/sugi/ya_kansuji/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
|
|
8
8
|
|
|
@@ -21,6 +21,7 @@ YaKansuji は ruby 用の日本語の漢数字ライブラリです。 和暦ラ
|
|
|
21
21
|
* 位取り (2億0010万 / 千〇〇二)
|
|
22
22
|
* 大字 (千皕卅肆)
|
|
23
23
|
* カンマ表現 (12,345 / 5億3,456万 / 二万、五十)
|
|
24
|
+
* 負数 (マイナス五十)
|
|
24
25
|
* 数値から漢数字, 漢字混じり数値文字列フォーマット
|
|
25
26
|
* 複数のビルトインフォーマッタ
|
|
26
27
|
* フォーマッタプラグイン機構
|
|
@@ -46,6 +47,7 @@ gem 'ya_kansuji'
|
|
|
46
47
|
|
|
47
48
|
```ruby
|
|
48
49
|
YaKansuji.to_i("一〇二四") # => 1024
|
|
50
|
+
YaKansuji.to_i("マイナス一〇二四") # => -1024
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
### フォーマット (数値 → 漢数字)
|
|
@@ -54,6 +56,7 @@ YaKansuji.to_i("一〇二四") # => 1024
|
|
|
54
56
|
|
|
55
57
|
```ruby
|
|
56
58
|
YaKansuji.to_kan(12345) # => 一万二千三百四十五
|
|
59
|
+
YaKansuji.to_kan(-12345) # => マイナス一万二千三百四十五
|
|
57
60
|
```
|
|
58
61
|
|
|
59
62
|
このさい、2つめの引数にシンボルを渡すことにより、フォーマッタを切り替えることができます。
|
|
@@ -78,6 +81,7 @@ YaKansuji.to_kan(12340005, :judic_h) # => "1234万0005"
|
|
|
78
81
|
|
|
79
82
|
`YaKansuji#register_formatter` を使うと独自のフォーマッタを登録できます。
|
|
80
83
|
`#call` を持つ任意のオブジェクトもしくはブロックを渡します。第1引数に数字、第2引数にオプションが渡ります。
|
|
84
|
+
負数を渡した場合も、フォーマッタには絶対値 (非負整数) が渡され、符号 (「マイナス」) は `to_kan` 側で前置されます。
|
|
81
85
|
|
|
82
86
|
```ruby
|
|
83
87
|
YaKansuji.register_formatter :hoge, -> (num, opts = {}) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ya_kansuji'
|
|
4
|
+
|
|
5
|
+
# Core extension by kansuji
|
|
6
|
+
class String
|
|
7
|
+
alias _to_i_ya_kansuji_orig to_i unless defined?(_to_i_ya_kansuji_orig)
|
|
8
|
+
|
|
9
|
+
def to_i(base = nil)
|
|
10
|
+
if base.nil? || base == :kan
|
|
11
|
+
YaKansuji.to_i self
|
|
12
|
+
else
|
|
13
|
+
_to_i_ya_kansuji_orig(base)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/ya_kansuji/core_ext.rb
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'ya_kansuji'
|
|
4
|
-
|
|
5
|
-
# Core extension by kansuji
|
|
6
|
-
class String
|
|
7
|
-
alias _to_i_ya_kansuji_orig to_i unless defined?(_to_i_ya_kansuji_orig)
|
|
8
|
-
|
|
9
|
-
def to_i(base = nil)
|
|
10
|
-
if base.nil? || base == :kan
|
|
11
|
-
YaKansuji.to_i self
|
|
12
|
-
else
|
|
13
|
-
_to_i_ya_kansuji_orig(base)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Core extension by kansuji
|
|
19
|
-
class Integer
|
|
20
|
-
def to_kan
|
|
21
|
-
YaKansuji.to_kan self
|
|
22
|
-
end
|
|
23
|
-
end
|
|
3
|
+
require 'ya_kansuji/core_ext/string'
|
|
4
|
+
require 'ya_kansuji/core_ext/integer'
|
data/lib/ya_kansuji/version.rb
CHANGED
data/lib/ya_kansuji.rb
CHANGED
|
@@ -13,13 +13,13 @@ module YaKansuji
|
|
|
13
13
|
REGEXP_PART = %r{
|
|
14
14
|
[
|
|
15
15
|
#{(NUM_ALT_CHARS + NUM_NORMALIZED_CHARS).chars.uniq.join}
|
|
16
|
-
#{(UNIT_EXP3 + UNIT_EXP4).find_all { |u| u.length == 1 }}
|
|
16
|
+
#{(UNIT_EXP3 + UNIT_EXP4).find_all { |u| u.length == 1 }.join}
|
|
17
17
|
卄廿卅丗卌皕
|
|
18
18
|
] |
|
|
19
19
|
#{UNIT_EXP4.find_all { |u| u.length > 1 }.join('|')}
|
|
20
20
|
}x.freeze
|
|
21
21
|
# rubocop:enable Lint/DuplicateRegexpCharacterClassElement
|
|
22
|
-
REGEXP = /(?:#{REGEXP_PART})+/.freeze
|
|
22
|
+
REGEXP = /(?:マイナス)?(?:#{REGEXP_PART})+/.freeze
|
|
23
23
|
@@formatters = {}
|
|
24
24
|
|
|
25
25
|
module_function
|
|
@@ -77,7 +77,8 @@ module YaKansuji
|
|
|
77
77
|
ret3 += curnum
|
|
78
78
|
curnum = nil
|
|
79
79
|
end
|
|
80
|
-
ret4 + ret3
|
|
80
|
+
ret = ret4 + ret3
|
|
81
|
+
matched[0].start_with?('マイナス') ? -ret : ret
|
|
81
82
|
end
|
|
82
83
|
|
|
83
84
|
def register_formatter(sym, proc = nil, &block)
|
|
@@ -100,6 +101,8 @@ module YaKansuji
|
|
|
100
101
|
|
|
101
102
|
def to_kan(num, formatter = :simple, options = {})
|
|
102
103
|
num.respond_to?(:_to_i_ya_kansuji_orig) ? num = num._to_i_ya_kansuji_orig : num = num.to_i
|
|
104
|
+
return "マイナス#{to_kan(-num, formatter, options)}" if num.negative?
|
|
105
|
+
|
|
103
106
|
if formatter.respond_to? :call
|
|
104
107
|
formatter.call num, options
|
|
105
108
|
elsif @@formatters[formatter]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ya_kansuji
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tatsuki Sugiura
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
Pure ruby library of Japanese kansuji.
|
|
@@ -24,6 +24,8 @@ files:
|
|
|
24
24
|
- README.md
|
|
25
25
|
- lib/ya_kansuji.rb
|
|
26
26
|
- lib/ya_kansuji/core_ext.rb
|
|
27
|
+
- lib/ya_kansuji/core_ext/integer.rb
|
|
28
|
+
- lib/ya_kansuji/core_ext/string.rb
|
|
27
29
|
- lib/ya_kansuji/core_refine.rb
|
|
28
30
|
- lib/ya_kansuji/formatter/gov.rb
|
|
29
31
|
- lib/ya_kansuji/formatter/judic_h.rb
|