ruby_toys 0.1.1 → 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
2
  SHA256:
3
- metadata.gz: cac3474236650871b96ebfbc8b60de62ad17b57101907d07e2775c34b2ff5c0c
4
- data.tar.gz: a5995f5a54f19fcbf1dcf94016c93306fc05413ee66c67c22730685db5076e66
3
+ metadata.gz: 7f15e30e98bbbd6820e27abd5d640a176fe7f0ab0977c4b352b4dd9d93a1d911
4
+ data.tar.gz: 22f06207521b45cc2f08286249d5bd1c0d22d3b3f7c2fd3019f0a5493860d639
5
5
  SHA512:
6
- metadata.gz: 4a7ce5995319ff2c875a266de89053429193124e3b415d314db8181c35c7c23365faee645eac624d3b75667275d6d77d13db64f2a66053e4f262f8767953275b
7
- data.tar.gz: 4ef816196a4a60107ba8aaa1805e7e40b20d19a99f0368939e6c292d20234ca1003ba1c738d06f561545fedc3568550d6018547aa95f22c071e1f451755a7ff7
6
+ metadata.gz: d3550d400f41398ea27851cfb366b875f5de1d82f121a7c160218f156e41509d2d0324962ede35e24031ea3dcf4ff4cd0bfb8e3dc8d18fb6fd3900106152621b
7
+ data.tar.gz: 9cf9d80ee335392551ee59940a9fd2c801ec661f56009acc7c753ee89c5f70ac306e9d1d02ae0c1558bd8b87100b1276284d2b68ee049568213ec6d5dc4a0d8e
@@ -1,12 +1,58 @@
1
1
  # lib/blank.rb
2
+
3
+ ##
4
+ # RubyToys::Blank
5
+ #
6
+ # Rails の `blank?` / `present?` メソッドを
7
+ # 純粋な Ruby 環境でも使えるようにする軽量リファインメント。
8
+ #
9
+ # @example 使用例
10
+ # require_relative "blank"
11
+ # using RubyToys::Blank
12
+ #
13
+ # nil.blank? # => true
14
+ # false.blank? # => true
15
+ # "".blank? # => true
16
+ # " ".blank? # => true
17
+ # "abc".blank? # => false
18
+ # [].blank? # => true
19
+ # [1, 2].blank? # => false
20
+ # {}.blank? # => true
21
+ # {a: 1}.blank? # => false
22
+ #
23
+ # "hello".present? # => true
24
+ # "".present? # => false
25
+ #
2
26
  module RubyToys
27
+ ##
28
+ # Refinement モジュール。
29
+ # `using RubyToys::Blank` を宣言したスコープ内で
30
+ # `blank?` / `present?` メソッドが利用可能になります。
31
+ #
32
+ # @note グローバルには影響しません。
33
+ #
3
34
  module Blank
35
+ ##
36
+ # オブジェクトが空または偽である場合に true を返します。
37
+ #
38
+ # @return [Boolean]
4
39
  refine Object do
5
40
  def blank?
6
41
  respond_to?(:empty?) ? empty? : !self
7
42
  end
8
43
  end
9
44
 
45
+ ##
46
+ # オブジェクトが空でない場合に true を返します。
47
+ #
48
+ # @return [Boolean]
49
+ refine Object do
50
+ def present?
51
+ !blank?
52
+ end
53
+ end
54
+
55
+
10
56
  refine NilClass do
11
57
  def blank?
12
58
  true
@@ -36,12 +82,5 @@ module RubyToys
36
82
  empty?
37
83
  end
38
84
  end
39
-
40
- refine Object do
41
- def present?
42
- !blank?
43
- end
44
- end
45
-
46
85
  end
47
86
  end
