autocorrect-rb 2.5.6-aarch64-linux
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 +7 -0
 - data/README.md +125 -0
 - data/Rakefile +97 -0
 - data/ext/autocorrect/Cargo.toml +13 -0
 - data/ext/autocorrect/extconf.rb +4 -0
 - data/ext/autocorrect/src/lib.rs +151 -0
 - data/lib/autocorrect/2.7/autocorrect.so +0 -0
 - data/lib/autocorrect/3.0/autocorrect.so +0 -0
 - data/lib/autocorrect/3.1/autocorrect.so +0 -0
 - data/lib/autocorrect-rb.rb +7 -0
 - metadata +70 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3568e4f5ed902754b06f105315a6a95b552046a52ea23b86fa584eb0d5ca0d4a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c9d8d3272f45e9ccfa52178bf6e73857f10a5d3651a883e43f1a18af78d53bd7
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2ef10bc49164a60447fd4367bc29c1b8fb25e1553fe18231656f06be40e713a335cbdb32689e797ebeb060292794928c03bf592f705118b9d005d34224bc1bad
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 98df78efa67bdd019ea351d3d7a35fbd603cb65fdc23c3cc162859531af3f9ddb9c3fa5306d27cfc2b67a4980e1508e1d8b2d2fb5d8c8751cc23f2931566b9c8
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,125 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # AutoCorrect for Ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            <a href="https://rubygems.org/gems/autocorrect-rb"><img src="https://img.shields.io/gem/v/autocorrect-rb?color=1&label=Gem" alt="Gem Version"></a>
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            The Native Ruby version of [AutoCorrect](https://github.com/huacnlee/autocorrect).
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            - Rust - [autocorrect](https://github.com/huacnlee/autocorrect)
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Ruby - [autocorrect-rb](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-rb)
         
     | 
| 
      
 9 
     | 
    
         
            +
            - Go - [autocorrect-go](https://github.com/longbridgeapp/autocorrect)
         
     | 
| 
      
 10 
     | 
    
         
            +
            - Python - [autocorrect-py](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-py)
         
     | 
| 
      
 11 
     | 
    
         
            +
            - Node.js - [autocorrect-node](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-node)
         
     | 
| 
      
 12 
     | 
    
         
            +
            - JavaScript (Browser) - [autocorrect-wasm](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-wasm)
         
     | 
| 
      
 13 
     | 
    
         
            +
            - Java - [autocorrect-java](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-java)
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 18 
     | 
    
         
            +
            $ bundle add autocorrect-rb
         
     | 
| 
      
 19 
     | 
    
         
            +
            ```
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ```rb
         
     | 
| 
      
 24 
     | 
    
         
            +
            require('autocorrect-rb')
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            out = AutoCorrect.format('Hello你好.')
         
     | 
| 
      
 27 
     | 
    
         
            +
            puts out
         
     | 
| 
      
 28 
     | 
    
         
            +
            # Hello 你好。
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            out = AutoCorrect.format_for("title = 'Hello你好。'", 'rb')
         
     | 
| 
      
 31 
     | 
    
         
            +
            puts out
         
     | 
| 
      
 32 
     | 
    
         
            +
            # title = 'Hello 你好。'
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            result = AutoCorrect.lint_for("title = 'Hello你好。'", 'rb')
         
     | 
| 
      
 35 
     | 
    
         
            +
            puts result
         
     | 
| 
      
 36 
     | 
    
         
            +
            # {
         
     | 
| 
      
 37 
     | 
    
         
            +
            #   filepath: 'rb',
         
     | 
| 
      
 38 
     | 
    
         
            +
            #   lines: [
         
     | 
| 
      
 39 
     | 
    
         
            +
            #     { l: 1, c: 13, new: "'Hello 你好。'", old: "'Hello你好。'", severity: 1 }
         
     | 
| 
      
 40 
     | 
    
         
            +
            #   ],
         
     | 
| 
      
 41 
     | 
    
         
            +
            #   error: ''
         
     | 
| 
      
 42 
     | 
    
         
            +
            # }
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            config_str = %({ textRules: { "你好hello": 0 } })
         
     | 
| 
      
 45 
     | 
    
         
            +
            AutoCorrect.load_config(config_str)
         
     | 
| 
      
 46 
     | 
    
         
            +
            out = AutoCorrect.format('Hello你好.')
         
     | 
| 
      
 47 
     | 
    
         
            +
            puts out
         
     | 
| 
      
 48 
     | 
    
         
            +
            # Hello 你好。
         
     | 
| 
      
 49 
     | 
    
         
            +
            out = AutoCorrect.format('你好hello')
         
     | 
| 
      
 50 
     | 
    
         
            +
            puts out
         
     | 
| 
      
 51 
     | 
    
         
            +
            # 你好hello
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            # Ignorer, if /path/to/workdir contains .autocorrectignore or .gitignore
         
     | 
| 
      
 54 
     | 
    
         
            +
            ignorer = AutoCorrect::Ignorer.new("/path/to/")
         
     | 
| 
      
 55 
     | 
    
         
            +
            ignorer.ignored?("README.md")
         
     | 
| 
      
 56 
     | 
    
         
            +
            ```
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            ## Benchmarks
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            🎊 Rust version is ~3.5x faster than the Ruby (pure) version.
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            > NOTE: In this case Rust version has more complex rules.
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            ### Rust version
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 67 
     | 
    
         
            +
            Warming up --------------------------------------
         
     | 
| 
      
 68 
     | 
    
         
            +
                 format 50 chars    11.348k i/100ms
         
     | 
| 
      
 69 
     | 
    
         
            +
                format 100 chars     6.033k i/100ms
         
     | 
| 
      
 70 
     | 
    
         
            +
                format 400 chars     1.772k i/100ms
         
     | 
| 
      
 71 
     | 
    
         
            +
                     format_html   545.000  i/100ms
         
     | 
| 
      
 72 
     | 
    
         
            +
            Calculating -------------------------------------
         
     | 
| 
      
 73 
     | 
    
         
            +
                 format 50 chars    111.904k (± 3.1%) i/s -    567.400k in   5.075674s
         
     | 
| 
      
 74 
     | 
    
         
            +
                format 100 chars     58.684k (± 2.1%) i/s -    295.617k in   5.039837s
         
     | 
| 
      
 75 
     | 
    
         
            +
                format 400 chars     17.266k (± 2.9%) i/s -     86.828k in   5.033234s
         
     | 
| 
      
 76 
     | 
    
         
            +
                     format_html      5.448k (± 1.5%) i/s -     27.250k in   5.002853s
         
     | 
| 
      
 77 
     | 
    
         
            +
            ```
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            ```
         
     | 
| 
      
 80 
     | 
    
         
            +
            1000 ms / 111904 i/s = 0.008 ms
         
     | 
| 
      
 81 
     | 
    
         
            +
            ```
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            ### Pure [Ruby version](https://rubygems.org/gems/auto-correct/versions/1.0.0) result:
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 86 
     | 
    
         
            +
            Warming up --------------------------------------
         
     | 
| 
      
 87 
     | 
    
         
            +
                 format 50 chars     3.167k i/100ms
         
     | 
| 
      
 88 
     | 
    
         
            +
                format 100 chars     1.588k i/100ms
         
     | 
| 
      
 89 
     | 
    
         
            +
                format 400 chars   496.000  i/100ms
         
     | 
| 
      
 90 
     | 
    
         
            +
                     format_html   166.000  i/100ms
         
     | 
| 
      
 91 
     | 
    
         
            +
            Calculating -------------------------------------
         
     | 
| 
      
 92 
     | 
    
         
            +
                 format 50 chars     31.589k (± 2.5%) i/s -    158.350k in   5.016131s
         
     | 
| 
      
 93 
     | 
    
         
            +
                format 100 chars     16.122k (± 1.2%) i/s -     80.988k in   5.024082s
         
     | 
| 
      
 94 
     | 
    
         
            +
                format 400 chars      4.946k (± 2.6%) i/s -     24.800k in   5.017711s
         
     | 
| 
      
 95 
     | 
    
         
            +
                     format_html      1.659k (± 1.7%) i/s -      8.300k in   5.003164s
         
     | 
| 
      
 96 
     | 
    
         
            +
            ```
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            ### Rust version VS Purge Ruby Version
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
            | Test Case   | Duration (Rust) | Duration (Pure Ruby) | Speedup |
         
     | 
| 
      
 101 
     | 
    
         
            +
            | ----------- | --------------- | -------------------- | ------- |
         
     | 
| 
      
 102 
     | 
    
         
            +
            | Foramt 50   | 0.008ms         | 0.031ms              | ~3.8x   |
         
     | 
| 
      
 103 
     | 
    
         
            +
            | Format 100  | 0.017ms         | 0.062ms              | ~3.6x   |
         
     | 
| 
      
 104 
     | 
    
         
            +
            | Format 400  | 0.052ms         | 0.2ms                | ~3.8x   |
         
     | 
| 
      
 105 
     | 
    
         
            +
            | Format HTML | 0.183ms         | 0.67ms               | ~3.6x   |
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            > 🎈 Rust version about 3.5 ~ 3.8x fast then Ruby (pure version).
         
     | 
| 
      
 108 
     | 
    
         
            +
            > 
         
     | 
| 
      
 109 
     | 
    
         
            +
            > By this result, we can see the Ruby version is also fast, but the Rust version is more better.
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            ## Know issues
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            Bundler install error:
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            ```
         
     | 
| 
      
 116 
     | 
    
         
            +
            Could not find gem 'autocorrect-rb' with platform 'ruby' in rubygems repository https://rubygems.org/ or installed locally.
         
     | 
| 
      
 117 
     | 
    
         
            +
            ```
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
            To fix this you can run:
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            ```bash
         
     | 
| 
      
 122 
     | 
    
         
            +
            $ bundle lock --remove-platform ruby
         
     | 
| 
      
 123 
     | 
    
         
            +
            ```
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
            Because of autocorrect-rb not release the gem for `platform: ruby`, but your `Gemfile.lock` specialed that. This command will remove `ruby` platform from your `Gemfile.lock`
         
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,97 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # autocorrect: false
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "rubygems"
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            begin
         
     | 
| 
      
 5 
     | 
    
         
            +
              require "bundler/setup"
         
     | 
| 
      
 6 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 7 
     | 
    
         
            +
              puts "You must `gem install bundler` and `bundle install` to run rake tasks"
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            require "bundler/gem_tasks"
         
     | 
| 
      
 11 
     | 
    
         
            +
            require "rubygems/package_task"
         
     | 
| 
      
 12 
     | 
    
         
            +
            require "rake/testtask"
         
     | 
| 
      
 13 
     | 
    
         
            +
            require "rake/extensiontask"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require "bundler"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            CROSS_PLATFORMS = %w[
         
     | 
| 
      
 17 
     | 
    
         
            +
              aarch64-linux
         
     | 
| 
      
 18 
     | 
    
         
            +
              arm64-darwin
         
     | 
| 
      
 19 
     | 
    
         
            +
              x64-mingw32
         
     | 
| 
      
 20 
     | 
    
         
            +
              x86_64-darwin
         
     | 
| 
      
 21 
     | 
    
         
            +
              x86_64-linux
         
     | 
| 
      
 22 
     | 
    
         
            +
            ]
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            Rake::TestTask.new(:test) do |t|
         
     | 
| 
      
 25 
     | 
    
         
            +
              t.libs << "test"
         
     | 
| 
      
 26 
     | 
    
         
            +
              t.libs << "lib"
         
     | 
| 
      
 27 
     | 
    
         
            +
              t.test_files = FileList["test/**/*_test.rb"]
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            spec = Bundler.load_gemspec("autocorrect-rb.gemspec")
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            # Make a autocorrect-rb-0.0.0.gem
         
     | 
| 
      
 33 
     | 
    
         
            +
            # Disable release gem for platform: ruby, because autocorrect rust source build is complex.
         
     | 
| 
      
 34 
     | 
    
         
            +
            # Gem::PackageTask.new(spec).define
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            # Make a native gem, eg. autocorrect-rb-0.0.0-x86_64-linux.gem
         
     | 
| 
      
 37 
     | 
    
         
            +
            Rake::ExtensionTask.new("autocorrect", spec) do |ext|
         
     | 
| 
      
 38 
     | 
    
         
            +
              # Compile output autocorrect.so into lib/autocorrect/autocorrect.so
         
     | 
| 
      
 39 
     | 
    
         
            +
              ext.lib_dir = "lib/autocorrect"
         
     | 
| 
      
 40 
     | 
    
         
            +
              ext.source_pattern = "*.{rs,toml}"
         
     | 
| 
      
 41 
     | 
    
         
            +
              ext.cross_compile = true
         
     | 
| 
      
 42 
     | 
    
         
            +
              ext.cross_platform = CROSS_PLATFORMS
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            task :bench do
         
     | 
| 
      
 46 
     | 
    
         
            +
              require "benchmark/ips"
         
     | 
| 
      
 47 
     | 
    
         
            +
              require "./lib/autocorrect-rb"
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
              html = open("./test/fixtures/example.txt").read
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              Benchmark.ips do |x|
         
     | 
| 
      
 52 
     | 
    
         
            +
                x.report("format 50 chars") do |n|
         
     | 
| 
      
 53 
     | 
    
         
            +
                  n.times do
         
     | 
| 
      
 54 
     | 
    
         
            +
                    AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
                x.report("format 100 chars") do |n|
         
     | 
| 
      
 58 
     | 
    
         
            +
                  n.times do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
                x.report("format 400 chars") do |n|
         
     | 
| 
      
 63 
     | 
    
         
            +
                  n.times do
         
     | 
| 
      
 64 
     | 
    
         
            +
                    AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,��期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一��都积极推动经销商去库存,这将有利公司今年利润率复苏。")
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                x.report("format_html") do |n|
         
     | 
| 
      
 69 
     | 
    
         
            +
                  n.times do
         
     | 
| 
      
 70 
     | 
    
         
            +
                    AutoCorrect.format_for(html, "text.html")
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
            end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
            task :memory do
         
     | 
| 
      
 77 
     | 
    
         
            +
              require "memory_profiler"
         
     | 
| 
      
 78 
     | 
    
         
            +
              require "./lib/autocorrect-rb"
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
              html = open("./test/fixtures/example.txt").read
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
              report = MemoryProfiler.report do
         
     | 
| 
      
 83 
     | 
    
         
            +
                20_000.times do
         
     | 
| 
      
 84 
     | 
    
         
            +
                  AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
         
     | 
| 
      
 85 
     | 
    
         
            +
                  AutoCorrect.format_for(html, "text.html")
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
              GC.start
         
     | 
| 
      
 90 
     | 
    
         
            +
              report.pretty_print
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
              puts "------------------------- Result Guide -------------------------"
         
     | 
| 
      
 93 
     | 
    
         
            +
              puts "If [Total retained] have any bytes, there will have memory leak."
         
     | 
| 
      
 94 
     | 
    
         
            +
            end
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
            task test: :compile
         
     | 
| 
      
 97 
     | 
    
         
            +
            task default: %i[test]
         
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            [package]
         
     | 
| 
      
 2 
     | 
    
         
            +
            edition = "2021"
         
     | 
| 
      
 3 
     | 
    
         
            +
            name = "autocorrect-rb"
         
     | 
| 
      
 4 
     | 
    
         
            +
            version = "2.5.5"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
         
     | 
| 
      
 7 
     | 
    
         
            +
            [lib]
         
     | 
| 
      
 8 
     | 
    
         
            +
            crate-type = ["cdylib"]
         
     | 
| 
      
 9 
     | 
    
         
            +
            name = "autocorrect"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            [dependencies]
         
     | 
| 
      
 12 
     | 
    
         
            +
            autocorrect = "2"
         
     | 
| 
      
 13 
     | 
    
         
            +
            magnus = "0.4"
         
     | 
| 
         @@ -0,0 +1,151 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            use magnus::{define_class, function, method, Error, Module, Object};
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            #[derive(Debug, Clone)]
         
     | 
| 
      
 4 
     | 
    
         
            +
            pub struct LineResult {
         
     | 
| 
      
 5 
     | 
    
         
            +
                line: usize,
         
     | 
| 
      
 6 
     | 
    
         
            +
                col: usize,
         
     | 
| 
      
 7 
     | 
    
         
            +
                new: String,
         
     | 
| 
      
 8 
     | 
    
         
            +
                old: String,
         
     | 
| 
      
 9 
     | 
    
         
            +
                severity: usize,
         
     | 
| 
      
 10 
     | 
    
         
            +
            }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            impl LineResult {
         
     | 
| 
      
 13 
     | 
    
         
            +
                pub fn line(&self) -> usize {
         
     | 
| 
      
 14 
     | 
    
         
            +
                    self.line
         
     | 
| 
      
 15 
     | 
    
         
            +
                }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                pub fn col(&self) -> usize {
         
     | 
| 
      
 18 
     | 
    
         
            +
                    self.col
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                pub fn get_new(&self) -> String {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    self.new.clone()
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                pub fn old(&self) -> String {
         
     | 
| 
      
 26 
     | 
    
         
            +
                    self.old.clone()
         
     | 
| 
      
 27 
     | 
    
         
            +
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                pub fn severity(&self) -> usize {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    self.severity
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                pub fn inspect(&self) -> String {
         
     | 
| 
      
 34 
     | 
    
         
            +
                    format!("{:?}", self)
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                pub fn to_hash(&self) -> Result<magnus::RHash, Error> {
         
     | 
| 
      
 38 
     | 
    
         
            +
                    let hash = magnus::RHash::new();
         
     | 
| 
      
 39 
     | 
    
         
            +
                    hash.aset("line", self.line())?;
         
     | 
| 
      
 40 
     | 
    
         
            +
                    hash.aset("col", self.col())?;
         
     | 
| 
      
 41 
     | 
    
         
            +
                    hash.aset("new", self.get_new())?;
         
     | 
| 
      
 42 
     | 
    
         
            +
                    hash.aset("old", self.old())?;
         
     | 
| 
      
 43 
     | 
    
         
            +
                    hash.aset("severity", self.severity())?;
         
     | 
| 
      
 44 
     | 
    
         
            +
                    Ok(hash)
         
     | 
| 
      
 45 
     | 
    
         
            +
                }
         
     | 
| 
      
 46 
     | 
    
         
            +
            }
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            #[derive(Debug, Clone)]
         
     | 
| 
      
 49 
     | 
    
         
            +
            pub struct LintResult {
         
     | 
| 
      
 50 
     | 
    
         
            +
                pub filepath: String,
         
     | 
| 
      
 51 
     | 
    
         
            +
                pub lines: Vec<LineResult>,
         
     | 
| 
      
 52 
     | 
    
         
            +
                pub error: String,
         
     | 
| 
      
 53 
     | 
    
         
            +
            }
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            impl LintResult {
         
     | 
| 
      
 56 
     | 
    
         
            +
                pub fn filepath(&self) -> String {
         
     | 
| 
      
 57 
     | 
    
         
            +
                    self.filepath.clone()
         
     | 
| 
      
 58 
     | 
    
         
            +
                }
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                pub fn lines(&self) -> Vec<LineResult> {
         
     | 
| 
      
 61 
     | 
    
         
            +
                    self.lines.clone()
         
     | 
| 
      
 62 
     | 
    
         
            +
                }
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                pub fn error(&self) -> String {
         
     | 
| 
      
 65 
     | 
    
         
            +
                    self.error.clone()
         
     | 
| 
      
 66 
     | 
    
         
            +
                }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                pub fn inspect(&self) -> String {
         
     | 
| 
      
 69 
     | 
    
         
            +
                    format!("{:?}", self)
         
     | 
| 
      
 70 
     | 
    
         
            +
                }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                pub fn to_hash(&self) -> Result<magnus::RHash, Error> {
         
     | 
| 
      
 73 
     | 
    
         
            +
                    let hash = magnus::RHash::new();
         
     | 
| 
      
 74 
     | 
    
         
            +
                    hash.aset("filepath", self.filepath())?;
         
     | 
| 
      
 75 
     | 
    
         
            +
                    hash.aset(
         
     | 
| 
      
 76 
     | 
    
         
            +
                        "lines",
         
     | 
| 
      
 77 
     | 
    
         
            +
                        self.lines()
         
     | 
| 
      
 78 
     | 
    
         
            +
                            .iter()
         
     | 
| 
      
 79 
     | 
    
         
            +
                            .map(|l| l.to_hash().unwrap())
         
     | 
| 
      
 80 
     | 
    
         
            +
                            .collect::<Vec<magnus::RHash>>(),
         
     | 
| 
      
 81 
     | 
    
         
            +
                    )?;
         
     | 
| 
      
 82 
     | 
    
         
            +
                    hash.aset("error", self.error())?;
         
     | 
| 
      
 83 
     | 
    
         
            +
                    Ok(hash)
         
     | 
| 
      
 84 
     | 
    
         
            +
                }
         
     | 
| 
      
 85 
     | 
    
         
            +
            }
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            #[magnus::wrap(class = "AutoCorrect::Ignorer")]
         
     | 
| 
      
 88 
     | 
    
         
            +
            pub struct Ignorer {
         
     | 
| 
      
 89 
     | 
    
         
            +
                core: autocorrect::ignorer::Ignorer,
         
     | 
| 
      
 90 
     | 
    
         
            +
            }
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            impl Ignorer {
         
     | 
| 
      
 93 
     | 
    
         
            +
                pub fn new(work_dir: String) -> Self {
         
     | 
| 
      
 94 
     | 
    
         
            +
                    Ignorer {
         
     | 
| 
      
 95 
     | 
    
         
            +
                        core: autocorrect::ignorer::Ignorer::new(&work_dir),
         
     | 
| 
      
 96 
     | 
    
         
            +
                    }
         
     | 
| 
      
 97 
     | 
    
         
            +
                }
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                fn is_ignored(&self, path: String) -> bool {
         
     | 
| 
      
 100 
     | 
    
         
            +
                    self.core.is_ignored(&path)
         
     | 
| 
      
 101 
     | 
    
         
            +
                }
         
     | 
| 
      
 102 
     | 
    
         
            +
            }
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            pub fn format(input: String) -> String {
         
     | 
| 
      
 105 
     | 
    
         
            +
                autocorrect::format(&input)
         
     | 
| 
      
 106 
     | 
    
         
            +
            }
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            pub fn format_for(input: String, filename_or_ext: String) -> String {
         
     | 
| 
      
 109 
     | 
    
         
            +
                autocorrect::format_for(&input, &filename_or_ext).out
         
     | 
| 
      
 110 
     | 
    
         
            +
            }
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
            pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
         
     | 
| 
      
 113 
     | 
    
         
            +
                let result = autocorrect::lint_for(&input, &filename_or_ext);
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                LintResult {
         
     | 
| 
      
 116 
     | 
    
         
            +
                    filepath: filename_or_ext,
         
     | 
| 
      
 117 
     | 
    
         
            +
                    lines: result
         
     | 
| 
      
 118 
     | 
    
         
            +
                        .lines
         
     | 
| 
      
 119 
     | 
    
         
            +
                        .iter()
         
     | 
| 
      
 120 
     | 
    
         
            +
                        .map(|l| LineResult {
         
     | 
| 
      
 121 
     | 
    
         
            +
                            line: l.line,
         
     | 
| 
      
 122 
     | 
    
         
            +
                            col: l.col,
         
     | 
| 
      
 123 
     | 
    
         
            +
                            new: l.new.clone(),
         
     | 
| 
      
 124 
     | 
    
         
            +
                            old: l.old.clone(),
         
     | 
| 
      
 125 
     | 
    
         
            +
                            severity: l.severity as usize,
         
     | 
| 
      
 126 
     | 
    
         
            +
                        })
         
     | 
| 
      
 127 
     | 
    
         
            +
                        .collect::<_>(),
         
     | 
| 
      
 128 
     | 
    
         
            +
                    error: result.error,
         
     | 
| 
      
 129 
     | 
    
         
            +
                }
         
     | 
| 
      
 130 
     | 
    
         
            +
                .to_hash()
         
     | 
| 
      
 131 
     | 
    
         
            +
                .unwrap()
         
     | 
| 
      
 132 
     | 
    
         
            +
            }
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
            pub fn load_config(config_str: String) {
         
     | 
| 
      
 135 
     | 
    
         
            +
                autocorrect::config::load(&config_str).unwrap();
         
     | 
| 
      
 136 
     | 
    
         
            +
            }
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
            #[magnus::init(name = "autocorrect")]
         
     | 
| 
      
 139 
     | 
    
         
            +
            fn init() -> Result<(), Error> {
         
     | 
| 
      
 140 
     | 
    
         
            +
                let class = define_class("AutoCorrect", Default::default())?;
         
     | 
| 
      
 141 
     | 
    
         
            +
                class.define_singleton_method("format", function!(format, 1))?;
         
     | 
| 
      
 142 
     | 
    
         
            +
                class.define_singleton_method("format_for", function!(format_for, 2))?;
         
     | 
| 
      
 143 
     | 
    
         
            +
                class.define_singleton_method("lint_for", function!(lint_for, 2))?;
         
     | 
| 
      
 144 
     | 
    
         
            +
                class.define_singleton_method("load_config", function!(load_config, 1))?;
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                let ignorer_class = class.define_class("Ignorer", Default::default())?;
         
     | 
| 
      
 147 
     | 
    
         
            +
                ignorer_class.define_singleton_method("new", function!(Ignorer::new, 1))?;
         
     | 
| 
      
 148 
     | 
    
         
            +
                ignorer_class.define_method("ignored?", method!(Ignorer::is_ignored, 1))?;
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                Ok(())
         
     | 
| 
      
 151 
     | 
    
         
            +
            }
         
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,70 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: autocorrect-rb
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 2.5.6
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: aarch64-linux
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Jason Lee
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-01-03 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: rb_sys
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 0.9.18
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 0.9.18
         
     | 
| 
      
 27 
     | 
    
         
            +
            description: AutoCorrect is a linter and formatter to help you to improve copywriting,
         
     | 
| 
      
 28 
     | 
    
         
            +
              correct spaces, words, punctuations between CJK (Chinese, Japanese, Korean).
         
     | 
| 
      
 29 
     | 
    
         
            +
            email:
         
     | 
| 
      
 30 
     | 
    
         
            +
            - huacnlee@gmail.com
         
     | 
| 
      
 31 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 33 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 34 
     | 
    
         
            +
            files:
         
     | 
| 
      
 35 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 36 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 37 
     | 
    
         
            +
            - ext/autocorrect/Cargo.toml
         
     | 
| 
      
 38 
     | 
    
         
            +
            - ext/autocorrect/extconf.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - ext/autocorrect/src/lib.rs
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/autocorrect-rb.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/autocorrect/2.7/autocorrect.so
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/autocorrect/3.0/autocorrect.so
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/autocorrect/3.1/autocorrect.so
         
     | 
| 
      
 44 
     | 
    
         
            +
            homepage: https://github.com/huacnlee/autocorrect
         
     | 
| 
      
 45 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 46 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 47 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 48 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
      
 49 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 50 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 51 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 52 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 53 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 54 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 55 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 56 
     | 
    
         
            +
                  version: '2.7'
         
     | 
| 
      
 57 
     | 
    
         
            +
              - - "<"
         
     | 
| 
      
 58 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 59 
     | 
    
         
            +
                  version: 3.2.dev
         
     | 
| 
      
 60 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 61 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 62 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 63 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 64 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 65 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 66 
     | 
    
         
            +
            rubygems_version: 3.3.22
         
     | 
| 
      
 67 
     | 
    
         
            +
            signing_key:
         
     | 
| 
      
 68 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 69 
     | 
    
         
            +
            summary: AutoCorrect is a linter and formatter to help you to improve copywriting.
         
     | 
| 
      
 70 
     | 
    
         
            +
            test_files: []
         
     |