mojicon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: db7cd5aff5f9ba028aae72bf783c695e300eb310f02954741d70e3ffead9a42f
4
+ data.tar.gz: cdc5ffe98bfbc894eb2dfe7fcdeffb5fd8c599ba5dbd187d1b0bc1c5e43b94f3
5
+ SHA512:
6
+ metadata.gz: fead8e5e794b714c9efcdc17566bdf3e377b592ea1c804653f482a4f10f1e017f12c2085a86548a156b27226ba516dae4f7490ec3a43bae3d7f3f0c580e89b04
7
+ data.tar.gz: d82911b162745ee1ea884e53141e0dc9f7a243a946a9fa72037aa5fe002c3a79db8d58772dcaf0c285f22074b217ffdf0b3f98319021222cd7b928078806e4a0
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6.0
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Style/FrozenStringLiteralComment:
8
+ Enabled: false
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Layout/LineLength:
19
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-01-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # mojicon
2
+
3
+ Convert japanese character
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mojicon'
10
+ And then execute:
11
+
12
+ $ bundle
13
+ Or install it yourself as:
14
+
15
+ $ gem install mojicon
16
+
17
+ ## Commands
18
+
19
+ Test command.
20
+
21
+ ```sh
22
+ rake
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,121 @@
1
+ require "nkf"
2
+ require "itaiji"
3
+ require "ya_kansuji"
4
+
5
+ module Mojicon
6
+ module Converter
7
+ using YaKansuji::CoreRefine
8
+
9
+ def trim_space
10
+ self&.delete(" ")&.delete(" ")
11
+ end
12
+
13
+ def zen_to_han
14
+ return self if self&.nil?
15
+ return self unless match(/[^ -~。-゚]/)
16
+
17
+ space_trimmed_word = tr(" ", " ")
18
+ nkf_converted = NKF.nkf("-Z4 -w", space_trimmed_word)
19
+ nkf_converted.tr("⦅⦆", "⦅⦆")
20
+ end
21
+
22
+ def han_to_zen
23
+ return self if self&.nil?
24
+
25
+ converted = tr("A-Za-z0-9", "A-Za-z0-9")
26
+ space_converted = converted.tr(" ", " ")
27
+ nkf_converted = NKF.nkf("-w -X", space_converted)
28
+ nkf_converted.tr("\s!#$%&\'\"()⦅⦆⟨⟩*+,-./:;<=>?@[]^_`{|}~\\", " !#$%&'"()⦅⦆〈〉*+,-./:;<=>?@[]^_`{|}~\")
29
+ end
30
+
31
+ def kana_to_hira
32
+ self&.tr("ァ-ヶ", "ぁ-ん")
33
+ end
34
+
35
+ def hira_to_kana
36
+ self&.tr("ぁ-ん", "ァ-ヶ")
37
+ end
38
+
39
+ def upper_to_down
40
+ return self if self&.nil?
41
+
42
+ downcased = downcase
43
+ downcased.tr("あいうえおつやゆよ", "ぁぃぅぇぉっゃゅょ")
44
+ end
45
+
46
+ def down_to_upper
47
+ return self if self&.nil?
48
+
49
+ upcased = upcase
50
+ upcased.tr("ぁぃぅぇぉっゃゅょ", "あいうえおつやゆよ")
51
+ end
52
+
53
+ def kanji_to_arabic(conversion_zenkaku: false)
54
+ kanji_pattern = /[一二三四五六七八九〇十百千万億兆]+/
55
+ kanji_numbers = scan(kanji_pattern).map(&:to_i)
56
+ replaced_str = gsub(kanji_pattern).with_index do |_match, index|
57
+ kanji_numbers[index].to_s
58
+ end
59
+
60
+ if conversion_zenkaku
61
+ replaced_str.han_to_zen
62
+ else
63
+ replaced_str
64
+ end
65
+ end
66
+
67
+ def arabic_to_kanji(zero: true)
68
+ arabic_pattern = /[\d0-9]+/
69
+ arabic_numbers = zen_to_han.scan(arabic_pattern).map(&:to_i)
70
+ arabic_numbers = gsub(arabic_pattern).with_index do |_match, index|
71
+ if zero
72
+ YaKansuji.to_kan(arabic_numbers[index], :judic_v)
73
+ else
74
+ YaKansuji.to_kan(arabic_numbers[index], :simple)
75
+ end
76
+ end
77
+ end
78
+
79
+ def to_new_moji
80
+ Itaiji::Converter.new.seijitai(self)
81
+ end
82
+
83
+ def equal?(other)
84
+ return false if nil?
85
+
86
+ candidate.include?(other)
87
+ end
88
+
89
+ def candidate
90
+ [
91
+ trim_space,
92
+ trim_space.zen_to_han,
93
+ trim_space.han_to_zen,
94
+ trim_space.kana_to_hira,
95
+ trim_space.hira_to_kana,
96
+ trim_space.upper_to_down,
97
+ 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
+ trim_space.kanji_to_arabic,
117
+ trim_space.kanji_to_arabic(conversion_zenkaku: true),
118
+ ].uniq
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mojicon
4
+ VERSION = "0.1.0"
5
+ end
data/lib/mojicon.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mojicon/version"
4
+ require "mojicon/converter"
5
+
6
+ class String
7
+ include Mojicon::Converter
8
+ class Error < StandardError; end
9
+ end
data/sig/mojicon.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Mojicon
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mojicon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - philosophynote
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-03-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "\n Converts hiragana, katakana, and kanji.\n It also performs conversion
14
+ to upper and lower case letters and half-width and full-width characters.\n "
15
+ email:
16
+ - adverdest@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/mojicon.rb
29
+ - lib/mojicon/converter.rb
30
+ - lib/mojicon/version.rb
31
+ - sig/mojicon.rbs
32
+ homepage: https://github.com/philosophynote/mojicon
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org/
37
+ homepage_uri: https://github.com/philosophynote/mojicon
38
+ source_code_uri: https://github.com/philosophynote/mojicon/blob/v0.1.0/CHANGELOG.md
39
+ changelog_uri: https://github.com/philosophynote/mojicon/tree/v0.1.0
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.5.3
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Japanese converter
59
+ test_files: []