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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c48c2d17a1bfcc48ced6fa08d1f4a7c0e52c3d4a77035417c770eb8274f3c376
4
- data.tar.gz: d44c10021302f56565593f73b8b12940f38b06fa45589ce87421e7f49e61d5ff
3
+ metadata.gz: 4882fd21cc240c35aa206dae9dd52f9e9078345516a60a7647118b97643d04bd
4
+ data.tar.gz: 71c76bb9d4d02443ba45e1725665a6c8c024a0603fe2e36d4bbe4a38f69f3d5c
5
5
  SHA512:
6
- metadata.gz: f23a2a93ec9ff3f75e8f5dc9ad501acd3064f6782c97b88b282465709d15acfa196889ab1008e09fab3921c869c32d1dc8c99f6b5db47f95ca46607397d00700
7
- data.tar.gz: add62814b07b9a6e36bfd2a2621bfb09f8fe799a64e6bf3240826d5492eb4174ca51912b6f65a03fc2e6b56083b788b4e77714c318559f7485e48ff0f608b763
6
+ metadata.gz: 28c4747318ecd804242ac8b7558b6302a5278a248dd0edd11b9628c15ccf1a42a8408950a26c369bd1e5309c81bcf6948d3432e0f6118d0c6e76e32d37e99734
7
+ data.tar.gz: 669d0d3e8edc8e2817d8f38d670fdad09e60f0b77bb6e19a862dd8dbb54c995bf6762d1e1a013493752179b2a5570bc075a911a19a26d9c7b1e676a7393b82d9
data/README.md CHANGED
@@ -1,31 +1,29 @@
1
1
  # Jisx0208
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
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
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jisx0208.
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
+ ```
@@ -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
@@ -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([]) do |line, arr|
10
+ mappings = file.each_line.with_object({}) do |line, hash|
11
11
  next if line.start_with?("#")
12
12
 
13
- _sjis, _, unicode, _others = line.split(" ")
14
- arr << { jisx: unicode.to_i(16) }
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 |unicode_value|
38
- unicode_value[:jisx] if unicode_value[:jisx].between?(jisx_start, jisx_end)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jisx0208
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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-16 00:00:00.000000000 Z
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