mojicon 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc82856a438d30fa4c1b5b3df3bc4c6b16bedaa4a664435e1870f38dc6f7e590
4
- data.tar.gz: fd21cc14da864be5a727b1716bf2d27f7a938637b29f0184c1f4bb18045720c8
3
+ metadata.gz: d396b14575c9ba5ab8fb0a9b96ee8dd425922e83803e8c0fd36a4834b839550b
4
+ data.tar.gz: 245017accf982cf7af606354ebec8e75eaf8add51b6c752c2c7b06e4b915a71c
5
5
  SHA512:
6
- metadata.gz: f92068597722dccdb1923285090f586e63b51c4dffee21f1fdcf6f7e74526e8cff6fde45c08f5687e409eab04f7fb26e7d6bc3f2a960f58bca7b98cbc613679d
7
- data.tar.gz: a93f2632e27ca1ad8d9f08fef9c2b2c3965273059f4cf9574e284642fcd7a3a7e685aaf3fa826a56ffc4856f1fe15dbb5aec49edcf098ad75ad336a3c1839c97
6
+ metadata.gz: 23b13f3779b82bbcb3d4b7ee6578c85fa7ad1e33cc4a69639391c321f20005012212c842e6fce6f664ded843e2cfcbc6265d10da8f7110507add400b06f5703e
7
+ data.tar.gz: 260c11ca6be1d7bf09b0bb58a268265c710f85514dd3c0b3e8212ccac652a5a2d6a199c40b63fbf9731ec468a46705896515e36758843dc5324ef7e5becb8f35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
- ## [Unreleased]
1
+ # [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-01-17
3
+ ## [0.1.0] - 2024-03-02
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.2.0] - 2024-03-02
8
+
9
+ - Bit revise
10
+
11
+ ## [0.3.0] - 2024-03-02
12
+
13
+ - Set up requirement
data/README.md CHANGED
@@ -1,23 +1,71 @@
1
- # mojicon
1
+ # Mojicon
2
2
 
3
- Convert japanese character
3
+ Mojicon is a Ruby Gem designed to simplify text processing for Japanese characters. It provides a wide range of text transformation functionalities, including conversions between full-width and half-width characters, kana and hiragana, kanji numerals to Arabic numerals, Arabic numerals to kanji, and more. This Gem allows methods to be applied directly to string objects.
4
+
5
+ ## Features
6
+
7
+ - Conversion between full-width and half-width characters
8
+ - Conversion between hiragana and katakana
9
+ - Conversion from kanji numerals to Arabic numerals and vice versa
10
+ - Conversion from old kanji to new kanji
11
+ - Flexible text processing through normalization and transformation
4
12
 
5
13
  ## Installation
6
14
 
7
- Add this line to your application's Gemfile:
15
+ Add the following line to your Gemfile:
8
16
 
17
+ ```ruby
9
18
  gem 'mojicon'
10
- And then execute:
19
+ ```
11
20
 
12
- $ bundle
13
- Or install it yourself as:
21
+ Then, install the Gem using Bundler:
22
+
23
+ ```ruby
24
+ bundle install
25
+ ```
14
26
 
15
- $ gem install mojicon
27
+ Or, you can install the Gem directly:
16
28
 
17
- ## Commands
29
+ ```ruby
30
+ gem install mojicon
31
+ ```
18
32
 
19
- Test command.
33
+ ## Usage
20
34
 
