zen_to_i 0.2.0 → 0.3.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/README.md +19 -22
- data/bin/zen_to_i +2 -1
- data/lib/zen_to_i/constant.rb +4 -2
- data/lib/zen_to_i/mixin.rb +21 -12
- data/lib/zen_to_i/refine.rb +1 -0
- data/lib/zen_to_i/string_ext.rb +2 -3
- data/lib/zen_to_i/to_i.rb +4 -7
- data/lib/zen_to_i/version.rb +1 -1
- metadata +7 -93
- data/.github/workflows/ci.yaml +0 -23
- data/.github/workflows/codeql-analysis.yml +0 -70
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -6
- data/Gemfile +0 -3
- data/Rakefile +0 -1
- data/spec/constant_spec.rb +0 -20
- data/spec/load_order_spec.rb +0 -72
- data/spec/refine_spec.rb +0 -30
- data/spec/string_ext_spec.rb +0 -28
- data/spec/zen_to_i_spec.rb +0 -27
- data/zen_to_i.gemspec +0 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b7159a12adbda141423184a4769d10011e872607f7504df9f10ff47146d25880
|
|
4
|
+
data.tar.gz: 8b34203aaad6483c34acf49d7f7e3b07972a0dec470a56cfef3598156c9ab22d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 66e00c3a2e43a09b7cf8e8cfa78d504fd798a8403c1f787ad4e03f7a34bd1ff05d2ac4033e80405cba4fe0a8b77c09c4fca7b656751c912ea067789f81ba0a56
|
|
7
|
+
data.tar.gz: e2a84957f2e08f246c001bbfd94b4bfc1e1bbe56d2a8a1c21a51d14684d072e394060a912be352ca6a938140975b8dd79c3aeeea888abebb9e431dbddea36042
|
data/README.md
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
# ZenToI
|
|
2
|
-
|
|
3
|
-
漢数字が続いていたらそれぞれ変換します。
|
|
2
|
+
兆までの漢数字を半角数字に変換します。文章中に含まれる漢数字も変換できます。
|
|
4
3
|
|
|
5
4
|
[](https://github.com/yoshitsugu/zen_to_i/actions)
|
|
6
5
|
|
|
7
6
|
## Installation
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
Install via RubyGems.
|
|
10
9
|
|
|
11
10
|
$ gem install zen_to_i
|
|
12
11
|
|
|
13
|
-
Or,
|
|
12
|
+
Or, use Bundler. Add this line to your application's Gemfile:
|
|
14
13
|
|
|
15
|
-
```ruby
|
|
16
|
-
gem
|
|
14
|
+
```ruby
|
|
15
|
+
gem "zen_to_i"
|
|
17
16
|
```
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
Then run:
|
|
20
19
|
|
|
21
20
|
$ bundle
|
|
22
21
|
|
|
23
22
|
## Usage
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
### 1. Use the `zen_to_i` command from your shell
|
|
26
25
|
|
|
27
26
|
$ zen_to_i "一二三"
|
|
28
27
|
123
|
|
29
28
|
|
|
30
|
-
# or
|
|
29
|
+
# or use a pipe
|
|
31
30
|
$ echo "一二三" | zen_to_i
|
|
32
31
|
123
|
|
33
32
|
|
|
34
|
-
Please
|
|
33
|
+
Please run `bundle exec zen_to_i` if you installed the gem via Bundler.
|
|
35
34
|
|
|
36
|
-
### 2.
|
|
35
|
+
### 2. Use it in your Ruby script
|
|
37
36
|
|
|
38
37
|
```ruby
|
|
39
38
|
require 'zen_to_i'
|
|
@@ -50,10 +49,9 @@ require 'zen_to_i'
|
|
|
50
49
|
"三兆五十二万四十八".zen_to_i
|
|
51
50
|
#=> "3000000520048"
|
|
52
51
|
```
|
|
53
|
-
Note that `zen_to_i` returns String, not Integer.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
This returns Integer same as default `to_i` method.
|
|
52
|
+
Note that `zen_to_i` returns a String, not an Integer.
|
|
53
|
+
|
|
54
|
+
You can also override `to_i` with a refinement. The override is active only in the lexical scope where `using ZenToI::Refine` appears, and returns an Integer like the built-in `to_i` method.
|
|
57
55
|
|
|
58
56
|
```ruby
|
|
59
57
|
require "zen_to_i/refine"
|
|
@@ -67,8 +65,7 @@ using ZenToI::Refine
|
|
|
67
65
|
#=> 123
|
|
68
66
|
```
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
Of course it is very dangerous. Please be careful to use it.
|
|
68
|
+
You can also replace `String#to_i` globally by requiring `zen_to_i/string_ext`. This affects all strings in the process; the original `to_i` implementation remains available as `String#_to_i`. Use this only when a global override is intended.
|
|
72
69
|
|
|
73
70
|
```ruby
|
|
74
71
|
require "zen_to_i/string_ext"
|
|
@@ -83,8 +80,8 @@ require "zen_to_i/string_ext"
|
|
|
83
80
|
|
|
84
81
|
## Contributing
|
|
85
82
|
|
|
86
|
-
1. Fork
|
|
87
|
-
2. Create
|
|
88
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
89
|
-
4. Push
|
|
90
|
-
5. Create
|
|
83
|
+
1. Fork the repository.
|
|
84
|
+
2. Create a feature branch (`git checkout -b my-new-feature`).
|
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
|
86
|
+
4. Push the branch (`git push origin my-new-feature`).
|
|
87
|
+
5. Create a pull request.
|
data/bin/zen_to_i
CHANGED
data/lib/zen_to_i/constant.rb
CHANGED
|
@@ -13,8 +13,10 @@ module ZenToI
|
|
|
13
13
|
"" => 1, "萬" => 10**4 }.freeze
|
|
14
14
|
ALL_KANSUUJI = KANNUM.keys + KANORDER.keys + KANORDER_F.keys
|
|
15
15
|
MAX_LOOP = 100
|
|
16
|
-
KANORDER_F_KEYS_REGEX = /([^#{KANORDER_F.keys.join(
|
|
17
|
-
KANORDER_KEYS_REGEX = /([^#{KANORDER.keys.join(
|
|
16
|
+
KANORDER_F_KEYS_REGEX = /([^#{KANORDER_F.keys.join("")}]*)([#{KANORDER_F.keys.join("")}]?)/
|
|
17
|
+
KANORDER_KEYS_REGEX = /([^#{KANORDER.keys.join("")}]*)([#{KANORDER.keys.join("")}]?)/
|
|
18
|
+
ALL_KANSUUJI_REGEX = /([#{ALL_KANSUUJI.join("")}]+)/
|
|
19
|
+
KANNUM_PAIR_REGEX = /([#{KANNUM.keys.join("")}])([#{KANNUM.keys.join("")}])/
|
|
18
20
|
end
|
|
19
21
|
end
|
|
20
22
|
|
data/lib/zen_to_i/mixin.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "constant"
|
|
4
4
|
|
|
5
5
|
module ZenToI
|
|
6
6
|
module Mixin
|
|
@@ -26,7 +26,7 @@ module ZenToI
|
|
|
26
26
|
|
|
27
27
|
# 漢数字のところだけ切り出す
|
|
28
28
|
def split_kansuuji(string)
|
|
29
|
-
string.split(
|
|
29
|
+
string.split(ALL_KANSUUJI_REGEX)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
# 位を表す数ではない普通の漢数字が続いていたらわける
|
|
@@ -44,9 +44,8 @@ module ZenToI
|
|
|
44
44
|
|
|
45
45
|
def split_kansuuji_detail_inner(array)
|
|
46
46
|
ary = array.map do |a|
|
|
47
|
-
if
|
|
48
|
-
|
|
49
|
-
a.gsub(/([#{kannum}])([#{kannum}])/, '\1,\2').split(",")
|
|
47
|
+
if ALL_KANSUUJI_REGEX.match?(a)
|
|
48
|
+
a.gsub(KANNUM_PAIR_REGEX, '\1,\2').split(",")
|
|
50
49
|
else
|
|
51
50
|
a
|
|
52
51
|
end
|
|
@@ -58,17 +57,27 @@ module ZenToI
|
|
|
58
57
|
# それぞれに対して漢数字→数字を実行している。
|
|
59
58
|
def convert_kansuuji(array)
|
|
60
59
|
array.map do |a|
|
|
61
|
-
if
|
|
62
|
-
a
|
|
63
|
-
unit_i = unit.scan(KANORDER_KEYS_REGEX).inject(-1) do |tmp, (kanji, order)|
|
|
64
|
-
tmp + KANNUM[kanji].to_i * KANORDER[order].to_i
|
|
65
|
-
end
|
|
66
|
-
ret + unit_i * KANORDER_F[order_f].to_i
|
|
67
|
-
end
|
|
60
|
+
if ALL_KANSUUJI_REGEX.match?(a)
|
|
61
|
+
sum_kansuuji(a)
|
|
68
62
|
else
|
|
69
63
|
a
|
|
70
64
|
end
|
|
71
65
|
end
|
|
72
66
|
end
|
|
67
|
+
|
|
68
|
+
def sum_kansuuji(str)
|
|
69
|
+
str.scan(KANORDER_F_KEYS_REGEX).inject(0) do |ret, (unit, order_f)|
|
|
70
|
+
ret + (unit_to_i(unit, order_f) * KANORDER_F[order_f].to_i)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# 大字だけの表記は 1 個分として数え、scan の末尾の空一致は桁を持たないので 0 とする。
|
|
75
|
+
def unit_to_i(unit, order_f)
|
|
76
|
+
return order_f.empty? ? 0 : 1 if unit.empty?
|
|
77
|
+
|
|
78
|
+
unit.scan(KANORDER_KEYS_REGEX).inject(-1) do |tmp, (kanji, order)|
|
|
79
|
+
tmp + (KANNUM[kanji].to_i * KANORDER[order].to_i)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
73
82
|
end
|
|
74
83
|
end
|
data/lib/zen_to_i/refine.rb
CHANGED
data/lib/zen_to_i/string_ext.rb
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
require_relative "../zen_to_i"
|
|
4
4
|
require_relative "to_i"
|
|
5
5
|
|
|
6
|
+
# 読み込むと String#to_i が漢数字変換に差し替わる。元の実装は String#_to_i に残る。
|
|
6
7
|
class String
|
|
7
|
-
unless String.
|
|
8
|
-
alias_method :_to_i, :to_i
|
|
9
|
-
end
|
|
8
|
+
alias _to_i to_i unless String.method_defined?(:_to_i, false)
|
|
10
9
|
|
|
11
10
|
define_method(:to_i, ZenToI::ToI.instance_method(:to_i))
|
|
12
11
|
end
|
data/lib/zen_to_i/to_i.rb
CHANGED
|
@@ -3,21 +3,18 @@
|
|
|
3
3
|
require_relative "../zen_to_i"
|
|
4
4
|
|
|
5
5
|
module ZenToI
|
|
6
|
-
# String#to_i を漢数字変換に差し替えるための実装。
|
|
7
6
|
# string_ext.rb(グローバルに適用)と refine.rb(refinement 経由)で共有する。
|
|
8
7
|
module ToI
|
|
9
8
|
# 差し替え前の String#to_i を保持する。読み込み時点で String 自身が持つ
|
|
10
9
|
# ネイティブ実装を捕捉し、どのロード順でも素の to_i を参照できるようにする。
|
|
11
|
-
unless const_defined?(:ORIGINAL_TO_I, false)
|
|
12
|
-
ORIGINAL_TO_I = String.instance_method(:to_i)
|
|
13
|
-
end
|
|
10
|
+
ORIGINAL_TO_I = String.instance_method(:to_i) unless const_defined?(:ORIGINAL_TO_I, false)
|
|
14
11
|
|
|
15
12
|
def to_i
|
|
16
|
-
ORIGINAL_TO_I.bind(
|
|
13
|
+
ORIGINAL_TO_I.bind(zen_to_i).call
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
def _to_i(*
|
|
20
|
-
ORIGINAL_TO_I.bind(self).call(*
|
|
16
|
+
def _to_i(*)
|
|
17
|
+
ORIGINAL_TO_I.bind(self).call(*)
|
|
21
18
|
end
|
|
22
19
|
end
|
|
23
20
|
end
|
data/lib/zen_to_i/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,84 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zen_to_i
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yoshitsugu
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: bundler
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - ">="
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: '0'
|
|
19
|
-
type: :development
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - ">="
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: '0'
|
|
26
|
-
- !ruby/object:Gem::Dependency
|
|
27
|
-
name: onkcop
|
|
28
|
-
requirement: !ruby/object:Gem::Requirement
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
-
type: :development
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
|
-
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: pry
|
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
|
43
|
-
requirements:
|
|
44
|
-
- - ">="
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0'
|
|
47
|
-
type: :development
|
|
48
|
-
prerelease: false
|
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
-
requirements:
|
|
51
|
-
- - ">="
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: '0'
|
|
54
|
-
- !ruby/object:Gem::Dependency
|
|
55
|
-
name: rake
|
|
56
|
-
requirement: !ruby/object:Gem::Requirement
|
|
57
|
-
requirements:
|
|
58
|
-
- - ">="
|
|
59
|
-
- !ruby/object:Gem::Version
|
|
60
|
-
version: '0'
|
|
61
|
-
type: :development
|
|
62
|
-
prerelease: false
|
|
63
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
-
requirements:
|
|
65
|
-
- - ">="
|
|
66
|
-
- !ruby/object:Gem::Version
|
|
67
|
-
version: '0'
|
|
68
|
-
- !ruby/object:Gem::Dependency
|
|
69
|
-
name: rspec
|
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
|
71
|
-
requirements:
|
|
72
|
-
- - ">="
|
|
73
|
-
- !ruby/object:Gem::Version
|
|
74
|
-
version: '0'
|
|
75
|
-
type: :development
|
|
76
|
-
prerelease: false
|
|
77
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
-
requirements:
|
|
79
|
-
- - ">="
|
|
80
|
-
- !ruby/object:Gem::Version
|
|
81
|
-
version: '0'
|
|
11
|
+
dependencies: []
|
|
82
12
|
description: 全角文字に含まれる数字を半角の数値に変換。兆まで対応
|
|
83
13
|
email:
|
|
84
14
|
- zeroinon1206bass@gmail.com
|
|
@@ -87,14 +17,8 @@ executables:
|
|
|
87
17
|
extensions: []
|
|
88
18
|
extra_rdoc_files: []
|
|
89
19
|
files:
|
|
90
|
-
- ".github/workflows/ci.yaml"
|
|
91
|
-
- ".github/workflows/codeql-analysis.yml"
|
|
92
|
-
- ".gitignore"
|
|
93
|
-
- ".rubocop.yml"
|
|
94
|
-
- Gemfile
|
|
95
20
|
- LICENSE.txt
|
|
96
21
|
- README.md
|
|
97
|
-
- Rakefile
|
|
98
22
|
- bin/zen_to_i
|
|
99
23
|
- lib/zen_to_i.rb
|
|
100
24
|
- lib/zen_to_i/constant.rb
|
|
@@ -103,16 +27,11 @@ files:
|
|
|
103
27
|
- lib/zen_to_i/string_ext.rb
|
|
104
28
|
- lib/zen_to_i/to_i.rb
|
|
105
29
|
- lib/zen_to_i/version.rb
|
|
106
|
-
- spec/constant_spec.rb
|
|
107
|
-
- spec/load_order_spec.rb
|
|
108
|
-
- spec/refine_spec.rb
|
|
109
|
-
- spec/string_ext_spec.rb
|
|
110
|
-
- spec/zen_to_i_spec.rb
|
|
111
|
-
- zen_to_i.gemspec
|
|
112
30
|
homepage: https://github.com/yoshitsugu/zen_to_i
|
|
113
31
|
licenses:
|
|
114
32
|
- MIT
|
|
115
|
-
metadata:
|
|
33
|
+
metadata:
|
|
34
|
+
rubygems_mfa_required: 'true'
|
|
116
35
|
rdoc_options: []
|
|
117
36
|
require_paths:
|
|
118
37
|
- lib
|
|
@@ -120,19 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
120
39
|
requirements:
|
|
121
40
|
- - ">="
|
|
122
41
|
- !ruby/object:Gem::Version
|
|
123
|
-
version:
|
|
42
|
+
version: 3.4.0
|
|
124
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
44
|
requirements:
|
|
126
45
|
- - ">="
|
|
127
46
|
- !ruby/object:Gem::Version
|
|
128
47
|
version: '0'
|
|
129
48
|
requirements: []
|
|
130
|
-
rubygems_version: 4.0.
|
|
49
|
+
rubygems_version: 4.0.20
|
|
131
50
|
specification_version: 4
|
|
132
51
|
summary: Japanese zenkaku to number
|
|
133
|
-
test_files:
|
|
134
|
-
- spec/constant_spec.rb
|
|
135
|
-
- spec/load_order_spec.rb
|
|
136
|
-
- spec/refine_spec.rb
|
|
137
|
-
- spec/string_ext_spec.rb
|
|
138
|
-
- spec/zen_to_i_spec.rb
|
|
52
|
+
test_files: []
|
data/.github/workflows/ci.yaml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: test
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
name: >-
|
|
8
|
-
Ruby: ${{ matrix.ruby }}
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
strategy:
|
|
11
|
-
matrix:
|
|
12
|
-
ruby:
|
|
13
|
-
- '3.4'
|
|
14
|
-
- '4.0'
|
|
15
|
-
steps:
|
|
16
|
-
- uses: actions/checkout@v7
|
|
17
|
-
- uses: ruby/setup-ruby@v1
|
|
18
|
-
with:
|
|
19
|
-
ruby-version: ${{ matrix.ruby }}
|
|
20
|
-
bundler-cache: true
|
|
21
|
-
- name: run rspec
|
|
22
|
-
run: |
|
|
23
|
-
bundle exec rspec
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
-
# to commit it to your repository.
|
|
3
|
-
#
|
|
4
|
-
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
-
# or to provide custom queries or build logic.
|
|
6
|
-
#
|
|
7
|
-
# ******** NOTE ********
|
|
8
|
-
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
-
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
-
# supported CodeQL languages.
|
|
11
|
-
#
|
|
12
|
-
name: "CodeQL"
|
|
13
|
-
|
|
14
|
-
on:
|
|
15
|
-
push:
|
|
16
|
-
branches: [ master ]
|
|
17
|
-
pull_request:
|
|
18
|
-
# The branches below must be a subset of the branches above
|
|
19
|
-
branches: [ master ]
|
|
20
|
-
schedule:
|
|
21
|
-
- cron: '37 20 * * 2'
|
|
22
|
-
|
|
23
|
-
jobs:
|
|
24
|
-
analyze:
|
|
25
|
-
name: Analyze
|
|
26
|
-
runs-on: ubuntu-latest
|
|
27
|
-
permissions:
|
|
28
|
-
actions: read
|
|
29
|
-
contents: read
|
|
30
|
-
security-events: write
|
|
31
|
-
|
|
32
|
-
strategy:
|
|
33
|
-
fail-fast: false
|
|
34
|
-
matrix:
|
|
35
|
-
language: [ 'ruby' ]
|
|
36
|
-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
|
37
|
-
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
|
38
|
-
|
|
39
|
-
steps:
|
|
40
|
-
- name: Checkout repository
|
|
41
|
-
uses: actions/checkout@v2
|
|
42
|
-
|
|
43
|
-
# Initializes the CodeQL tools for scanning.
|
|
44
|
-
- name: Initialize CodeQL
|
|
45
|
-
uses: github/codeql-action/init@v1
|
|
46
|
-
with:
|
|
47
|
-
languages: ${{ matrix.language }}
|
|
48
|
-
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
49
|
-
# By default, queries listed here will override any specified in a config file.
|
|
50
|
-
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
51
|
-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
52
|
-
|
|
53
|
-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
54
|
-
# If this step fails, then you should remove it and run the build manually (see below)
|
|
55
|
-
- name: Autobuild
|
|
56
|
-
uses: github/codeql-action/autobuild@v1
|
|
57
|
-
|
|
58
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
|
59
|
-
# 📚 https://git.io/JvXDl
|
|
60
|
-
|
|
61
|
-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
62
|
-
# and modify them (or add more) to build your code if your project
|
|
63
|
-
# uses a compiled language
|
|
64
|
-
|
|
65
|
-
#- run: |
|
|
66
|
-
# make bootstrap
|
|
67
|
-
# make release
|
|
68
|
-
|
|
69
|
-
- name: Perform CodeQL Analysis
|
|
70
|
-
uses: github/codeql-action/analyze@v1
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
data/spec/constant_spec.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "zen_to_i"
|
|
4
|
-
|
|
5
|
-
describe ZenToI::Constant do
|
|
6
|
-
describe "複数回読み込んでも例外にならない" do
|
|
7
|
-
it "constantを再度読み込んでも定数が残る" do
|
|
8
|
-
expect { load File.expand_path("../lib/zen_to_i/constant.rb", __dir__) }.not_to raise_error
|
|
9
|
-
|
|
10
|
-
expect(ZenToI::Constant::KANNUM["一"]).to eq 1
|
|
11
|
-
expect("一二三".zen_to_i).to eq "123"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "定数定義がスキップされModuleがfrozenのまま維持される" do
|
|
15
|
-
load File.expand_path("../lib/zen_to_i/constant.rb", __dir__)
|
|
16
|
-
|
|
17
|
-
expect(ZenToI::Constant).to be_frozen
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/spec/load_order_spec.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "open3"
|
|
4
|
-
require "rbconfig"
|
|
5
|
-
|
|
6
|
-
RSpec.describe "ロード順" do
|
|
7
|
-
# refinement の定義は読み込み時点のグローバル String#to_i に影響されるため、
|
|
8
|
-
# ロード順によって挙動が変わらないことをサブプロセスで検証する。
|
|
9
|
-
def run_script(script)
|
|
10
|
-
stdout, stderr, status = Open3.capture3(
|
|
11
|
-
RbConfig.ruby, "-I", File.expand_path("../lib", __dir__), "-e", script
|
|
12
|
-
)
|
|
13
|
-
raise "script failed: #{stderr}" unless status.success?
|
|
14
|
-
|
|
15
|
-
stdout.strip
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "string_ext の後に refine を読み込んでも to_i が変換結果を返す" do
|
|
19
|
-
output = run_script(<<~RUBY)
|
|
20
|
-
require "zen_to_i/string_ext"
|
|
21
|
-
require "zen_to_i/refine"
|
|
22
|
-
using ZenToI::Refine
|
|
23
|
-
print "一二三".to_i
|
|
24
|
-
RUBY
|
|
25
|
-
|
|
26
|
-
expect(output).to eq "123"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "refine の後に string_ext を読み込んでも to_i が変換結果を返す" do
|
|
30
|
-
output = run_script(<<~RUBY)
|
|
31
|
-
require "zen_to_i/refine"
|
|
32
|
-
require "zen_to_i/string_ext"
|
|
33
|
-
using ZenToI::Refine
|
|
34
|
-
print "一二三".to_i
|
|
35
|
-
RUBY
|
|
36
|
-
|
|
37
|
-
expect(output).to eq "123"
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "ロード順によらず _to_i は素の to_i と同じ結果を返す" do
|
|
41
|
-
outputs = [
|
|
42
|
-
<<~RUBY,
|
|
43
|
-
require "zen_to_i/string_ext"
|
|
44
|
-
require "zen_to_i/refine"
|
|
45
|
-
using ZenToI::Refine
|
|
46
|
-
print "一二三"._to_i
|
|
47
|
-
RUBY
|
|
48
|
-
<<~RUBY,
|
|
49
|
-
require "zen_to_i/refine"
|
|
50
|
-
require "zen_to_i/string_ext"
|
|
51
|
-
using ZenToI::Refine
|
|
52
|
-
print "一二三"._to_i
|
|
53
|
-
RUBY
|
|
54
|
-
].map { |script| run_script(script) }
|
|
55
|
-
|
|
56
|
-
expect(outputs).to eq ["0", "0"]
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "先に定義された String#_to_i を上書きしない" do
|
|
60
|
-
output = run_script(<<~RUBY)
|
|
61
|
-
class String
|
|
62
|
-
def _to_i(*)
|
|
63
|
-
"third-party"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
require "zen_to_i/string_ext"
|
|
67
|
-
print "一二三"._to_i, " ", "一二三".to_i
|
|
68
|
-
RUBY
|
|
69
|
-
|
|
70
|
-
expect(output).to eq "third-party 123"
|
|
71
|
-
end
|
|
72
|
-
end
|
data/spec/refine_spec.rb
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "zen_to_i/refine"
|
|
4
|
-
|
|
5
|
-
using ZenToI::Refine
|
|
6
|
-
|
|
7
|
-
describe ZenToI::Refine do
|
|
8
|
-
describe "String#to_i refined" do
|
|
9
|
-
it "usingを使っていると漢数字は変換できる" do
|
|
10
|
-
expect("一二三".to_i).to eq 123
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe "String#_to_i refined" do
|
|
15
|
-
it "_to_iは差し替え前のto_iと同じ結果を返す" do
|
|
16
|
-
expect("一二三"._to_i).to eq 0
|
|
17
|
-
expect("123"._to_i).to eq 123
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "複数回読み込んでも無限再帰にならない" do
|
|
22
|
-
it "refineを再度読み込んでもto_iが動作する" do
|
|
23
|
-
load File.expand_path("../lib/zen_to_i/refine.rb", __dir__)
|
|
24
|
-
|
|
25
|
-
expect { "一二三".to_i }.not_to raise_error
|
|
26
|
-
expect("一二三".to_i).to eq 123
|
|
27
|
-
expect("四五六".to_i).to eq 456
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/spec/string_ext_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "zen_to_i/string_ext"
|
|
4
|
-
|
|
5
|
-
describe String do
|
|
6
|
-
describe "#to_i overwritten" do
|
|
7
|
-
it "to_iで漢数字変換ができる" do
|
|
8
|
-
expect("一二三".to_i).to eq 123
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe "String#_to_i overwritten" do
|
|
13
|
-
it "_to_iは差し替え前のto_iと同じ結果を返す" do
|
|
14
|
-
expect("一二三"._to_i).to eq 0
|
|
15
|
-
expect("123"._to_i).to eq 123
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
describe "複数回読み込んでも無限再帰にならない" do
|
|
20
|
-
it "string_extを再度読み込んでもto_iが動作する" do
|
|
21
|
-
load File.expand_path("../lib/zen_to_i/string_ext.rb", __dir__)
|
|
22
|
-
|
|
23
|
-
expect { "一二三".to_i }.not_to raise_error
|
|
24
|
-
expect("一二三".to_i).to eq 123
|
|
25
|
-
expect("四五六".to_i).to eq 456
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
data/spec/zen_to_i_spec.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "zen_to_i"
|
|
4
|
-
|
|
5
|
-
describe ZenToI do
|
|
6
|
-
describe "String#zen_to_i" do
|
|
7
|
-
it "数字以外の文字の場合はそのまま返す" do
|
|
8
|
-
expect("hoge".zen_to_i).to eq "hoge"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "漢数字の場合は半角数字に変換する" do
|
|
12
|
-
expect("一二三".zen_to_i).to eq "123"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "位をあらわす漢数字を含む場合も半角数字に変換する" do
|
|
16
|
-
expect("百三".zen_to_i).to eq "103"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "兆の位まで半角数字に変換する" do
|
|
20
|
-
expect("三兆五十二万四十八".zen_to_i).to eq "3000000520048"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "大字でも変換可能" do
|
|
24
|
-
expect("肆佰参拾捌".zen_to_i).to eq "438"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/zen_to_i.gemspec
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
lib = File.expand_path("lib", __dir__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require "zen_to_i/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "zen_to_i"
|
|
7
|
-
spec.version = ZenToI::VERSION
|
|
8
|
-
spec.authors = ["yoshitsugu"]
|
|
9
|
-
spec.email = ["zeroinon1206bass@gmail.com"]
|
|
10
|
-
spec.description = "全角文字に含まれる数字を半角の数値に変換。兆まで対応"
|
|
11
|
-
spec.summary = "Japanese zenkaku to number"
|
|
12
|
-
spec.homepage = "https://github.com/yoshitsugu/zen_to_i"
|
|
13
|
-
spec.license = "MIT"
|
|
14
|
-
spec.required_ruby_version = ">= 2.4.6"
|
|
15
|
-
|
|
16
|
-
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.require_paths = ["lib"]
|
|
20
|
-
|
|
21
|
-
spec.add_development_dependency "bundler"
|
|
22
|
-
spec.add_development_dependency "onkcop"
|
|
23
|
-
spec.add_development_dependency "pry"
|
|
24
|
-
spec.add_development_dependency "rake"
|
|
25
|
-
spec.add_development_dependency "rspec"
|
|
26
|
-
end
|