jisx0208 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JISX0208
4
+ class Processor
5
+ def initialize
6
+ # https://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/JIS0208.TXT
7
+ file_path = File.join(File.dirname(__FILE__), "..", "..", "data", "JIS0208.TXT")
8
+ file = File.open(file_path)
9
+
10
+ mappings = file.each_line.with_object([]) do |line, arr|
11
+ next if line.start_with?("#")
12
+
13
+ _sjis, _, unicode, _others = line.split(" ")
14
+ arr << { jisx: unicode.to_i(16) }
15
+ end
16
+
17
+ # see http://ash.jp/code/unitbl21.htm
18
+ @first_level_ranges = collect_unicode_set(mappings, 0x3021, 0x4F53)
19
+ @second_level_ranges = collect_unicode_set(mappings, 0x5021, 0x7426)
20
+ end
21
+
22
+ def contains_first_level_kanji?(string)
23
+ string.each_char.any? { |char| @first_level_ranges.include?(char.ord) }
24
+ end
25
+
26
+ def contains_seconde_level_kanji?(string)
27
+ string.each_char.any? { |char| @second_level_ranges.include?(char.ord) }
28
+ end
29
+
30
+ def contains_jisx0208_kanji?(string)
31
+ contains_first_level_kanji?(string) || contains_seconde_level_kanji?(string)
32
+ end
33
+
34
+ private
35
+
36
+ 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)
39
+ end.compact.to_set
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jisx0208
4
+ VERSION = "0.1.0"
5
+ end
data/lib/jisx0208.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "jisx0208/version"
4
+ require_relative "jisx0208/processor"
5
+
6
+ module JISX0208
7
+ class Code
8
+ def initialize
9
+ @processor = Processor.new
10
+ end
11
+
12
+ def contains_first_level_kanji?(string)
13
+ @processor.contains_first_level_kanji?(string)
14
+ end
15
+
16
+ def contains_second_level_kanji?(string)
17
+ @processor.contains_seconde_level_kanji?(string)
18
+ end
19
+
20
+ def contains_jisx0208_kanji?(string)
21
+ @processor.contains_jisx0208_kanji?(string)
22
+ end
23
+ end
24
+ end
data/sig/jisx0208.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Jisx0208
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jisx0208
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kaiba
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-11-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Determines if a character is included in jisx0208 with JIS0208.TXT
14
+ email:
15
+ - kaibadash@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rubocop.yml"
21
+ - LICENSE
22
+ - README.md
23
+ - Rakefile
24
+ - data/JIS0208.TXT
25
+ - lib/jisx0208.rb
26
+ - lib/jisx0208/processor.rb
27
+ - lib/jisx0208/version.rb
28
+ - sig/jisx0208.rbs
29
+ homepage: https://github.com/kaibadash/jisx0208-ruby
30
+ licenses: []
31
+ metadata:
32
+ homepage_uri: https://github.com/kaibadash/jisx0208-ruby
33
+ source_code_uri: https://github.com/kaibadash/jisx0208-ruby
34
+ changelog_uri: https://github.com/kaibadash/jisx0208-ruby
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 3.5.3
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Determines if a character is included in jisx0208
54
+ test_files: []