zen_to_i 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 53867a13f9fae7bc43db15f95836a223ffe980d5
4
- data.tar.gz: 10748a96c6d837e14637bc40a05d8461e6ce8499
2
+ SHA256:
3
+ metadata.gz: c17322f7e45062265d402a73f26fdb4204e39fd8385feb3dd69746956703e720
4
+ data.tar.gz: 8531336638b87ad8dcd182d7b8692ffe6403830c6c3203375bde8f64c34d4109
5
5
  SHA512:
6
- metadata.gz: b414e37deb0dcedaa7e7521038fa4aa5ed5842796b7d1ae951789b3781c37eb00681e9863733db9b97f1cf2cda5d82bbe7a112479b0ff26b89bedb1116244c45
7
- data.tar.gz: 234124278855d5f4f70b982f3c18644fbb8e437013b9c59de39f526f89b2e64e75cbf5e16338763b2b99cd83dea237b680b506151f10366905d81fa6718ff1c7
6
+ metadata.gz: 2db39986d5ce76e554a94945dabe40363d9c3fa6966aabbb605a25ba3409b4beadffbc90095173db3369e307bcc570186c9849c8de2d5cee74f4ce9c269bdb7b
7
+ data.tar.gz: 2d8c718b07f4d40aa1fc77ab901dd8ade5ed3a0d1c1709a0d47abc83efc3a3676f6ad0f394528800aae86fbaf12ac94555474a761a446158e74dc53f44909950
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,70 @@
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/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_gem:
2
+ onkcop:
3
+ - "config/rubocop.yml"
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.4
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'rspec'
4
-
5
- # Specify your gem's dependencies in zen_to_i.gemspec
6
3
  gemspec
data/README.md CHANGED
@@ -2,25 +2,42 @@
2
2
  兆までの漢数字を半角数字に変換します。
3
3
  漢数字が続いていたらそれぞれ変換します。
4
4
 
