whatlang 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5b245173c946709df258efa77b2e253d062ecd79087cde657919f488d3f08b8
4
- data.tar.gz: ec4cd29f02a29bfd44c66b31ee8cd5e2aec9b5be6db126897dbf7214ccb7ad73
3
+ metadata.gz: b63c656fd014ba105b808ee8b7a80b31f6223fb59d988123f60b74e35b30ffa2
4
+ data.tar.gz: 2317a34d7f831f2c27ddaadb7b9694b546c0ae9013e133e09776c55956819d38
5
5
  SHA512:
6
- metadata.gz: e13e54ad577c1949673739ab8a02dab3405dd19f7ac3602d47232cf5f746576be8c0d23de36efc02ac1837e8bbaeb41a21fff9a7eecf6170bf0a6b782fbb246f
7
- data.tar.gz: 89832e91d3b3be94a019416f95627c5fe8e46981a0066a85a0b3a758bae333a72572dba8a31197ef3665c0ec8fe61a5b601792beb18367c306ad17f07c6ac37c
6
+ metadata.gz: c2656f9ff575b44e1e763537c290e725d217d9ed0b74cfd713b5c84a4c2b797ae9bec0b614202f8b5e544a012feeeba80e42e669ad4df2b94698e568a0b485a5
7
+ data.tar.gz: 57c662f065d1fc43f4f3ef6ee9655af9bdc91b245901dfba8b5dd5c8a61a42251d8605d3cd0862029ab3e228544beba334c68e2d747e9da39b893791b1b2ac2a
data/.gitignore CHANGED
@@ -8,5 +8,8 @@
8
8
  /tmp/
9
9
  Gemfile.lock
10
10
  /lib/whatlang.bundle
11
- /whatlang.bundle
11
+ /ext/whatlang.bundle
12
12
  /ext/target/
13
+ /ext/release/
14
+ /ext/.rustc_info.json
15
+ target/
data/.gitlab-ci.yml CHANGED
@@ -1,6 +1,5 @@
1
- default:
2
- image: ruby:3.4.7
3
-
1
+ test:
2
+ image: ruby:$RUBY_VERSION
4
3
  before_script:
5
4
  - apt-get update && apt-get install -y clang
6
5
  - curl https://sh.rustup.rs -sSf | sh -s -- -y
@@ -8,9 +7,10 @@ default:
8
7
  - gem update --system
9
8
  - gem install bundler
10
9
  - bundle install
11
-
12
- test:
13
10
  variables:
14
11
  RB_SYS_FORCE_INSTALL_RUST_TOOLCHAIN: 'true'
15
12
  script:
16
13
  - source "$HOME/.cargo/env" && rake test
14
+ parallel:
15
+ matrix:
16
+ - RUBY_VERSION: ["3.2", "3.3", "3.4", "4.0"]
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 0.2.1
2
+ =====
3
+
4
+ * Switch Rust glue library from [Magnus][] to [Rutie][]
5
+
1
6
  0.2.0
2
7
  =====
3
8
 
data/Cargo.lock ADDED
@@ -0,0 +1,72 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "allocator-api2"
7
+ version = "0.2.21"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
10
+
11
+ [[package]]
12
+ name = "equivalent"
13
+ version = "1.0.2"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
16
+
17
+ [[package]]
18
+ name = "foldhash"
19
+ version = "0.1.5"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
22
+
23
+ [[package]]
24
+ name = "hashbrown"
25
+ version = "0.15.5"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
28
+ dependencies = [
29
+ "allocator-api2",
30
+ "equivalent",
31
+ "foldhash",
32
+ ]
33
+
34
+ [[package]]
35
+ name = "lazy_static"
36
+ version = "1.5.1"
37
+ source = "registry+https://github.com/rust-lang/crates.io-index"
38
+ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
39
+
40
+ [[package]]
41
+ name = "libc"
42
+ version = "0.2.190"
43
+ source = "registry+https://github.com/rust-lang/crates.io-index"
44
+ checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"
45
+
46
+ [[package]]
47
+ name = "rutie"
48
+ version = "0.14.1"
49
+ source = "registry+https://github.com/rust-lang/crates.io-index"
50
+ checksum = "2f2bb20b12c4e3f307de8021dbf6f2b7396dbc203c1c9a2beeabd32aa9522e5e"
51
+ dependencies = [
52
+ "lazy_static",
53
+ "libc",
54
+ ]
55
+
56
+ [[package]]
57
+ name = "whatlang"
58
+ version = "0.2.1"
59
+ dependencies = [
60
+ "lazy_static",
61
+ "rutie",
62
+ "whatlang 0.18.0",
63
+ ]
64
+
65
+ [[package]]
66
+ name = "whatlang"
67
+ version = "0.18.0"
68
+ source = "registry+https://github.com/rust-lang/crates.io-index"
69
+ checksum = "f5e8f38b596e2a359b755342473520a99421e43658548c79489ee221b728c107"
70
+ dependencies = [
71
+ "hashbrown",
72
+ ]
@@ -1,14 +1,14 @@
1
1
  [package]