@@ -0,0 +1,73 @@
1
+ module RubyToys
2
+ class Japanese
3
+
4
+ # 全角括弧を半角に変換し、括弧の前後の空白を削除する
5
+ def self.format_parentheses(str)
6
+ s = str.gsub('(', '(').gsub(')', ')')
7
+ sp = "[\\s\\u3000]"
8
+ s = s.gsub(/#{sp}+(?=\()/, '')
9
+ s = s.gsub(/(?<=\))#{sp}+/, '')
10
+ s = s.gsub(/(?<=\()#{sp}+/, '')
11
+ s = s.gsub(/#{sp}+(?=\))/, '')
12
+ s
13
+ end
14
+
15
+ ## 全角カンマの前後の空白を削除し、半角カンマを全角カンマに置換する
16
+ def self.format_comma(str)
17
+ # カンマの後の空白(半角・全角)を削除して、カンマを全角に置換
18
+ sp = "[\\s\\u3000]"
19
+ # 半角カンマの前後空白を削除して全角カンマに置換
20
+ str = str.gsub(/#{sp}*,#{sp}*/, '、')
21
+ # 既存の全角カンマの前後空白も削除
22
+ str = str.gsub(/#{sp}*、#{sp}*/, '、')
23
+ str
24
+ end
25
+
26
+ def self.format(str)
27
+ str = format_parentheses(str)
28
+ str = format_comma(str)
29
+ str
30
+ end
31
+
32
+ # KUTEN = "、"
33
+ # TOUTEN = "。"
34
+ # NAKAGOU = "・"
35
+ # KAGIKAKKO_START = "「"
36
+ # KAGIKAKKO_END = "」"
37
+ # NAKAGOU_REPLACEMENT = "・" # 半角中黒
38
+ #
39
+ # # コンストラクタ
40
+ # def initialize(text)
41
+ # @text = text
42
+ # end
43
+ #
44
+ # # フォーマットを実行して結果を返す
45
+ # def format
46
+ # formatted_text = @text.dup
47
+ #
48
+ # # 全角スペースを半角スペースに変換
49
+ # formatted_text.gsub!(/ /, ' ')
50
+ #
51
+ # # 連続するスペースを1つにまとめる
52
+ # formatted_text.gsub!(/ {2,}/, ' ')
53
+ #
54
+ # # 句点と読点の前後のスペースを削除
55
+ # formatted_text.gsub!(/\s*#{KUTEN}\s*/, KUTEN)
56
+ # formatted_text.gsub!(/\s*#{TOUTEN}\s*/, TOUTEN)
57
+ #
58
+ # # 中黒の前後のスペースを削除し、半角中黒に置換
59
+ # formatted_text.gsub!(/\s*#{NAKAGOU}\s*/, NAKAGOU_REPLACEMENT)
60
+ #
61
+ # # 括弧の前後のスペースを削除
62
+ # formatted_text.gsub!(/\s*#{KAGIKAKKO_START}\s*/, KAGIKAKKO_START)
63
+ # formatted_text.gsub!(/\s*#{KAGIKAKKO_END}\s*/, KAGIKAKKO_END)
64
+ #
65
+ # # 文末に句点がない場合は追加
66
+ # unless formatted_text.end_with?(TOUTEN)
67
+ # formatted_text += TOUTEN
68
+ # end
69
+ #
70
+ # formatted_text
71
+ # end
72
+ end
73
+ end
@@ -12,14 +12,17 @@ module RubyToys
12
12
  return nil
13
13
  end
14
14
 
15
- def self.handle_error(e)
16
- if e.message =~ /Incorrect string value:/
17
- # utf8mb4にすればいいのだ…。とりあえずそのばしのぎ。
18
- puts e.message[0, 100]
19
- else
20
- puts e.message
21
- puts e.backtrace
22
- end
15
+ def self.handle_error(e, verbose = true)
16
+ # if e.message =~ /Incorrect string value:/
17
+ # # utf8mb4にすればいいのだ…。とりあえずそのばしのぎ。
18
+ # puts e.message[0, 100]
19
+ # else
20
+ # puts e.message
21
+ # puts e.backtrace
22
+ # end
23
+ # 2025/05/15(木) Incorrect string value:をテストのために外してみた
24
+ puts "Error: #{e.message}"
25
+ puts e.backtrace.join("\n") + "\n" if verbose
23
26
  end
24
27
  end
25
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyToys
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ruby_toys.rb CHANGED
@@ -5,6 +5,7 @@ require_relative 'ruby_toys/blank'
5
5
  require_relative 'ruby_toys/pair'
6
6
  require_relative 'ruby_toys/utils'
7
7
  require_relative 'ruby_toys/multi_io'
8
+ require_relative 'ruby_toys/japanese'
8
9
 
9
10
  module RubyToys
10
11
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_toys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - src
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-05-15 00:00:00.000000000 Z
11
+ date: 2025-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: My Ruby Library
14
14
  email:
@@ -18,11 +18,6 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - ".idea/.gitignore"
22
- - ".idea/inspectionProfiles/Project_Default.xml"
23
- - ".idea/modules.xml"
24
- - ".idea/ruby_toys.iml"
25
- - ".idea/vcs.xml"
26
21
  - ".ruby-version"
27
22
  - CHANGELOG.md
28
23
  - CODE_OF_CONDUCT.md
@@ -33,6 +28,7 @@ files:
33
28
  - exe/ruby_toys
34
29
  - lib/ruby_toys.rb
35
30
  - lib/ruby_toys/blank.rb
31
+ - lib/ruby_toys/japanese.rb
36
32
  - lib/ruby_toys/multi_io.rb
37
33
  - lib/ruby_toys/pair.rb
38
34
  - lib/ruby_toys/utils.rb
data/.idea/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- # デフォルトの無視対象ファイル
2
- /shelf/
3
- /workspace.xml
4
- # エディターベースの HTTP クライアントリクエスト
5
- /httpRequests/
6
- # Datasource local storage ignored files
7
- /dataSources/
8
- /dataSources.local.xml
@@ -1,47 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="GemInspection" enabled="false" level="WARNING" enabled_by_default="false" />
5
- <inspection_tool class="RbsBadTypeArgumentType" enabled="false" level="ERROR" enabled_by_default="false" />
6
- <inspection_tool class="RbsBadTypeVariableDefaultType" enabled="false" level="ERROR" enabled_by_default="false" />
7
- <inspection_tool class="RbsConflictingTypeVariableCount" enabled="false" level="ERROR" enabled_by_default="false" />
8
- <inspection_tool class="RbsConflictingTypeVariableVariance" enabled="false" level="ERROR" enabled_by_default="false" />
9
- <inspection_tool class="RbsCyclicClassModuleAliasDeclaration" enabled="false" level="ERROR" enabled_by_default="false" />
10
- <inspection_tool class="RbsDuplicateDeclarations" enabled="false" level="ERROR" enabled_by_default="false" />
11
- <inspection_tool class="RbsDuplicateKeywordParameter" enabled="false" level="WARNING" enabled_by_default="false" />
12
- <inspection_tool class="RbsInconsistentClassModuleAlias" enabled="false" level="ERROR" enabled_by_default="false" />
13
- <inspection_tool class="RbsIncorrectInclusionCall" enabled="false" level="ERROR" enabled_by_default="false" />
14
- <inspection_tool class="RbsIncorrectTypeArgumentCount" enabled="false" level="ERROR" enabled_by_default="false" />
15
- <inspection_tool class="RbsIncorrectTypeArgumentVariance" enabled="false" level="ERROR" enabled_by_default="false" />
16
- <inspection_tool class="RbsInvalidMethodOverload" enabled="false" level="ERROR" enabled_by_default="false" />
17
- <inspection_tool class="RbsInvalidTypeArgumentUsage" enabled="false" level="ERROR" enabled_by_default="false" />
18
- <inspection_tool class="RbsLiteralClassReferenced" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
19
- <inspection_tool class="RbsMissingTypeSignature" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
20
- <inspection_tool class="RbsModuleUsedAsSuperclass" enabled="false" level="ERROR" enabled_by_default="false" />
21
- <inspection_tool class="RbsSimplifiableBooleanUnion" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
22
- <inspection_tool class="RbsUnconventionalInterfaceName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
23
- <inspection_tool class="RbsUnconventionalTypeAliasName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
24
- <inspection_tool class="RbsUnconventionalTypeVariableName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
25
- <inspection_tool class="RbsUnconventionalUseAliasName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
26
- <inspection_tool class="RbsUnnecessaryParentheses" enabled="false" level="INFORMATION" enabled_by_default="false" />
27
- <inspection_tool class="RbsUnnecessaryQualifier" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
28
- <inspection_tool class="RbsUnresolvedReference" enabled="false" level="ERROR" enabled_by_default="false" />
29
- <inspection_tool class="RbsUnusedInterface" enabled="false" level="WARNING" enabled_by_default="false" />
30
- <inspection_tool class="RbsUnusedTypeAlias" enabled="false" level="WARNING" enabled_by_default="false" />
31
- <inspection_tool class="RbsUnusedTypeVariable" enabled="false" level="WARNING" enabled_by_default="false" />
32
- <inspection_tool class="RbsUnusedUseClause" enabled="false" level="WARNING" enabled_by_default="false" />
33
- <inspection_tool class="RubyCaseWithoutElseBlockInspection" enabled="false" level="WARNING" enabled_by_default="false" />
34
- <inspection_tool class="RubyMismatchedArgumentType" enabled="false" level="WARNING" enabled_by_default="false" />
35
- <inspection_tool class="RubyMismatchedReturnType" enabled="false" level="WARNING" enabled_by_default="false" />
36
- <inspection_tool class="RubyMismatchedVariableType" enabled="false" level="WARNING" enabled_by_default="false" />
37
- <inspection_tool class="RubyNilAnalysis" enabled="false" level="WARNING" enabled_by_default="false" />
38
- <inspection_tool class="RubyUnnecessaryReturnStatement" enabled="false" level="WARNING" enabled_by_default="false" />
39
- <inspection_tool class="RubyUnnecessaryReturnValue" enabled="false" level="WARNING" enabled_by_default="false" />
40
- <inspection_tool class="RubyUnusedLocalVariable" enabled="false" level="WARNING" enabled_by_default="false" />
41
- <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
42
- <option name="processCode" value="true" />
43
- <option name="processLiterals" value="true" />
44
- <option name="processComments" value="true" />
45
- </inspection_tool>
46
- </profile>
47
- </component>
data/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/ruby_toys.iml" filepath="$PROJECT_DIR$/.idea/ruby_toys.iml" />
6
- </modules>
7
- </component>
8
- </project>
data/.idea/ruby_toys.iml DELETED
@@ -1,89 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="ModuleRunConfigurationManager">
4
- <shared />
5
- </component>
6
- <component name="NewModuleRootManager">
7
- <content url="file://$MODULE_DIR$">
8
- <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
- <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
- </content>
12
- <orderEntry type="jdk" jdkName="rbenv: 3.2.6" jdkType="RUBY_SDK" />
13
- <orderEntry type="sourceFolder" forTests="false" />
14
- <orderEntry type="module-library">
15
- <library name="minitest (v5.25.5) [path][gem]" type="rubylib">
16
- <properties>
17
- <option name="additionalInfo">
18
- <AdditionalInfo>
19
- <option name="authors" value="該当なし" />
20
- <option name="email" value="該当なし" />
21
- <option name="homepage" value="該当なし" />
22
- <option name="summary" value="該当なし" />
23
- </AdditionalInfo>
24
- </option>
25
- <option name="fromPath" value="true" />
26
- <option name="name" value="minitest" />
27
- <option name="requirePaths">
28
- <list>
29
- <option value="lib" />
30
- </list>
31
- </option>
32
- <option name="url" value="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5" />
33
- <option name="version" value="5.25.5" />
34
- </properties>
35
- <CLASSES>
36
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/lib" />
37
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
38
- </CLASSES>
39
- <JAVADOC />
40
- <SOURCES>
41
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/lib" />
42
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
43
- </SOURCES>
44
- <excluded>
45
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/minitest-5.25.5/test" />
46
- </excluded>
47
- </library>
48
- </orderEntry>
49
- <orderEntry type="module-library">
50
- <library name="rake (v13.2.1) [path][gem]" type="rubylib">
51
- <properties>
52
- <option name="additionalInfo">
53
- <AdditionalInfo>
54
- <option name="authors" value="該当なし" />
55
- <option name="email" value="該当なし" />
56
- <option name="homepage" value="該当なし" />
57
- <option name="summary" value="該当なし" />
58
- </AdditionalInfo>
59
- </option>
60
- <option name="fromPath" value="true" />
61
- <option name="name" value="rake" />
62
- <option name="requirePaths">
63
- <list>
64
- <option value="lib" />
65
- </list>
66
- </option>
67
- <option name="url" value="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1" />
68
- <option name="version" value="13.2.1" />
69
- </properties>
70
- <CLASSES>
71
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/doc" />
72
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/exe" />
73
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib" />
74
- </CLASSES>
75
- <JAVADOC />
76
- <SOURCES>
77
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/doc" />
78
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/exe" />
79
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/lib" />
80
- </SOURCES>
81
- <excluded>
82
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/doc" />
83
- <root url="file://$MODULE_DIR$/vendor/bundle/ruby/3.2.0/gems/rake-13.2.1/exe" />
84
- </excluded>
85
- </library>
86
- </orderEntry>
87
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.19, rbenv: 3.2.6) [gem]" level="application" />
88
- </component>
89
- </module>
data/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>