5
- [![Build Status](https://travis-ci.org/yoshitsugu/zen_to_i.svg)](https://travis-ci.org/yoshitsugu/zen_to_i)
5
+ [![Actions Status](https://github.com/yoshitsugu/zen_to_i/workflows/test/badge.svg)](https://github.com/yoshitsugu/zen_to_i/actions)
6
6
 
7
7
  ## Installation
8
8
 
9
- Add this line to your application's Gemfile:
9
+ install via rubygems
10
10
 
11
- gem 'zen_to_i'
11
+ $ gem install zen_to_i
12
+
13
+ Or, you can use bundler. Please add this line to your application's Gemfile:
14
+
15
+ ```ruby:Gemfile
16
+ gem 'zen_to_i'
17
+ ```
12
18
 
13
19
  And then execute:
14
20
 
15
21
  $ bundle
16
22
 
17
- Or install it yourself as:
23
+ ## Usage
18
24
 
19
- $ gem install zen_to_i
25
+ ## 1. You can use `zen_to_i` command from your shell
20
26
 
21
- ## Usage
27
+ $ zen_to_i "一二三"
28
+ 123
29
+
30
+ # or you can use with pipe
31
+ $ echo "一二三" | zen_to_i
32
+ 123
33
+
34
+ Please call `bundle exec zen_to_i` if you install this gem via bundler.
35
+
36
+ ### 2. In your Ruby script
22
37
 
23
38
  ```ruby
39
+ require 'zen_to_i'
40
+
24
41
  "hoge".zen_to_i
25
42
  #=> "hoge"
26
43
 
@@ -33,6 +50,36 @@ Or install it yourself as:
33
50
  "三兆五十二万四十八".zen_to_i
34
51
  #=> "3000000520048"
35
52
  ```
53
+ Note that `zen_to_i` returns String, not Integer.
54
+
55
+ Or you can overwrite `to_i` method with Refinements.
56
+ This returns Integer same as default `to_i` method.
57
+
58
+ ```ruby
59
+ require "zen_to_i/refine"
60
+
61
+ using ZenToI::Refine
62
+
63
+ "一二三".zen_to_i
64
+ #=> "123"
65
+
66
+ "一二三".to_i
67
+ #=> 123
68
+ ```
69
+
70
+ Also, you can implicitly overwrite `to_i` method by `require "zen_to_i/string_ext"`.
71
+ Of course it is very dangerous. Please be careful to use it.
72
+
73
+ ```ruby
74
+ require "zen_to_i/string_ext"
75
+
76
+ "一二三".zen_to_i
77
+ #=> "123"
78
+
79
+ "一二三".to_i
80
+ #=> 123
81
+ ```
82
+
36
83
 
37
84
  ## Contributing
38
85
 
data/bin/zen_to_i ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap("INT") { abort }
4
+
5
+ require "zen_to_i"
6
+
7
+ begin
8
+ if $stdin.tty?
9
+ if ARGV.length == 1
10
+ puts ARGV[0].zen_to_i
11
+ else
12
+ warn "Usage: zen_to_i (string)"
13
+ exit 1
14
+ end
15
+ else
16
+ $stdin.each_line do |l|
17
+ puts l.zen_to_i
18
+ end
19
+ end
20
+ rescue => e
21
+ warn e.inspect
22
+ e.backtrace.each do |t|
23
+ warn " #{t}"
24
+ end
25
+ exit 2
26
+ end
@@ -1,15 +1,22 @@
1
- # encoding: utf-8
2
- class String
3
- module Zen2Num
4
- KANNUM = { '〇' => 0, '' => 1, '一' => 1, '二' => 2, '三' => 3, '四' => 4,
5
- '五' => 5, '六' => 6, '七' => 7, '八' => 8, '九' => 9,
6
- '零' => 0, '壱' => 1, '弐' => 2, '参' => 3, '肆' => 4,
7
- '伍' => 5, '陸' => 6, '漆' => 7, '捌' => 8, '玖' => 9 }.freeze
8
- KANORDER = { '十' => 10, '百' => 100, '千' => 1000, '' => 1, '拾' => 10,
9
- '陌' => 100, '佰' => 100, '阡' => 1000, '仟' => 1000 }.freeze
10
- KANORDER_F = { '万' => 10**4, '億' => 10**8, '兆' => 10**12,
11
- '' => 1, '萬' => 10**4 }.freeze
12
- ALL_KANSUUJI = KANNUM.keys + KANORDER.keys + KANORDER_F.keys
13
- MAX_LOOP = 100
1
+ # frozen_string_literal: true
2
+
3
+ module ZenToI
4
+ module Constant
5
+ unless const_defined?(:KANNUM, false)
6
+ KANNUM = { "〇" => 0, "" => 1, "一" => 1, "二" => 2, "三" => 3, "四" => 4,
7
+ "五" => 5, "六" => 6, "七" => 7, "八" => 8, "九" => 9,
8
+ "零" => 0, "壱" => 1, "弐" => 2, "参" => 3, "肆" => 4,
9
+ "伍" => 5, "陸" => 6, "漆" => 7, "捌" => 8, "玖" => 9 }.freeze
10
+ KANORDER = { "十" => 10, "百" => 100, "千" => 1000, "" => 1, "拾" => 10,
11
+ "陌" => 100, "佰" => 100, "阡" => 1000, "仟" => 1000 }.freeze
12
+ KANORDER_F = { "万" => 10**4, "億" => 10**8, "兆" => 10**12,
13
+ "" => 1, "萬" => 10**4 }.freeze
14
+ ALL_KANSUUJI = KANNUM.keys + KANORDER.keys + KANORDER_F.keys
15
+ MAX_LOOP = 100
16
+ KANORDER_F_KEYS_REGEX = /([^#{KANORDER_F.keys.join('')}]*)([#{KANORDER_F.keys.join('')}]?)/.freeze
17
+ KANORDER_KEYS_REGEX = /([^#{KANORDER.keys.join('')}]*)([#{KANORDER.keys.join('')}]?)/.freeze
18
+ end
14
19
  end
20
+
21
+ Constant.freeze
15
22
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./constant"
4
+
5
+ module ZenToI
6
+ module Mixin
7
+ include ::ZenToI::Constant
8
+
9
+ def zen_to_i
10
+ result = kanji2num(self)
11
+ zen2han(result)
12
+ end
13
+
14
+ private
15
+
16
+ def kanji2num(str)
17
+ array = split_kansuuji(str)
18
+ array = split_kansuuji_detail(array)
19
+ result = convert_kansuuji(array)
20
+ result.join("")
21
+ end
22
+
23
+ def zen2han(str)
24
+ str.tr("0-9", "0-9")
25
+ end
26
+
27
+ # 漢数字のところだけ切り出す
28
+ def split_kansuuji(string)
29
+ string.split(/([#{ALL_KANSUUJI.join('')}]+)/)
30
+ end
31
+
32
+ # 位を表す数ではない普通の漢数字が続いていたらわける
33
+ def split_kansuuji_detail(array)
34
+ array_tmp = array.clone
35
+ array_result = array.clone
36
+ (1..MAX_LOOP).each do |_i|
37
+ array_result = split_kansuuji_detail_inner(array_result)
38
+ return array_result if array_result == array_tmp
39
+
40
+ array_tmp = array_result.clone
41
+ end
42
+ array_result
43
+ end
44
+
45
+ def split_kansuuji_detail_inner(array)
46
+ ary = array.map do |a|
47
+ if /([#{ALL_KANSUUJI.join('')}]+)/.match?(a)
48
+ kannum = KANNUM.keys.join("")
49
+ a.gsub(/([#{kannum}])([#{kannum}])/, '\1,\2').split(",")
50
+ else
51
+ a
52
+ end
53
+ end
54
+ ary.flatten
55
+ end
56
+
57
+ # 4桁ごとの単位(万、億、兆など)でまずわけ、
58
+ # それぞれに対して漢数字→数字を実行している。
59
+ def convert_kansuuji(array)
60
+ array.map do |a|
61
+ if /([#{ALL_KANSUUJI.join('')}]+)/.match?(a)
62
+ a.scan(KANORDER_F_KEYS_REGEX).inject(0) do |ret, (unit, order_f)|
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
68
+ else
69
+ a
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../zen_to_i"
4
+ require_relative "to_i"
5
+
6
+ module ZenToI
7
+ unless const_defined?(:Refine, false)
8
+ module Refine
9
+ refine String do
10
+ define_method(:_to_i, ZenToI::ToI.instance_method(:_to_i))
11
+ define_method(:to_i, ZenToI::ToI.instance_method(:to_i))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../zen_to_i"
4
+ require_relative "to_i"
5
+
6
+ class String
7
+ unless String.instance_methods(false).include?(:_to_i)
8
+ alias_method :_to_i, :to_i
9
+ end
10
+
11
+ define_method(:to_i, ZenToI::ToI.instance_method(:to_i))
12
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../zen_to_i"
4
+
5
+ module ZenToI
6
+ # String#to_i を漢数字変換に差し替えるための実装。
7
+ # string_ext.rb(グローバルに適用)と refine.rb(refinement 経由)で共有する。
8
+ module ToI
9
+ # 差し替え前の String#to_i を保持する。読み込み時点で String 自身が持つ
10
+ # ネイティブ実装を捕捉し、どのロード順でも素の to_i を参照できるようにする。
11
+ unless const_defined?(:ORIGINAL_TO_I, false)
12
+ ORIGINAL_TO_I = String.instance_method(:to_i)
13
+ end
14
+
15
+ def to_i
16
+ ORIGINAL_TO_I.bind(self.zen_to_i).call
17
+ end
18
+
19
+ def _to_i(*args)
20
+ ORIGINAL_TO_I.bind(self).call(*args)
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ZenToI
2
- VERSION = "0.0.2"
4
+ VERSION = "0.2.0"
3
5
  end
data/lib/zen_to_i.rb CHANGED
@@ -1,85 +1,7 @@
1
- # coding: utf-8
2
- require 'zen_to_i/version'
3
- require 'zen_to_i/constant'
1
+ # frozen_string_literal: true
4
2
 
5
- class String
6
- module Zen2Num
7
- def zen_to_i
8
- result = kanji2num(self)
9
- zen2han(result)
10
- end
11
-
12
- def kanji2num(string)
13
- array = split_kansuuji(string)
14
- array = split_kansuuji_detail(array)
15
- result = convert_kansuuji(array)
16
- result.join('')
17
- end
18
-
19
- def zen2han str
20
- str.tr("0-9","0-9")
21
- end
22
-
23
- private
24
-
25
- #漢数字のところだけ切り出す
26
- def split_kansuuji(string)
27
- string.split(/([#{ALL_KANSUUJI.join('')}]+)/)
28
- end
29
-
30
- #位を表す数ではない普通の漢数字が続いていたらわける
31
- def split_kansuuji_detail(array)
32
- array_tmp = array.clone
33
- array_result = array.clone
34
- (1..MAX_LOOP).each{|i|
35
- array_result = split_kansuuji_detail_inner(array_result)
36
- if array_result == array_tmp
37
- return array_result
38
- else
39
- array_tmp = array_result.clone
40
- end
41
- }
42
- array_result
43
- end
44
-
45
- def split_kansuuji_detail_inner(array)
46
- array.map{|a|
47
- if( a =~ /([#{ALL_KANSUUJI.join('')}]+)/)
48
- kannum = KANNUM.keys.join('')
49
- a.gsub(/([#{kannum}])([#{kannum}])/,'\1,\2').split(",")
50
- else
51
- a
52
- end
53
- }.flatten
54
- end
3
+ require "zen_to_i/mixin"
55
4
 
56
- # 4桁ごとの単位(万、億、兆など)でまずわけ、
57
- # それぞれに対して漢数字→数字を実行している。
58
- def convert_kansuuji(array)
59
- array.map{|a|
60
- if( a =~ /([#{ALL_KANSUUJI.join('')}]+)/)
61
- reg_order_f = /([^#{KANORDER_F.keys.join('')}]*)([#{KANORDER_F.keys.join('')}]?)/
62
- a.scan( reg_order_f ).inject(0) do |ret, (lt_1000, order_f)|
63
- reg_order = /([^#{KANORDER.keys.join('')}]*)([#{KANORDER.keys.join('')}]?)/
64
- lt_1000_i = lt_1000.scan( reg_order ).inject(-1) do |tmp, (_1_9, order)|
65
- tmp + KANNUM[_1_9].to_i * KANORDER[order].to_i
66
- end
67
- ret + lt_1000_i * KANORDER_F[order_f].to_i
68
- end
69
- else
70
- a
71
- end
72
- }
73
- end
74
-
75
-
76
- def format_location string
77
- location_map.each{|key,value|
78
- string.gsub!(/#{key}/,value)
79
- }
80
- string
81
- end
82
-
83
- end
84
- include Zen2Num
5
+ class String
6
+ include ZenToI::Mixin
85
7
  end
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,72 @@
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
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,28 @@
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
@@ -1,8 +1,9 @@
1
- # coding: utf-8
2
- require File.dirname(__FILE__)+"/../spec_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require "zen_to_i"
3
4
 
4
5
  describe ZenToI do
5
- describe "String#zen_to_i" do
6
+ describe "String#zen_to_i" do
6
7
  it "数字以外の文字の場合はそのまま返す" do
7
8
  expect("hoge".zen_to_i).to eq "hoge"
8
9
  end
@@ -22,6 +23,5 @@ describe ZenToI do
22
23
  it "大字でも変換可能" do
23
24
  expect("肆佰参拾捌".zen_to_i).to eq "438"
24
25
  end
25
-
26
26
  end
27
27
  end
data/zen_to_i.gemspec CHANGED
@@ -1,23 +1,26 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'zen_to_i/version'
3
+ require "zen_to_i/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "zen_to_i"
8
7
  spec.version = ZenToI::VERSION
9
8
  spec.authors = ["yoshitsugu"]
10
9
  spec.email = ["zeroinon1206bass@gmail.com"]
11
- spec.description = %q{全角文字に含まれる数字を半角の数値に変換。兆まで対応}
12
- spec.summary = %q{Japanese zenkaku to number}
13
- spec.homepage = ""
10
+ spec.description = "全角文字に含まれる数字を半角の数値に変換。兆まで対応"
11
+ spec.summary = "Japanese zenkaku to number"
12
+ spec.homepage = "https://github.com/yoshitsugu/zen_to_i"
14
13
  spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.4.6"
15
15
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "onkcop"
23
+ spec.add_development_dependency "pry"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
23
26
  end
metadata CHANGED
@@ -1,29 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zen_to_i
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshitsugu
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
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
+ - - ">="
18
45
  - !ruby/object:Gem::Version
19
- version: '1.3'
46
+ version: '0'
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
- - - "~>"
51
+ - - ">="
25
52
  - !ruby/object:Gem::Version
26
- version: '1.3'
53
+ version: '0'
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: rake
29
56
  requirement: !ruby/object:Gem::Requirement
@@ -38,30 +65,54 @@ dependencies:
38
65
  - - ">="
39
66
  - !ruby/object:Gem::Version
40
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'
41
82
  description: 全角文字に含まれる数字を半角の数値に変換。兆まで対応
42
83
  email:
43
84
  - zeroinon1206bass@gmail.com
44
- executables: []
85
+ executables:
86
+ - zen_to_i
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
90
+ - ".github/workflows/ci.yaml"
91
+ - ".github/workflows/codeql-analysis.yml"
48
92
  - ".gitignore"
49
- - ".travis.yml"
93
+ - ".rubocop.yml"
50
94
  - Gemfile
51
95
  - LICENSE.txt
52
96
  - README.md
53
97
  - Rakefile
98
+ - bin/zen_to_i
54
99
  - lib/zen_to_i.rb
55
100
  - lib/zen_to_i/constant.rb
101
+ - lib/zen_to_i/mixin.rb
102
+ - lib/zen_to_i/refine.rb
103
+ - lib/zen_to_i/string_ext.rb
104
+ - lib/zen_to_i/to_i.rb
56
105
  - lib/zen_to_i/version.rb
57
- - spec/lib/zen_to_i_spec.rb
58
- - spec/spec_helper.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
59
111
  - zen_to_i.gemspec
60
- homepage: ''
112
+ homepage: https://github.com/yoshitsugu/zen_to_i
61
113
  licenses:
62
114
  - MIT
63
115
  metadata: {}
64
- post_install_message:
65
116
  rdoc_options: []
66
117
  require_paths:
67
118
  - lib
@@ -69,18 +120,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
120
  requirements:
70
121
  - - ">="
71
122
  - !ruby/object:Gem::Version
72
- version: '0'
123
+ version: 2.4.6
73
124
  required_rubygems_version: !ruby/object:Gem::Requirement
74
125
  requirements:
75
126
  - - ">="
76
127
  - !ruby/object:Gem::Version
77
128
  version: '0'
78
129
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.5.1
81
- signing_key:
130
+ rubygems_version: 4.0.3
82
131
  specification_version: 4
83
132
  summary: Japanese zenkaku to number
84
133
  test_files:
85
- - spec/lib/zen_to_i_spec.rb
86
- - spec/spec_helper.rb
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
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3.1
4
- - 2.2.4
5
- - 2.1.0
6
- script: bundle exec rspec
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- # coding: utf-8
2
- require File.dirname(__FILE__)+"/../lib/zen_to_i"