2
2
  name = "whatlang"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  authors = ["Kitaiti Makoto <KitaitiMakoto@gmail.com>"]
5
5
  edition = "2024"
6
6
  publish = false
7
7
 
8
8
  [dependencies]
9
- magnus = "0.8"
9
+ lazy_static = "1.5.1"
10
+ rutie = "0.14"
10
11
  whatlang-rs = { package = "whatlang", version = "0.18.0", registry = "crates-io" }
11
- rb-sys = { version = "*", features = ["stable-api-compiled-fallback"] }
12
12
 
13
13
  [lib]
14
14
  crate-type = ["cdylib"]
data/Rakefile CHANGED
@@ -1,37 +1,26 @@
1
1
  require "rake/clean"
2
- require "rubygems/ext"
3
2
  require "rubygems/tasks"
4
3
  require "rake/testtask"
5
4
  require "yard"
6
- require "shellwords"
5
+ require "rutie/rake_task"
6
+ require "kar/dsl"
7
7
 
8
- task default: :test
8
+ TARGET = "target/release/libwhatlang.#{RbConfig::CONFIG['SOEXT']}"
9
9
 
10
- GEMSPEC = Gem::Specification.load("whatlang.gemspec")
11
- MANIFEST = GEMSPEC.extensions.first
10
+ task default: :test
12
11
 
13
- CARGO_LOCK = "ext/Cargo.lock"
14
- file CARGO_LOCK => MANIFEST do |t|
15
- pkgid = `cargo pkgid --manifest-path=#{t.source.shellescape}`.chomp
16
- system "cargo", "update", "--manifest-path", t.source, pkgid, exception: true
17
- end
12
+ gem_tasks = Gem::Tasks.new
18
13
 
19
- SO_NAME = "#{GEMSPEC.name}.#{RbConfig::CONFIG["DLEXT"]}"
20
- SO_PATH = File.join("lib", SO_NAME)
21
- SRC = FileList["ext/src/**/*.rs"]
22
- file SO_PATH => [CARGO_LOCK] + SRC do
23
- results = Rake.verbose == true ? $stdout : []
24
- Gem::Ext::CargoBuilder.new.build MANIFEST, ".", results, [], "lib", File.expand_path("ext")
14
+ file TARGET do |t|
15
+ chdir "ext" do
16
+ sh "rake"
17
+ end
25
18
  end
26
- CLEAN.include SO_NAME
27
- CLOBBER.include SO_PATH
28
19
 
29
- Gem::Tasks.new
30
- task build: CARGO_LOCK
31
- CLOBBER.include("pkg/#{GEMSPEC.file_name}")
20
+ Rake::TestTask.new test: TARGET
21
+ Rutie::RakeTask.new
32
22
 
33
- Rake::TestTask.new
34
- task test: SO_PATH
23
+ task clean: "rutie:clean"
35
24
 
36
25
  YARD::Rake::YardocTask.new
37
26
  desc "Generate Ruby and Rust documentation"
