jisx0208 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -23
- data/bump_new_version.sh +38 -0
- data/lib/jisx0208/processor.rb +18 -5
- data/lib/jisx0208/version.rb +1 -1
- data/lib/jisx0208.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4882fd21cc240c35aa206dae9dd52f9e9078345516a60a7647118b97643d04bd
|
4
|
+
data.tar.gz: 71c76bb9d4d02443ba45e1725665a6c8c024a0603fe2e36d4bbe4a38f69f3d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28c4747318ecd804242ac8b7558b6302a5278a248dd0edd11b9628c15ccf1a42a8408950a26c369bd1e5309c81bcf6948d3432e0f6118d0c6e76e32d37e99734
|
7
|
+
data.tar.gz: 669d0d3e8edc8e2817d8f38d670fdad09e60f0b77bb6e19a862dd8dbb54c995bf6762d1e1a013493752179b2a5570bc075a911a19a26d9c7b1e676a7393b82d9
|
data/README.md
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
# Jisx0208
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jisx0208`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
JIS X 0208 is a collection of common characters used in Japanese writing, place names, and people's names.
|
4
|
+
[jisx0208](https://rubygems.org/gems/jisx0208) is a Ruby gem that provides a simple way to check if a string contains [JIS X 0208 characters](https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/JIS0208.TXT).
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
8
|
+
```ruby
|
9
|
+
gem install jisx0208
|
10
|
+
```
|
18
11
|
|
19
12
|
## Usage
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
14
|
+
```ruby
|
15
|
+
require "jisx0208"
|
16
|
+
|
17
|
+
code = JISX0208::Code.new
|
18
|
+
code.contains_first_level_kanji?("亜") # => true
|
19
|
+
code.contains_first_level_kanji?("弌") # => false
|
20
|
+
code.contains_seconde_level_kanji?("弌") # => true
|
21
|
+
code.contains_seconde_level_kanji?("亜") # => false
|
22
|
+
# same as (contains_first_level_kanji || contains_seconde_level_kanji)
|
23
|
+
code.contains_jisx0208_kanji?("亜弌") # => true
|
24
|
+
|
25
|
+
code.only_first_level_kanji?("回転寿司") # => true
|
26
|
+
code.only_second_level_kanji?("偃龠偕") # => true
|
27
|
+
# same as (only_first_level_kanji || only_second_level_kanji)
|
28
|
+
code.only_jisx0208_kanji?("回転寿司偃龠偕") # => true
|
29
|
+
```
|
data/bump_new_version.sh
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
if [ -z "$1" ]; then
|
4
|
+
echo "Usage: $0 <version>"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
# ~/.gem/credentials
|
9
|
+
if [ ! -f ~/.gem/credentials ]; then
|
10
|
+
echo "Error: ~/.gem/credentials not found. Please set up your RubyGems credentials."
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
14
|
+
PROJECT_NAME="jisx0208"
|
15
|
+
GITHUB_REPO="kaibadash/jisx0208-ruby"
|
16
|
+
VERSION=$1
|
17
|
+
echo "Start bumping version: $VERSION"
|
18
|
+
|
19
|
+
# Publish
|
20
|
+
# Add release branch
|
21
|
+
git checkout master
|
22
|
+
git checkout -b release/$VERSION
|
23
|
+
sed -i '' "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/$PROJECT_NAME/version.rb
|
24
|
+
git commit -am "Bump version $VERSION"
|
25
|
+
|
26
|
+
# Publish to rubygems
|
27
|
+
gem build $PROJECT_NAME.gemspec
|
28
|
+
bundle install
|
29
|
+
gem push $PROJECT_NAME-$VERSION.gem
|
30
|
+
|
31
|
+
# GitHub release
|
32
|
+
git tag $VERSION
|
33
|
+
git push --tags
|
34
|
+
open https://github.com/$GITHUB_REPO/releases/new
|
35
|
+
|
36
|
+
# merge to master
|
37
|
+
git checkout master
|
38
|
+
git merge release/$VERSION
|
data/lib/jisx0208/processor.rb
CHANGED
@@ -7,11 +7,11 @@ module JISX0208
|
|
7
7
|
file_path = File.join(File.dirname(__FILE__), "..", "..", "data", "JIS0208.TXT")
|
8
8
|
file = File.open(file_path)
|
9
9
|
|
10
|
-
mappings = file.each_line.with_object(
|
10
|
+
mappings = file.each_line.with_object({}) do |line, hash|
|
11
11
|
next if line.start_with?("#")
|
12
12
|
|
13
|
-
_sjis,
|
14
|
-
|
13
|
+
_sjis, jisx, unicode, _others = line.split(" ")
|
14
|
+
hash[jisx.to_i(16)] = unicode.to_i(16)
|
15
15
|
end
|
16
16
|
|
17
17
|
# see http://ash.jp/code/unitbl21.htm
|
@@ -31,11 +31,24 @@ module JISX0208
|
|
31
31
|
contains_first_level_kanji?(string) || contains_seconde_level_kanji?(string)
|
32
32
|
end
|
33
33
|
|
34
|
+
def only_first_level_kanji?(string)
|
35
|
+
string.each_char.all? { |char| @first_level_ranges.include?(char.ord) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def only_second_level_kanji?(string)
|
39
|
+
string.each_char.all? { |char| @second_level_ranges.include?(char.ord) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def only_jisx0208_kanji?(string)
|
43
|
+
jisx0208 = @first_level_ranges + @second_level_ranges
|
44
|
+
string.each_char.all? { |char| jisx0208.include?(char.ord) }
|
45
|
+
end
|
46
|
+
|
34
47
|
private
|
35
48
|
|
36
49
|
def collect_unicode_set(mappings, jisx_start, jisx_end)
|
37
|
-
mappings.map do |
|
38
|
-
|
50
|
+
mappings.map do |jisx, unicode|
|
51
|
+
unicode if jisx.between?(jisx_start, jisx_end)
|
39
52
|
end.compact.to_set
|
40
53
|
end
|
41
54
|
end
|
data/lib/jisx0208/version.rb
CHANGED
data/lib/jisx0208.rb
CHANGED
@@ -20,5 +20,17 @@ module JISX0208
|
|
20
20
|
def contains_jisx0208_kanji?(string)
|
21
21
|
@processor.contains_jisx0208_kanji?(string)
|
22
22
|
end
|
23
|
+
|
24
|
+
def only_first_level_kanji?(string)
|
25
|
+
@processor.only_first_level_kanji?(string)
|
26
|
+
end
|
27
|
+
|
28
|
+
def only_second_level_kanji?(string)
|
29
|
+
@processor.only_second_level_kanji?(string)
|
30
|
+
end
|
31
|
+
|
32
|
+
def only_jisx0208_kanji?(string)
|
33
|
+
@processor.only_jisx0208_kanji?(string)
|
34
|
+
end
|
23
35
|
end
|
24
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jisx0208
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaiba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Determines if a character is included in jisx0208 with JIS0208.TXT
|
14
14
|
email:
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
24
|
+
- bump_new_version.sh
|
24
25
|
- data/JIS0208.TXT
|
25
26
|
- lib/jisx0208.rb
|
26
27
|
- lib/jisx0208/processor.rb
|