ruby_rqrr 0.9.0.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.
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/ruby_rqrr"]
7
+ resolver = "2"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Shawn Jordan
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,50 @@
1
+ # RubyRqrr
2
+
3
+ RubyRqrr (Ruby RQ'er) is a Ruby gem that provides a simple interface to scan images for QR codes. It uses the [Rust crate RQrr](https://docs.rs/crate/rqrr/latest) under the hood to decode QR codes. This gem is a simple wrapper around the Rust crate to provide a Ruby interface.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add ruby_rqrr
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install ruby_rqrr
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ The gem provides a module `RubyRqrr` with a single method `detect_qrs_in_image` that takes an image file path as an argument and returns an array of QR codes found in the image.
22
+
23
+ ```ruby
24
+ require 'ruby_rqrr'
25
+
26
+ RubyRqrr.detect_qrs_in_image('path/to/image.png')
27
+ ["https://github.com/phchun/ruby_rqrr"]
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ 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).
35
+
36
+ ## Versioning
37
+
38
+ We will follow the RQrr versioning for the first three digits. The fourth digit will be used for RubyRqrr specific changes within that version of RQrr.
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/phchun/ruby_rqrr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/phchun/ruby_rqrr/blob/main/CODE_OF_CONDUCT.md).
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
+
48
+ ## Code of Conduct
49
+
50
+ Everyone interacting in the RubyRqrr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/phchun/ruby_rqrr/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ require "rb_sys/extensiontask"
11
+
12
+ task build: :compile
13
+
14
+ GEMSPEC = Gem::Specification.load("ruby_rqrr.gemspec")
15
+
16
+ RbSys::ExtensionTask.new("ruby_rqrr", GEMSPEC) do |ext|
17
+ ext.lib_dir = "lib/ruby_rqrr"
18
+ end
19
+
20
+ task default: %i[compile test standard]
@@ -0,0 +1,16 @@
1
+ [package]
2
+ name = "ruby_rqrr"
3
+ version = "0.9.0-1"
4
+ edition = "2021"
5
+ authors = ["Shawn Jordan <shawn.jordan@me.com>"]
6
+ license = "MIT"
7
+ publish = false
8
+
9
+ [lib]
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ image = { version ="0.25.5" }
14
+ magnus = { version = "0.6.2" }
15
+ rqrr = { version = "0.9.0"}
16
+ url = { version = "2.5.4" }
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("ruby_rqrr/ruby_rqrr")
@@ -0,0 +1,47 @@
1
+ use image;
2
+ use magnus::{
3
+ exception, exception::ExceptionClass, function, prelude::*, value::Lazy, Error, RArray,
4
+ RModule, Ruby,
5
+ };
6
+ use rqrr;
7
+ use std::path::Path;
8
+
9
+ static RUBY_RQRR: Lazy<RModule> = Lazy::new(|ruby| ruby.define_module("RubyRqrr").unwrap());
10
+
11
+ static ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
12
+ ruby.get_inner(&RUBY_RQRR)
13
+ .define_error("Error", ruby.exception_standard_error())
14
+ .unwrap()
15
+ });
16
+
17
+ static QR_PARSE_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
18
+ ruby.get_inner(&RUBY_RQRR)
19
+ .define_error("QrParseError", ruby.get_inner(&ERROR))
20
+ .unwrap()
21
+ });
22
+
23
+ fn detect_qrs_in_image(ruby: &Ruby, file_path: String) -> Result<RArray, Error> {
24
+ // Load the image
25
+ let img_file = image::open(Path::new(&file_path))
26
+ .map_err(|e| Error::new(exception::io_error(), e.to_string()))?
27
+ .to_luma8();
28
+ let mut img = rqrr::PreparedImage::prepare(img_file);
29
+ let grids = img.detect_grids();
30
+ let urls = RArray::new();
31
+
32
+ for grid in grids {
33
+ let (_, content) = grid
34
+ .decode()
35
+ .map_err(|e| Error::new(ruby.get_inner(&QR_PARSE_ERROR), e.to_string()))?;
36
+ urls.push(content)?;
37
+ }
38
+ Ok(urls)
39
+ }
40
+
41
+ #[magnus::init]
42
+ fn init(ruby: &Ruby) -> Result<(), Error> {
43
+ Lazy::force(&QR_PARSE_ERROR, ruby);
44
+ ruby.get_inner(&RUBY_RQRR)
45
+ .define_singleton_method("detect_qrs_in_image", function!(detect_qrs_in_image, 1))?;
46
+ Ok(())
47
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyRqrr
4
+ VERSION = "0.9.0.1"
5
+ end
data/lib/ruby_rqrr.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_rqrr/version"
4
+ require_relative "ruby_rqrr/ruby_rqrr"
5
+
6
+ module RubyRqrr
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
data/mise.toml ADDED
@@ -0,0 +1,3 @@
1
+ [tools]
2
+ ruby = "3.4.1"
3
+ rust = "1.85.1"
data/sig/ruby_rqrr.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module RubyRqrr
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_rqrr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shawn Jordan
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-04-01 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rb_sys
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.9.91
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.9.91
26
+ description: This gem brings in a rust library (RQRR) to detect QR codes in images.
27
+ email:
28
+ - shawn.jordan@me.com
29
+ executables: []
30
+ extensions:
31
+ - ext/ruby_rqrr/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".standard.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - Cargo.lock
38
+ - Cargo.toml
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - ext/ruby_rqrr/Cargo.toml
43
+ - ext/ruby_rqrr/extconf.rb
44
+ - ext/ruby_rqrr/src/lib.rs
45
+ - lib/ruby_rqrr.rb
46
+ - lib/ruby_rqrr/version.rb
47
+ - mise.toml
48
+ - sig/ruby_rqrr.rbs
49
+ homepage: https://gitlab.com/phchun/ruby_rqrr
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://gitlab.com/phchun/ruby_rqrr
55
+ source_code_uri: https://gitlab.com/phchun/ruby_rqrr
56
+ changelog_uri: https://gitlab.com/phchun/ruby_rqrr/CHANGELOG.md
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.1.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.3.11
70
+ requirements: []
71
+ rubygems_version: 3.6.2
72
+ specification_version: 4
73
+ summary: A Ruby Binding for Rust's RQRR'.
74
+ test_files: []