data/ext/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require "rutie/rake_task"
2
+
3
+ RUBY_TO_RUTIE = {
4
+ "3.2" => "0.13",
5
+ "3.3" => "0.13",
6
+ "3.4" => "0.13",
7
+ "4.0" => "0.14"
8
+ }
9
+
10
+ task default: "rutie:build"
11
+
12
+ ruby_version = [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".")
13
+ rutie_version = RUBY_TO_RUTIE[ruby_version]
14
+ unless rutie_version
15
+ abort "Unsupported Ruby version. Available versions are: #{RUBY_TO_RUTIE.keys.join(', ')}"
16
+ end
17
+ sh "cargo", "add", "rutie@#{rutie_version}"
18
+
19
+ Rutie::RakeTask.new
data/lib/whatlang.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "rutie"
2
+
3
+ Rutie.new(:whatlang).init "Init_whatlang", __dir__
data/src/lib.rs ADDED
@@ -0,0 +1,192 @@
1
+ use rutie::{AnyException, AnyObject, Array, Boolean, Class, Exception, Float, Module, NilClass, Object, RString, VM, class, methods, module, rutie_callback, types::Argc, util::parse_arguments, wrappable_struct};
2
+ use whatlang_rs as wl;
3
+
4
+ module!(Whatlang);
5
+
6
+ wrappable_struct!(wl::Lang, LangWrapper, LANG_WRAPPER);
7
+
8
+ class!(Lang);
9
+
10
+ fn get_lang(rtself: &Lang) -> wl::Lang {
11
+ *rtself.get_data(&*LANG_WRAPPER)
12
+ }
13
+
14
+ impl Lang {
15
+ fn new(lang: wl::Lang) -> AnyObject {
16
+ Module::from_existing("Whatlang").get_nested_class("Lang").wrap_data(lang, &*LANG_WRAPPER)
17
+ }
18
+ }
19
+
20
+ methods!(
21
+ Lang,
22
+ rtself,
23
+
24
+ fn wl_lang_all() -> Array {
25
+ let langs = wl::Lang::all();
26
+ let mut ary = Array::with_capacity(langs.len());
27
+ for lang in langs {
28
+ ary.push(Lang::new(*lang));
29
+ }
30
+ ary
31
+ }
32
+
33
+ fn wl_lang_code() -> RString {
34
+ get_lang(&rtself).code().into()
35
+ }
36
+
37
+ fn wl_lang_name() -> RString {
38
+ get_lang(&rtself).name().into()
39
+ }
40
+
41
+ fn wl_lang_eng_name() -> RString {
42
+ get_lang(&rtself).eng_name().into()
43
+ }
44
+ );
45
+
46
+ wrappable_struct!(wl::Info, InfoWrapper, INFO_WRAPPER);
47
+
48
+ class!(Info);
49
+
50
+ impl Info {
51
+ fn new(info: wl::Info) -> AnyObject {
52
+ Module::from_existing("Whatlang").get_nested_class("Info").wrap_data(info, &*INFO_WRAPPER)
53
+ }
54
+ }
55
+
56
+ methods!(
57
+ Info,
58
+ rtself,
59
+
60
+ fn wl_info_lang() -> AnyObject {
61
+ Lang::new(rtself.get_data(&*INFO_WRAPPER).lang())
62
+ }
63
+
64
+ fn wl_info_script() -> RString {
65
+ rtself.get_data(&*INFO_WRAPPER).script().name().to_owned().into()
66
+ }
67
+
68
+ fn wl_info_confidence() -> Float {
69
+ Float::new(rtself.get_data(&*INFO_WRAPPER).confidence())
70
+ }
71
+
72
+ fn wl_info_is_reliable() -> Boolean {
73
+ Boolean::new(rtself.get_data(&*INFO_WRAPPER).is_reliable())
74
+ }
75
+ );
76
+
77
+ rutie_callback! {
78
+ fn wl_detect(argc: Argc, argv: *const AnyObject, _rtself: AnyObject) -> AnyObject {
79
+ let arguments = parse_arguments(argc, argv);
80
+ let args = match VM::scan_args(&arguments, "10:") {
81
+ Ok(args) => args,
82
+ Err(error) => VM::raise_message(error.class(), &error.message())
83
+ };
84
+
85
+ let Ok(text) = args.required[0].try_convert_to::<RString>() else {
86
+ return NilClass::new().into()
87
+ };
88
+
89
+ let keywords = VM::get_kwargs((&args.keywords).into(), &[], &["allowlist", "denylist"], false).map_err(VM::raise_ex).unwrap();
90
+
91
+ let info = match (keywords.optional[0].clone(), keywords.optional[1].clone()) {
92
+ (Some(..), Some(..)) => {
93
+ VM::raise_message(Class::argument_error(), "Couldn't specify `allowlist' and `denylist' at a time. Choose one.");
94
+ },
95
+ (Some(allowlist), None) => detect_with_allowlist(text.to_str(), lang_list(allowlist.try_convert_to::<Array>().map_err(VM::raise_ex).unwrap())),
96
+ (None, Some(denylist)) => detect_with_denylist(text.to_str(), lang_list(denylist.try_convert_to::<Array>().map_err(VM::raise_ex).unwrap())),
97
+ (None, None) => detect_without_options(text.to_str())
98
+ };
99
+ option_to_nillable(info)
100
+ }
101
+ }
102
+
103
+ methods!(
104
+ Whatlang,
105
+ _rtself,
106
+
107
+ fn wl_detect_without_options(text: RString) -> AnyObject {
108
+ let text = text.map_err(VM::raise_ex).unwrap();
109
+ let info = detect_without_options(text.to_str());
110
+ option_to_nillable(info)
111
+ }
112
+
113
+ fn wl_detect_with_allowlist(text: RString, allowlist: Array) -> AnyObject {
114
+ let text = text.map_err(VM::raise_ex).unwrap();
115
+ let allowlist = allowlist.map_err(VM::raise_ex).unwrap();
116
+ let info = detect_with_allowlist(text.to_str(), lang_list(allowlist));
117
+ option_to_nillable(info)
118
+ }
119
+
120
+ fn wl_detect_with_denylist(text: RString, denylist: Array) -> AnyObject {
121
+ let text = text.map_err(VM::raise_ex).unwrap();
122
+ let denylist = denylist.map_err(VM::raise_ex).unwrap();
123
+ let info = detect_with_denylist(text.to_str(), lang_list(denylist));
124
+ option_to_nillable(info)
125
+ }
126
+
127
+ fn wl_detect_lang(text: RString) -> AnyObject {
128
+ let lang = wl::detect_lang(rstring(text).to_str()).map(Lang::new);
129
+ option_to_nillable(lang)
130
+ }
131
+
132
+ fn wl_detect_script(text: RString) -> AnyObject {
133
+ let script = wl::detect_script(rstring(text).to_str())
134
+ .map(|script| RString::new_utf8(script.name()).into());
135
+ option_to_nillable(script)
136
+ }
137
+ );
138
+
139
+ fn detect_without_options(text: &str) -> Option<AnyObject> {
140
+ wl::detect(text).map(Info::new)
141
+ }
142
+
143
+ fn detect_with_allowlist(text: &str, allowlist: Vec<wl::Lang>) -> Option<AnyObject> {
144
+ wl::Detector::with_allowlist(allowlist)
145
+ .detect(text)
146
+ .map(Info::new)
147
+ }
148
+
149
+ fn detect_with_denylist(text: &str, denylist: Vec<wl::Lang>) -> Option<AnyObject> {
150
+ wl::Detector::with_denylist(denylist)
151
+ .detect(text)
152
+ .map(Info::new)
153
+ }
154
+
155
+ fn rstring(s: Result<RString, AnyException>) -> RString {
156
+ s.map_err(VM::raise_ex).unwrap()
157
+ }
158
+
159
+ fn lang_list(list: Array) -> Vec<wl::Lang> {
160
+ list.into_iter().filter_map(|s| wl::Lang::from_code(s.as_string().to_str())).collect()
161
+ }
162
+
163
+ fn option_to_nillable(nillable: Option<AnyObject>) -> AnyObject {
164
+ nillable.unwrap_or_else(|| NilClass::new().into())
165
+ }
166
+
167
+ #[allow(non_snake_case)]
168
+ #[unsafe(no_mangle)]
169
+ pub extern "C" fn Init_whatlang() {
170
+ Module::new("Whatlang").define(|whatlang| {
171
+ whatlang.def_self("detect", wl_detect);
172
+ whatlang.def_self("detect_with_allowlist", wl_detect_with_allowlist);
173
+ whatlang.def_self("detect_without_options", wl_detect_without_options);
174
+ whatlang.def_self("detect_with_denylist", wl_detect_with_denylist);
175
+ whatlang.def_self("detect_lang", wl_detect_lang);
176
+ whatlang.def_self("detect_script", wl_detect_script);
177
+
178
+ whatlang.define_nested_class("Lang", None).define(|lang| {
179
+ lang.def_self("all", wl_lang_all);
180
+ lang.def("code", wl_lang_code);
181
+ lang.def("name", wl_lang_name);
182
+ lang.def("eng_name", wl_lang_eng_name);
183
+ });
184
+
185
+ whatlang.define_nested_class("Info", None).define(|info| {
186
+ info.def("lang", wl_info_lang);
187
+ info.def("script", wl_info_script);
188
+ info.def("confidence", wl_info_confidence);
189
+ info.def("is_reliable", wl_info_is_reliable);
190
+ });
191
+ });
192
+ }
data/test/test_package.rb CHANGED
@@ -14,18 +14,18 @@ class TestPackage < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  class TestInstall < self
17
- def setup
18
- system "rake", "build", exception: true
19
- end
20
-
21
17
  def test_install
22
18
  gemspec = Gem::Specification.load("whatlang.gemspec")
23
19
  Dir.mktmpdir do |dir|
24
20
  dir = File.realpath(dir)
25
- system "gem", "install", "--install-dir", dir.shellescape, "--no-document", "pkg/#{gemspec.file_name.shellescape}", exception: true
26
- assert_installed dir, gemspec.version
21
+ gemfile = File.join(dir, gemspec.full_name + ".gem")
22
+ system "gem", "build", "whatlang.gemspec", "--output", gemfile, exception: true
23
+ install_dir = File.join(dir, "install")
24
+ FileUtils.mkdir install_dir
25
+ system "gem", "install", "--install-dir", install_dir, "--no-document", gemfile, exception: true
26
+ assert_installed install_dir, gemspec.version
27
27
 
28
- libdir = File.join(dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
28
+ libdir = File.join(install_dir, "gems", "#{gemspec.name}-#{gemspec.version}", "lib")
29
29
  assert_match(/ita/, `ruby -I #{libdir.shellescape} -r whatlang -e 'print Whatlang.detect("Jen la trinkejo fermitis, ni iras tra mallumo kaj pluvo.", allowlist: ["eng", "ita"]).lang.code'`)
30
30
  end
31
31
  end
@@ -33,7 +33,7 @@ class TestPackage < Test::Unit::TestCase
33
33
  private
34
34
 
35
35
  def assert_installed(dir, version)
36
- assert_path_exist File.join(dir, "gems/whatlang-#{version}/lib", "whatlang.#{RbConfig::CONFIG["DLEXT"]}")
36
+ assert_path_exist File.join(dir, "gems", "whatlang-#{version}", "target", "release", "libwhatlang.#{RbConfig::CONFIG["SOEXT"]}")
37
37
  end
38
38
  end
39
39
  end
@@ -43,6 +43,8 @@ class TestWhatlang < Test::Unit::TestCase
43
43
  def test_detect_script
44
44
  text = "Благодаря Эсперанто вы обрётете друзей по всему миру!"
45
45
  assert_equal "Cyrillic", Whatlang.detect_script(text)
46
+
47
+ assert_nil Whatlang.detect_script("")
46
48
  end
47
49
 
48
50
  def test_detect_empty_string
data/whatlang.gemspec CHANGED
@@ -2,7 +2,7 @@ require "json"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "whatlang"
5
- spec.version = JSON.parse(`cargo metadata --no-deps --format-version=1 --manifest-path=ext/Cargo.toml`)["packages"][0]["version"]
5
+ spec.version = JSON.parse(`cargo metadata --no-deps --format-version=1`)["packages"][0]["version"]
6
6
  spec.license = "Ruby"
7
7
  spec.authors = ["Kitaiti Makoto"]
8
8
  spec.email = ["KitaitiMakoto@gmail.com"]
@@ -15,15 +15,19 @@ Gem::Specification.new do |spec|
15
15
  spec.metadata["source_code_uri"] = "https://gitlab.com/KitaitiMakoto/whatlang-rb"
16
16
  spec.metadata["changelog_uri"] = "https://gitlab.com/KitaitiMakoto/whatlang-rb/-/blob/master/CHANGELOG.md"
17
17
 
18
+ spec.required_ruby_version = ">= 3.2.0"
18
19
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
20
  `git ls-files -z`.split("\x0")
20
21
  end
21
- spec.extensions = ["ext/Cargo.toml"]
22
+ spec.extensions = ["ext/Rakefile"]
23
+
24
+ spec.add_runtime_dependency "rutie"
22
25
 
23
26
  spec.add_development_dependency "test-unit"
24
27
  spec.add_development_dependency "test-unit-notify"
25
28
  spec.add_development_dependency "rake"
26
29
  spec.add_development_dependency "yard"
27
30
  spec.add_development_dependency "rubygems-tasks"
31
+ spec.add_development_dependency "kar"
28
32
  spec.add_development_dependency "terminal-notifier"
29
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatlang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kitaiti Makoto
@@ -9,6 +9,20 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rutie
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: test-unit
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +93,20 @@ dependencies:
79
93
  - - ">="
80
94
  - !ruby/object:Gem::Version
81
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: kar
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
82
110
  - !ruby/object:Gem::Dependency
83
111
  name: terminal-notifier
84
112
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +126,7 @@ email:
98
126
  - KitaitiMakoto@gmail.com
99
127
  executables: []
100
128
  extensions:
101
- - ext/Cargo.toml
129
+ - ext/Rakefile
102
130
  extra_rdoc_files: []
103
131
  files:
104
132
  - ".gitignore"
@@ -107,12 +135,14 @@ files:
107
135
  - BSDL
108
136
  - CHANGELOG.md
109
137
  - COPYING
138
+ - Cargo.lock
139
+ - Cargo.toml
110
140
  - Gemfile
111
141
  - README.md
112
142
  - Rakefile
113
- - ext/Cargo.lock
114
- - ext/Cargo.toml
115
- - ext/src/lib.rs
143
+ - ext/Rakefile
144
+ - lib/whatlang.rb
145
+ - src/lib.rs
116
146
  - test/test_package.rb
117
147
  - test/test_whatlang.rb
118
148
  - whatlang.gemspec
@@ -130,14 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
160
  requirements:
131
161
  - - ">="
132
162
  - !ruby/object:Gem::Version
133
- version: '0'
163
+ version: 3.2.0
134
164
  required_rubygems_version: !ruby/object:Gem::Requirement
135
165
  requirements:
136
166
  - - ">="
137
167
  - !ruby/object:Gem::Version
138
168
  version: '0'
139
169
  requirements: []
140
- rubygems_version: 3.7.2
170
+ rubygems_version: 4.0.20
141
171
  specification_version: 4
142
172
  summary: Fast natural language detection library.
143
173
  test_files: []
data/ext/Cargo.lock DELETED
@@ -1,329 +0,0 @@
1
- # This file is automatically @generated by Cargo.
2
- # It is not intended for manual editing.
3
- version = 4
4
-
5
- [[package]]
6
- name = "aho-corasick"
7
- version = "1.1.3"
8
- source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
10
- dependencies = [
11
- "memchr",
12
- ]
13
-
14
- [[package]]
15
- name = "allocator-api2"
16
- version = "0.2.21"
17
- source = "registry+https://github.com/rust-lang/crates.io-index"
18
- checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
19
-
20
- [[package]]
21
- name = "bindgen"
22
- version = "0.69.5"
23
- source = "registry+https://github.com/rust-lang/crates.io-index"
24
- checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
25
- dependencies = [
26
- "bitflags",
27
- "cexpr",
28
- "clang-sys",
29
- "itertools",
30
- "lazy_static",
31
- "lazycell",
32
- "proc-macro2",
33
- "quote",
34
- "regex",
35
- "rustc-hash",
36
- "shlex",
37
- "syn",
38
- ]
39
-
40
- [[package]]
41
- name = "bitflags"
42
- version = "2.10.0"
43
- source = "registry+https://github.com/rust-lang/crates.io-index"
44
- checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
45
-
46
- [[package]]
47
- name = "cexpr"
48
- version = "0.6.0"
49
- source = "registry+https://github.com/rust-lang/crates.io-index"
50
- checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
51
- dependencies = [
52
- "nom",
53
- ]
54
-
55
- [[package]]
56
- name = "cfg-if"
57
- version = "1.0.4"
58
- source = "registry+https://github.com/rust-lang/crates.io-index"
59
- checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
60
-
61
- [[package]]
62
- name = "clang-sys"
63
- version = "1.8.1"
64
- source = "registry+https://github.com/rust-lang/crates.io-index"
65
- checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
66
- dependencies = [
67
- "glob",
68
- "libc",
69
- "libloading",
70
- ]
71
-
72
- [[package]]
73
- name = "either"
74
- version = "1.15.0"
75
- source = "registry+https://github.com/rust-lang/crates.io-index"
76
- checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
77
-
78
- [[package]]
79
- name = "equivalent"
80
- version = "1.0.2"
81
- source = "registry+https://github.com/rust-lang/crates.io-index"
82
- checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
83
-
84
- [[package]]
85
- name = "foldhash"
86
- version = "0.1.5"
87
- source = "registry+https://github.com/rust-lang/crates.io-index"
88
- checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
89
-
90
- [[package]]
91
- name = "glob"
92
- version = "0.3.3"
93
- source = "registry+https://github.com/rust-lang/crates.io-index"
94
- checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
95
-
96
- [[package]]
97
- name = "hashbrown"
98
- version = "0.15.5"
99
- source = "registry+https://github.com/rust-lang/crates.io-index"
100
- checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
101
- dependencies = [
102
- "allocator-api2",
103
- "equivalent",
104
- "foldhash",
105
- ]
106
-
107
- [[package]]
108
- name = "itertools"
109
- version = "0.12.1"
110
- source = "registry+https://github.com/rust-lang/crates.io-index"
111
- checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
112
- dependencies = [
113
- "either",
114
- ]
115
-
116
- [[package]]
117
- name = "lazy_static"
118
- version = "1.5.0"
119
- source = "registry+https://github.com/rust-lang/crates.io-index"
120
- checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
121
-
122
- [[package]]
123
- name = "lazycell"
124
- version = "1.3.0"
125
- source = "registry+https://github.com/rust-lang/crates.io-index"
126
- checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
127
-
128
- [[package]]
129
- name = "libc"
130
- version = "0.2.177"
131
- source = "registry+https://github.com/rust-lang/crates.io-index"
132
- checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
133
-
134
- [[package]]
135
- name = "libloading"
136
- version = "0.8.9"
137
- source = "registry+https://github.com/rust-lang/crates.io-index"
138
- checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
139
- dependencies = [
140
- "cfg-if",
141
- "windows-link",
142
- ]
143
-
144
- [[package]]
145
- name = "magnus"
146
- version = "0.8.2"
147
- source = "registry+https://github.com/rust-lang/crates.io-index"
148
- checksum = "3b36a5b126bbe97eb0d02d07acfeb327036c6319fd816139a49824a83b7f9012"
149
- dependencies = [
150
- "magnus-macros",
151
- "rb-sys",
152
- "rb-sys-env",
153
- "seq-macro",
154
- ]
155
-
156
- [[package]]
157
- name = "magnus-macros"
158
- version = "0.8.0"
159
- source = "registry+https://github.com/rust-lang/crates.io-index"
160
- checksum = "47607461fd8e1513cb4f2076c197d8092d921a1ea75bd08af97398f593751892"
161
- dependencies = [
162
- "proc-macro2",
163
- "quote",
164
- "syn",
165
- ]
166
-
167
- [[package]]
168
- name = "memchr"
169
- version = "2.7.6"
170
- source = "registry+https://github.com/rust-lang/crates.io-index"
171
- checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
172
-
173
- [[package]]
174
- name = "minimal-lexical"
175
- version = "0.2.1"
176
- source = "registry+https://github.com/rust-lang/crates.io-index"
177
- checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
178
-
179
- [[package]]
180
- name = "nom"
181
- version = "7.1.3"
182
- source = "registry+https://github.com/rust-lang/crates.io-index"
183
- checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
184
- dependencies = [
185
- "memchr",
186
- "minimal-lexical",
187
- ]
188
-
189
- [[package]]
190
- name = "proc-macro2"
191
- version = "1.0.101"
192
- source = "registry+https://github.com/rust-lang/crates.io-index"
193
- checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
194
- dependencies = [
195
- "unicode-ident",
196
- ]
197
-
198
- [[package]]
199
- name = "quote"
200
- version = "1.0.41"
201
- source = "registry+https://github.com/rust-lang/crates.io-index"
202
- checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
203
- dependencies = [
204
- "proc-macro2",
205
- ]
206
-
207
- [[package]]
208
- name = "rb-sys"
209
- version = "0.9.117"
210
- source = "registry+https://github.com/rust-lang/crates.io-index"
211
- checksum = "f900d1ce4629a2ebffaf5de74bd8f9c1188d4c5ed406df02f97e22f77a006f44"
212
- dependencies = [
213
- "rb-sys-build",
214
- ]
215
-
216
- [[package]]
217
- name = "rb-sys-build"
218
- version = "0.9.117"
219
- source = "registry+https://github.com/rust-lang/crates.io-index"
220
- checksum = "ef1e9c857028f631056bcd6d88cec390c751e343ce2223ddb26d23eb4a151d59"
221
- dependencies = [
222
- "bindgen",
223
- "lazy_static",
224
- "proc-macro2",
225
- "quote",
226
- "regex",
227
- "shell-words",
228
- "syn",
229
- ]
230
-
231
- [[package]]
232
- name = "rb-sys-env"
233
- version = "0.2.2"
234
- source = "registry+https://github.com/rust-lang/crates.io-index"
235
- checksum = "08f8d2924cf136a1315e2b4c7460a39f62ef11ee5d522df9b2750fab55b868b6"
236
-
237
- [[package]]
238
- name = "regex"
239
- version = "1.12.2"
240
- source = "registry+https://github.com/rust-lang/crates.io-index"
241
- checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
242
- dependencies = [
243
- "aho-corasick",
244
- "memchr",
245
- "regex-automata",
246
- "regex-syntax",
247
- ]
248
-
249
- [[package]]
250
- name = "regex-automata"
251
- version = "0.4.13"
252
- source = "registry+https://github.com/rust-lang/crates.io-index"
253
- checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
254
- dependencies = [
255
- "aho-corasick",
256
- "memchr",
257
- "regex-syntax",
258
- ]
259
-
260
- [[package]]
261
- name = "regex-syntax"
262
- version = "0.8.8"
263
- source = "registry+https://github.com/rust-lang/crates.io-index"
264
- checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
265
-
266
- [[package]]
267
- name = "rustc-hash"
268
- version = "1.1.0"
269
- source = "registry+https://github.com/rust-lang/crates.io-index"
270
- checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
271
-
272
- [[package]]
273
- name = "seq-macro"
274
- version = "0.3.6"
275
- source = "registry+https://github.com/rust-lang/crates.io-index"
276
- checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
277
-
278
- [[package]]
279
- name = "shell-words"
280
- version = "1.1.0"
281
- source = "registry+https://github.com/rust-lang/crates.io-index"
282
- checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
283
-
284
- [[package]]
285
- name = "shlex"
286
- version = "1.3.0"
287
- source = "registry+https://github.com/rust-lang/crates.io-index"
288
- checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
289
-
290
- [[package]]
291
- name = "syn"
292
- version = "2.0.107"
293
- source = "registry+https://github.com/rust-lang/crates.io-index"
294
- checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b"
295
- dependencies = [
296
- "proc-macro2",
297
- "quote",
298
- "unicode-ident",
299
- ]
300
-
301
- [[package]]
302
- name = "unicode-ident"
303
- version = "1.0.20"
304
- source = "registry+https://github.com/rust-lang/crates.io-index"
305
- checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06"
306
-
307
- [[package]]
308
- name = "whatlang"
309
- version = "0.2.0"
310
- dependencies = [
311
- "magnus",
312
- "rb-sys",
313
- "whatlang 0.18.0",
314
- ]
315
-
316
- [[package]]
317
- name = "whatlang"
318
- version = "0.18.0"
319
- source = "registry+https://github.com/rust-lang/crates.io-index"
320
- checksum = "f5e8f38b596e2a359b755342473520a99421e43658548c79489ee221b728c107"
321
- dependencies = [
322
- "hashbrown",
323
- ]
324
-
325
- [[package]]
326
- name = "windows-link"
327
- version = "0.2.1"
328
- source = "registry+https://github.com/rust-lang/crates.io-index"
329
- checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
data/ext/src/lib.rs DELETED
@@ -1,132 +0,0 @@
1
- use magnus::{
2
- Error, RArray, Ruby, Value, function, method,
3
- prelude::*,
4
- scan_args::{get_kwargs, scan_args},
5
- };
6
- use whatlang_rs as wl;
7
-
8
- #[magnus::wrap(class = "Whatlang::Lang")]
9
- struct Lang(wl::Lang);
10
-
11
- impl Lang {
12
- fn all(ruby: &Ruby) -> RArray {
13
- let langs = wl::Lang::all();
14
- ruby.ary_from_iter(langs.iter().map(|&lang| Lang(lang)))
15
- }
16
-
17
- fn code(&self) -> &str {
18
- self.0.code()
19
- }
20
-
21
- fn name(&self) -> &str {
22
- self.0.name()
23
- }
24
-
25
- fn eng_name(&self) -> &str {
26
- self.0.eng_name()
27
- }
28
- }
29
-
30
- #[magnus::wrap(class = "Whatlang::Info")]
31
- struct Info(wl::Info);
32
-
33
- impl Info {
34
- fn lang(&self) -> Lang {
35
- Lang(self.0.lang())
36
- }
37
-
38
- fn script(&self) -> String {
39
- self.0.script().to_string()
40
- }
41
-
42
- fn confidence(&self) -> f64 {
43
- self.0.confidence()
44
- }
45
-
46
- fn is_reliable(&self) -> bool {
47
- self.0.is_reliable()
48
- }
49
- }
50
-
51
- fn detect(ruby: &Ruby, args: &[Value]) -> Result<Option<Info>, Error> {
52
- type LangList = Option<Vec<String>>;
53
-
54
- let args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
55
- let kw_args = get_kwargs::<_, (), (LangList, LangList), ()>(
56
- args.keywords,
57
- &[],
58
- &["allowlist", "denylist"],
59
- )?;
60
- let (allowlist, denylist) = kw_args.optional;
61
- if allowlist.is_some() && denylist.is_some() {
62
- return Err(Error::new(
63
- ruby.exception_arg_error(),
64
- "Couldn't specify `allowlist' and `denylist' at a time. Choose one.",
65
- ));
66
- }
67
-
68
- let text = args.required.0.to_r_string()?.to_string()?;
69
- Ok(if let Some(allowlist) = allowlist {
70
- detect_with_allowlist(text, allowlist)
71
- } else if let Some(denylist) = denylist {
72
- detect_with_denylist(text, denylist)
73
- } else {
74
- detect_without_options(text)
75
- })
76
- }
77
-
78
- fn detect_without_options(text: String) -> Option<Info> {
79
- wl::detect(&text).map(Info)
80
- }
81
-
82
- fn detect_with_allowlist(text: String, allowlist: Vec<String>) -> Option<Info> {
83
- wl::Detector::with_allowlist(lang_list(allowlist))
84
- .detect(&text)
85
- .map(Info)
86
- }
87
-
88
- fn detect_with_denylist(text: String, denylist: Vec<String>) -> Option<Info> {
89
- wl::Detector::with_denylist(lang_list(denylist))
90
- .detect(&text)
91
- .map(Info)
92
- }
93
-
94
- fn lang_list(list: Vec<String>) -> Vec<wl::Lang> {
95
- list.iter().filter_map(wl::Lang::from_code).collect()
96
- }
97
-
98
- fn detect_lang(text: String) -> Option<Lang> {
99
- wl::detect_lang(&text).map(Lang)
100
- }
101
-
102
- fn detect_script(text: String) -> Option<String> {
103
- wl::detect_script(&text).map(|script| script.to_string())
104
- }
105
-
106
- #[magnus::init]
107
- fn init(ruby: &Ruby) -> Result<(), Error> {
108
- let module = ruby.define_module("Whatlang")?;
109
- module.define_singleton_method(
110
- "detect_without_options",
111
- function!(detect_without_options, 1),
112
- )?;
113
- module.define_singleton_method("detect", function!(detect, -1))?;
114
- module.define_singleton_method("detect_with_allowlist", function!(detect_with_allowlist, 2))?;
115
- module.define_singleton_method("detect_with_denylist", function!(detect_with_denylist, 2))?;
116
- module.define_singleton_method("detect_lang", function!(detect_lang, 1))?;
117
- module.define_singleton_method("detect_script", function!(detect_script, 1))?;
118
-
119
- let lang = module.define_class("Lang", ruby.class_object())?;
120
- lang.define_singleton_method("all", function!(Lang::all, 0))?;
121
- lang.define_method("code", method!(Lang::code, 0))?;
122
- lang.define_method("name", method!(Lang::name, 0))?;
123
- lang.define_method("eng_name", method!(Lang::eng_name, 0))?;
124
-
125
- let info = module.define_class("Info", ruby.class_object())?;
126
- info.define_method("lang", method!(Info::lang, 0))?;
127
- info.define_method("script", method!(Info::script, 0))?;
128
- info.define_method("confidence", method!(Info::confidence, 0))?;
129
- info.define_method("reliable?", method!(Info::is_reliable, 0))?;
130
-
131
- Ok(())
132
- }