21
- ```sh
22
- rake
35
+ With Mojicon, you can apply methods directly to string objects. For example:
36
+
37
+ ```ruby
38
+ require 'mojicon'
39
+
40
+ str = "hoge"
41
+ puts str.han_to_zen
42
+ # => "hoge"
23
43
  ```
44
+
45
+ Available methods include:
46
+
47
+ - trim_space - Removes all full-width and half-width spaces from the string.
48
+ - zen_to_han - Converts full-width characters to half-width characters.
49
+ - han_to_zen - Converts half-width characters to full-width characters.
50
+ - kana_to_hira - Converts katakana to hiragana.
51
+ - hira_to_kana - Converts hiragana to katakana.
52
+ - kanji_to_arabic - Converts kanji numeral representations to Arabic numerals.
53
+ - arabic_to_kanji - Converts Arabic numerals to kanji numeral representations.
54
+
55
+ And many more.
56
+
57
+ ## How to Contribute
58
+
59
+ 1.Fork the repository.
60
+
61
+ 2.Create a feature branch (`git checkout -b feature/fooBar`).
62
+
63
+ 3.Commit your changes (`git commit -am 'Add some fooBar'`).
64
+
65
+ 4.Push to the branch (`git push origin feature/fooBar`).
66
+
67
+ 5.Create a new Pull Request.
68
+
69
+ ## License
70
+
71
+ This project is licensed under the MIT License.
@@ -7,11 +7,10 @@ module Mojicon
7
7
  using YaKansuji::CoreRefine
8
8
 
9
9
  def trim_space
10
- self&.delete(" ")&.delete(" ")
10
+ delete(" ")&.delete(" ")
11
11
  end
12
12
 
13
13
  def zen_to_han
14
- return self if self&.nil?
15
14
  return self unless match(/[^ -~。-゚]/)
16
15
 
17
16
  space_trimmed_word = tr(" ", " ")
@@ -20,48 +19,39 @@ module Mojicon
20
19
  end
21
20
 
22
21
  def han_to_zen
23
- return self if self&.nil?
24
-
25
22
  converted = tr("A-Za-z0-9", "A-Za-z0-9")
26
23
  space_converted = converted.tr(" ", " ")
27
24
  nkf_converted = NKF.nkf("-w -X", space_converted)
28
- nkf_converted.tr("\s!#$%&\'\"()⦅⦆⟨⟩*+,-./:;<=>?@[]^_`{|}~\\", " !#$%&'"()⦅⦆〈〉*+,-./:;<=>?@[]^_`{|}~\")
25
+ nkf_converted.tr("\s!#$%&\'\"()⦅⦆⟨⟩*+,-./:;<=>?@[]^_`−{|}~\\", " !#$%&'"()⦅⦆〈〉*+,-./:;<=>?@[]^_`-{|}~\")
29
26
  end
30
27
 
31
28
  def kana_to_hira
32
- self&.tr("ァ-ヶ", "ぁ-ん")
29
+ vu = tr("", "")
30
+ vu.tr("ァ-ヶ", "ぁ-ん")
33
31
  end
34
32
 
35
33
  def hira_to_kana
36
- self&.tr("ぁ-ん", "ァ-ヶ")
34
+ vu = tr("", "")
35
+ vu.tr("ぁ-ん", "ァ-ヶ")
37
36
  end
38
37
 
39
38
  def upper_to_down
40
- return self if self&.nil?
41
-
42
39
  downcased = downcase
43
- downcased.tr("あいうえおつやゆよ", "ぁぃぅぇぉっゃゅょ")
40
+ downcased.tr("あいうえおつやゆよアイウエオツヤユヨアイウエオツヤユヨ", "ぁぃぅぇぉっゃゅょァィゥェォッャュョァィゥェォッャュョ")
44
41
  end
45
42
 
46
43
  def down_to_upper
47
- return self if self&.nil?
48
-
49
44
  upcased = upcase
50
- upcased.tr("ぁぃぅぇぉっゃゅょ", "あいうえおつやゆよ")
45
+ upcased.tr("ぁぃぅぇぉっゃゅょァィゥェォッャュョァィゥェォッャュョ", "あいうえおつやゆよアイウエオツヤユヨアイウエオツヤユヨ")
51
46
  end
52
47
 
53
- def kanji_to_arabic(conversion_zenkaku: false)
48
+ def kanji_to_arabic
54
49
  kanji_pattern = /[一二三四五六七八九〇十百千万億兆]+/
55
50
  kanji_numbers = scan(kanji_pattern).map(&:to_i)
56
51
  replaced_str = gsub(kanji_pattern).with_index do |_match, index|
57
52
  kanji_numbers[index].to_s
58
53
  end
59
-
60
- if conversion_zenkaku
61
- replaced_str.han_to_zen
62
- else
63
- replaced_str
64
- end
54
+ replaced_str.zen_to_han
65
55
  end
66
56
 
67
57
  def arabic_to_kanji(zero: true)
@@ -74,6 +64,7 @@ module Mojicon
74
64
  YaKansuji.to_kan(arabic_numbers[index], :simple)
75
65
  end
76
66
  end
67
+ arabic_numbers.han_to_zen
77
68
  end
78
69
 
79
70
  def to_new_moji
@@ -81,9 +72,11 @@ module Mojicon
81
72
  end
82
73
 
83
74
  def equal?(other)
84
- return false if nil?
75
+ return false if other.nil?
76
+ return false unless other.is_a?(String)
77
+ return true if self == other
85
78
 
86
- candidate.include?(other)
79
+ candidate.include?(other.trim_space)
87
80
  end
88
81
 
89
82
  def candidate
@@ -95,26 +88,15 @@ module Mojicon
95
88
  trim_space.hira_to_kana,
96
89
  trim_space.upper_to_down,
97
90
  trim_space.down_to_upper,
98
- trim_space.zen_to_han.hira_to_kana,
99
- trim_space.han_to_zen.kana_to_hira,
100
- trim_space.han_to_zen.hira_to_kana,
101
- trim_space.kana_to_hira.zen_to_han,
102
- trim_space.kana_to_hira.han_to_zen,
103
- trim_space.hira_to_kana.zen_to_han,
104
- trim_space.hira_to_kana.han_to_zen,
105
- trim_space.upper_to_down.zen_to_han,
106
- trim_space.upper_to_down.han_to_zen,
107
- trim_space.upper_to_down.kana_to_hira,
108
- trim_space.upper_to_down.hira_to_kana,
109
- trim_space.down_to_upper.zen_to_han,
110
- trim_space.down_to_upper.han_to_zen,
111
- trim_space.down_to_upper.kana_to_hira,
112
- trim_space.down_to_upper.hira_to_kana,
113
- trim_space.to_new_moji,
114
- trim_space.arabic_to_kanji,
115
- trim_space.arabic_to_kanji(zero: true),
116
91
  trim_space.kanji_to_arabic,
117
- trim_space.kanji_to_arabic(conversion_zenkaku: true)
92
+ trim_space.arabic_to_kanji,
93
+ trim_space.arabic_to_kanji(zero: false),
94
+ trim_space.to_new_moji,
95
+ trim_space.hira_to_kana.zen_to_han,
96
+ trim_space.kanji_to_arabic.han_to_zen,
97
+ trim_space.arabic_to_kanji.zen_to_han,
98
+ trim_space.arabic_to_kanji(zero: false).zen_to_han,
99
+ trim_space.han_to_zen.kana_to_hira
118
100
  ].uniq
119
101
  end
120
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mojicon
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - philosophynote
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: factory_bot
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nkf
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: ya_kansuji
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,8 +81,10 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  description: |
70
- Converts hiragana, katakana, and kanji.
71
- It also performs conversion to upper and lower case letters and half-width and full-width characters.
84
+ Provides a wide range of text transformation functionalities,
85
+ including conversions between full-width and half-width characters,
86
+ kana and hiragana, kanji numerals to Arabic numerals,
87
+ Arabic numerals to kanji, and more.
72
88
  email:
73
89
  - adverdest@gmail.com
74
90
  executables: []
@@ -92,8 +108,8 @@ licenses:
92
108
  metadata:
93
109
  allowed_push_host: https://rubygems.org/
94
110
  homepage_uri: https://github.com/philosophynote/mojicon
95
- source_code_uri: https://github.com/philosophynote/mojicon/blob/v0.2.0/CHANGELOG.md
96
- changelog_uri: https://github.com/philosophynote/mojicon/tree/v0.2.0
111
+ source_code_uri: https://github.com/philosophynote/mojicon/blob/v0.3.0/CHANGELOG.md
112
+ changelog_uri: https://github.com/philosophynote/mojicon/tree/v0.3.0
97
113
  post_install_message:
98
114
  rdoc_options: []
99
115
  require_paths: