Skip to content

Commit

Permalink
Add README (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystof-k authored Feb 5, 2024
1 parent 3df73e2 commit 96a0194
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Compact Encoding Detection for Ruby

Ruby bindings for [Google's Compact Encoding Detection](https://github.com/google/compact_enc_det) (CED for short) C++ library

## Usage

You will need [CMake](https://cmake.org) to build the C++ native extension.

>  macOS
>
> You can use [Homebrew](https://brew.sh) to install it:
>
> ```console
> brew install cmake
> ```
Then you can install the gem from [RubyGems.org](https://rubygems.org/gems/compact_enc_det).
> Either add this to your Gemfile:
>
> ```ruby
> gem 'compact_enc_det', '~> 0.1'
> ```
> or run the following command to install it:
>
> ```console
> gem install compact_enc_det
> ```
Now you can detect the encoding via the `CompactEncDet.detect_encoding`,
which is a thin wrapper around `CompactEncDet::DetectEncoding` and `MimeEncodingName` functions from the C++ library.
> ```ruby
> file = File.read("unknown-encoding.txt")
> result = CompactEncDet.detect_encoding(file, file.bytesize)
> result.encoding
> # => #<Encoding:Windows-1250>
> result.bytes_consumed
> # => 239
> result.is_reliable?
> # => true
> ```
## Contributing
Any contributions are welcome! Feel free to open an issue or a pull request.
### Repository
The [google/compact_enc_det](https://github.com/google/compact_enc_det) repository is linked as a Git submodule at `ext/compact_enc_det/compact_enc_det`.
> You need to clone the repository with `--recurse-submodules` flag:
>
> ```console
> git clone --recurse-submodules [email protected]:cloudaper/compact_enc_det.git
> ```
>
> Or initialize and update the submodule after cloning with the following commands:
>
> ```console
> git submodule init && git submodule update
> ```
### Testing
Tests located at `tests` use the [minitest](https://github.com/minitest/minitest) framework.
> Run the tests via test Rake task:
>
> ```console
> rake test
> ```
>
> The gem will be compiled to `lib/compact_enc_det/compact_enc_det.bundle` first.
## License
This gem is released under [MIT license](LICENSE), while the original Google's [Compact Encoding Detection library](https://github.com/google/compact_enc_det) source code,
located at `ext/compact_enc_det/compact_enc_det`, is under the [Apache-2.0](LICENSE-APACHE) license.
2 changes: 1 addition & 1 deletion compact_enc_det.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
spec.licenses = ["MIT", "Apache-2.0"]

spec.extensions = ["ext/compact_enc_det/extconf.rb"]
spec.files = Dir["ext/**/*", "lib/**/*"]
spec.files = Dir["ext/**/*", "lib/**/*", "README.md", "LICENSE", "LICENSE-APACHE"]

spec.require_paths = ["lib"]

Expand Down

0 comments on commit 96a0194

Please sign in to comment.