nkj 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +34 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +28 -0
- data/lib/nkj/range_table.rb +15 -0
- data/lib/nkj/unicode2jis_mapping.rb +18 -0
- data/lib/nkj/version.rb +5 -0
- data/lib/nkj.rb +75 -0
- data/nkj.gemspec +39 -0
- data/sig/nkj.rbs +4 -0
- data/source/unicode2jisx0213.yml +11234 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 478eb79767512a70602080f4cd1467530b56455b0a5968098e91feb5f57856c1
|
4
|
+
data.tar.gz: 68ff1fd4bda2b0525cc0defc76f37c56fb3d63b0376655eebd6c45e580616797
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2afcb917778d1ea2fd088bb95ed79e5bc40028ed8443048c3051d28c364b9b3aac2a11b06ef0b46cb688f2dec13d91a643354e663fb2831db96c6c131187a46
|
7
|
+
data.tar.gz: ef9f28d9b57dcab7aa3cbb5c36ded6eec9b9d8bf0d22734ca84327cc3314a96072cacdb621c7f5dd14c8aa72396a6ce62d1e6c7c0404419091f0e0425b99cc97
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
EnabledByDefault: true
|
4
|
+
SuggestExtensions: false
|
5
|
+
Exclude:
|
6
|
+
- "nkj.gemspec"
|
7
|
+
Bundler/GemComment:
|
8
|
+
Enabled: false
|
9
|
+
Bundler/GemVersion:
|
10
|
+
Enabled: false
|
11
|
+
Lint/ConstantResolution:
|
12
|
+
Enabled: false
|
13
|
+
Layout/SingleLineBlockChain:
|
14
|
+
Enabled: false
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
Style/ArrayFirstLast:
|
18
|
+
Enabled: false
|
19
|
+
Style/DocumentationMethod:
|
20
|
+
Enabled: false
|
21
|
+
Style/InlineComment:
|
22
|
+
Enabled: false
|
23
|
+
Style/Copyright:
|
24
|
+
Enabled: false
|
25
|
+
Style/ConstantVisibility:
|
26
|
+
Enabled: false
|
27
|
+
Style/RequireOrder:
|
28
|
+
Enabled: false
|
29
|
+
Style/MethodCallWithArgsParentheses:
|
30
|
+
Exclude:
|
31
|
+
- "spec/**/*"
|
32
|
+
Metrics/BlockLength:
|
33
|
+
Exclude:
|
34
|
+
- "spec/**/*"
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 nomuyoshi0111@gmail.com. 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 nomuyoshi
|
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,46 @@
|
|
1
|
+
# NKJ
|
2
|
+
NKJ can judge given chars are included in JIS X 0213 or not.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'nkj'
|
9
|
+
```
|
10
|
+
|
11
|
+
Or install it yourself as:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install nkj
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
require 'nkj'
|
21
|
+
|
22
|
+
# `jisx0213?` returns a boolean value whether or not the given all chars are included in JIS X 0213.
|
23
|
+
NKJ.jisx0213?('aあ!庵') #=> true
|
24
|
+
NKJ.jisx0213?('髙') #=> false
|
25
|
+
|
26
|
+
# `level1?` returns whether or not the given all chars are included Japanse Level1 Kanji.(第一水準)
|
27
|
+
NKJ.level1?('山') #=> true
|
28
|
+
|
29
|
+
# `level2?` returns whether or not the given all chars are included Japanse Level2 Kanji.(第二水準)
|
30
|
+
NKJ.level2?('丼') #=> true
|
31
|
+
|
32
|
+
# `level3?` returns whether or not the given all chars are included Japanse Level3 Kanji.(第三水準)
|
33
|
+
NKJ.level3?('﨑') #=> true
|
34
|
+
|
35
|
+
# `level4?` returns whether or not the given all chars are included Japanse Level4 Kanji.(第四水準)
|
36
|
+
NKJ.level4?('挻') #=> true
|
37
|
+
```
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
+
|
43
|
+
|
44
|
+
## Special Thanks
|
45
|
+
NKJ uses "JIS X 0213 Code Mapping Tables" which created by Project X0213.
|
46
|
+
https://x0213.org/codetable/index.en.html
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'yaml'
|
5
|
+
require 'open-uri'
|
6
|
+
require 'bundler/gem_tasks'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
task default: :spec
|
12
|
+
|
13
|
+
desc 'generate unicode2jisx0213.yml'
|
14
|
+
task :generate_unicode2jisx0213 do
|
15
|
+
uri = 'https://x0213.org/codetable/jisx0213-2004-8bit-std.txt'
|
16
|
+
file = OpenURI.open_uri(uri, 'r', &:read)
|
17
|
+
|
18
|
+
mapping = {}
|
19
|
+
CSV.parse(file, col_sep: "\t", skip_lines: /\A##/).each do |row|
|
20
|
+
unicode_point = row[1]
|
21
|
+
next if unicode_point.nil?
|
22
|
+
|
23
|
+
jis_code_point = Integer(row[0])
|
24
|
+
mapping[unicode_point] = jis_code_point
|
25
|
+
end
|
26
|
+
|
27
|
+
YAML.dump(mapping, File.open('./source/unicode2jisx0213.yml', 'w'))
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module NKJ
|
6
|
+
class Unicode2JISMapping
|
7
|
+
DATA = YAML.load_file(File.expand_path('../../source/unicode2jisx0213.yml', __dir__)).freeze
|
8
|
+
|
9
|
+
private_constant :DATA
|
10
|
+
def self.fetch(unicode_point)
|
11
|
+
DATA[unicode_point]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.exists?(unicode_point)
|
15
|
+
DATA.key?(unicode_point)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/nkj/version.rb
ADDED
data/lib/nkj.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require_relative 'nkj/version'
|
5
|
+
require_relative 'nkj/range_table'
|
6
|
+
require_relative 'nkj/unicode2jis_mapping'
|
7
|
+
|
8
|
+
module NKJ
|
9
|
+
class Error < StandardError; end
|
10
|
+
class << self
|
11
|
+
def jisx0213?(str)
|
12
|
+
each_grapheme_codepoint(encode(str)) do |cp|
|
13
|
+
return false unless Unicode2JISMapping.exists?(cp)
|
14
|
+
end
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def level1?(str)
|
20
|
+
level1_range_table = RangeTable.new((0x3021..0x4F53))
|
21
|
+
each_grapheme_codepoint(encode(str)) do |cp|
|
22
|
+
jis_cp = Unicode2JISMapping.fetch(cp)
|
23
|
+
return false unless level1_range_table.include?(jis_cp)
|
24
|
+
end
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def level2?(str)
|
30
|
+
level2_range_table = RangeTable.new((0x5021..0x7426))
|
31
|
+
each_grapheme_codepoint(encode(str)) do |cp|
|
32
|
+
jis_cp = Unicode2JISMapping.fetch(cp)
|
33
|
+
return false unless level2_range_table.include?(jis_cp)
|
34
|
+
end
|
35
|
+
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def level3?(str)
|
40
|
+
level3_range_table = RangeTable.new((0x2E21..0x2F7E), (0x4F54..0x4F7E), (0x7427..0x7E7E))
|
41
|
+
each_grapheme_codepoint(encode(str)) do |cp|
|
42
|
+
jis_cp = Unicode2JISMapping.fetch(cp)
|
43
|
+
return false unless level3_range_table.include?(jis_cp)
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def level4?(str)
|
50
|
+
level4_range_table = RangeTable.new((0xA1A1..0xFEF6))
|
51
|
+
each_grapheme_codepoint(encode(str)) do |cp|
|
52
|
+
jis_cp = Unicode2JISMapping.fetch(cp)
|
53
|
+
return false unless level4_range_table.include?(jis_cp)
|
54
|
+
end
|
55
|
+
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def each_grapheme_codepoint(str)
|
62
|
+
str.each_grapheme_cluster do |char|
|
63
|
+
cp = "U+#{char.codepoints.map { |p| format('%04X', p) }.join('+')}"
|
64
|
+
|
65
|
+
yield(cp)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def encode(str)
|
70
|
+
return str if str.encoding == Encoding::UTF_8
|
71
|
+
|
72
|
+
str.encode(Encoding::UTF_8)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/nkj.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/nkj/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'nkj'
|
7
|
+
spec.version = Nkj::VERSION
|
8
|
+
spec.authors = ['nomuyoshi']
|
9
|
+
|
10
|
+
spec.summary = 'NKJ is a library for identifying JIS X 0213 characters.'
|
11
|
+
spec.description = 'NKJ is a library for identifying JIS X 0213 characters.'
|
12
|
+
spec.homepage = 'https://github.com/nomuyoshi/nkj'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 3.0.0'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = 'https://github.com/nomuyoshi/nkj'
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/nomuyoshi/nkj'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/nomuyoshi/nkj/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(File.expand_path(f) == __FILE__) ||
|
25
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
spec.add_runtime_dependency 'csv', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 1.62'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
|
36
|
+
# For more information and examples about making a new gem, check out our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
39
|
+
end
|
data/sig/nkj.rbs
ADDED