ruby_toys 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8211e351a5dd7b0475fdff98fcd10401029e1ae8c0b86b59d1f574be87bc9932
4
- data.tar.gz: 709701818e3d50fc8fb53ea38514bd916cf59a18d7505bbf719a6e1bdfead5d5
3
+ metadata.gz: 57a09073280ac5aa6d1b7c66a7be577803842cef6c35a21e0c3239193b44d270
4
+ data.tar.gz: 0c99e587399ab6e91cee39c840692ab749f7e703fb132d28bfb51f0560f6df80
5
5
  SHA512:
6
- metadata.gz: 63ccc54776ec0437018faa7bc213d7b6f67626f5a63fc9aed3fc4a7a9a756b798808a988fb8f39386a726e62c1418610eae64a1228817287fa09a3d9aa5c4448
7
- data.tar.gz: ec209dac2573536ce05a568eb9efb40db67da0d30ac9dd3890504213fe3b32ba8ee495f4ec9da089bca0a2299125a2b93573eefa43857716659a446fb3641b75
6
+ metadata.gz: f469b1c075e9a050ad280b48bbbe48c7a25456582ff7dd3e9fd1533fe4c90e6e58b22b37c745105e351274c7af32325ae0838d80f6bcc837d7a88b5741727125
7
+ data.tar.gz: bfc964d8c43b5628335e0fd238743d01ac8e419f3e24fedd7c86042548ebf7679a4343cd502622079b4982e5b329f2b7f6ccfb37e7e8f3e49e75b7793ff6b77a
data/.DS_Store ADDED
Binary file
@@ -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,102 @@
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
+ # 英単語の前後の空白だけを削除する
27
+ def self.format_word(text)
28
+ # ChatGPTが解決できずGeminiに教えて貰う(英単語を検索する方法ではうまくいかず、日本語文字列を指定する方法)
29
+ # 1. 文字列全体の先頭と末尾の空白を削除(trim)
30
+ trimmed_text = text.strip
31
+
32
+ # 2. 英単語以外の文字(ここでは日本語を想定)の直前・直後の空白を削除
33
+ # - \s* は0回以上の空白文字
34
+ # - ([\p{Han}\p{Hiragana}\p{Katakana}]+) は日本語の文字(漢字、ひらがな、カタカナ、記号)をキャプチャ
35
+ # - \1 はキャプチャした日本語の文字に戻す
36
+ cleaned_text = trimmed_text.gsub(/\s*([\p{Han}\p{Hiragana}\p{Katakana}\p{Punctuation}]+)\s*/, '\1')
37
+
38
+ # 3. 英語と日本語の間の空白も整えるため、再度全体をtrimする(念のため)
39
+ cleaned_text.strip
40
+ end
41
+
42
+ # 全角コロン or 半角コロン(後ろにスペースがない場合も含む)正規化
43
+ def self.format_colon(text)
44
+ text.gsub(/\s*[:\uFF1A]\s*/, ': ') # コロンの前に空白があれば削除
45
+ end
46
+
47
+ def self.format(str)
48
+ # puts "Input: #{str}"
49
+ # 最初に空白を削除しとかないとformat_colonが正しく動作しないので注意(あとからformat_wordを呼ぶと追加した空白が削除されてしまう)
50
+ str = format_word(str)
51
+ #puts "After word formatting: #{str}"
52
+ str = format_parentheses(str)
53
+ #puts "After parentheses: #{str}"
54
+ str = format_comma(str)
55
+ #puts "After comma: #{str}"
56
+ str = format_colon(str)
57
+ #puts "After colon: #{str}"
58
+ str
59
+ end
60
+
61
+ # KUTEN = "、"
62
+ # TOUTEN = "。"
63
+ # NAKAGOU = "・"
64
+ # KAGIKAKKO_START = "「"
65
+ # KAGIKAKKO_END = "」"
66
+ # NAKAGOU_REPLACEMENT = "・" # 半角中黒
67
+ #
68
+ # # コンストラクタ
69
+ # def initialize(text)
70
+ # @text = text
71
+ # end
72
+ #
73
+ # # フォーマットを実行して結果を返す
74
+ # def format
75
+ # formatted_text = @text.dup
76
+ #
77
+ # # 全角スペースを半角スペースに変換
78
+ # formatted_text.gsub!(/ /, ' ')
79
+ #
80
+ # # 連続するスペースを1つにまとめる
81
+ # formatted_text.gsub!(/ {2,}/, ' ')
82
+ #
83
+ # # 句点と読点の前後のスペースを削除
84
+ # formatted_text.gsub!(/\s*#{KUTEN}\s*/, KUTEN)
85
+ # formatted_text.gsub!(/\s*#{TOUTEN}\s*/, TOUTEN)
86
+ #
87
+ # # 中黒の前後のスペースを削除し、半角中黒に置換
88
+ # formatted_text.gsub!(/\s*#{NAKAGOU}\s*/, NAKAGOU_REPLACEMENT)
89
+ #
90
+ # # 括弧の前後のスペースを削除
91
+ # formatted_text.gsub!(/\s*#{KAGIKAKKO_START}\s*/, KAGIKAKKO_START)
92
+ # formatted_text.gsub!(/\s*#{KAGIKAKKO_END}\s*/, KAGIKAKKO_END)
93
+ #
94
+ # # 文末に句点がない場合は追加
95
+ # unless formatted_text.end_with?(TOUTEN)
96
+ # formatted_text += TOUTEN
97
+ # end
98
+ #
99
+ # formatted_text
100
+ # end
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyToys
4
- VERSION = "0.1.2"
4
+ VERSION = "0.3.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.2
4
+ version: 0.3.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-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: My Ruby Library
14
14
  email:
@@ -18,11 +18,7 @@ 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"
21
+ - ".DS_Store"
26
22
  - ".ruby-version"
27
23
  - CHANGELOG.md
28
24
  - CODE_OF_CONDUCT.md
@@ -33,6 +29,7 @@ files:
33
29
  - exe/ruby_toys
34
30
  - lib/ruby_toys.rb
35
31
  - lib/ruby_toys/blank.rb
32
+ - lib/ruby_toys/japanese.rb
36
33
  - lib/ruby_toys/multi_io.rb
37
34
  - lib/ruby_toys/pair.rb
38
35
  - 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>