autocorrect-rb 2.4.0-x86_64-darwin → 2.5.0-x86_64-darwin

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: c806da49ac6704ff6f3f2797fcef27a1785d5848219678b94d77404a23f740a2
4
- data.tar.gz: 519bd8bd246152a9630fb0cd9c02fa24dc127693a2e56e80adc21487d13f4aed
3
+ metadata.gz: 1b06e91fbac00e95102d1a0a8a8fd139c0aab35820d82428c3026da3cf4f0683
4
+ data.tar.gz: a2e74c4c6f6d3532505c644e4d262b9899f53ffcc77bdac6d55e9177df8ecbc3
5
5
  SHA512:
6
- metadata.gz: 8cbe826e811572d67d6add61124d718af618f1fe3b1f9a49f395469e227a9aef19d096f2be307a735bda8d6bea613ac91b15cc264697012e4e4a68e87193320c
7
- data.tar.gz: fd25943924da227f6f99ea90cd6a391eae76cf62d0c9b8c63d83e527f7cc962c6a78ea1094456cb883566bb125b31ee5f26c8a42a2835d5ee65cef5c3c3a6eef
6
+ metadata.gz: e32c4eeb1f5e307a7c62cb2ca2a611209386af5ba2d0a9457f0b303a524723efdaebe04ae1701e93856ae516d129e125692a33d05066979a2cc42f38ca947cf5
7
+ data.tar.gz: 819f18584c78867dafa9338d5ff9d8a8faf09b380d3adda87dfbac3fedfdea2a713312ba7a5d5a277c41f64759fc9da20ac0ef4d25608a5990c2b1c5bf52e578
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # AutoCorrect for Ruby
2
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
+
3
5
  The Native Ruby version of [AutoCorrect](https://github.com/huacnlee/autocorrect).
4
6
 
5
7
  - Rust - [autocorrect](https://github.com/huacnlee/autocorrect)
@@ -38,11 +40,24 @@ puts result
38
40
  # ],
39
41
  # error: ''
40
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")
41
56
  ```
42
57
 
43
58
  ## Benchmarks
44
59
 
45
- 🎊 Rust version is 3x faster than the Ruby (pure) version.
60
+ 🎊 Rust version is ~3.5x faster than the Ruby (pure) version.
46
61
 
47
62
  > NOTE: In this case Rust version has more complex rules.
48
63
 
@@ -61,6 +76,10 @@ Calculating -------------------------------------
61
76
  format_html 5.448k (± 1.5%) i/s - 27.250k in 5.002853s
62
77
  ```
63
78
 
79
+ ```
80
+ 1000 ms / 111904 i/s = 0.008 ms
81
+ ```
82
+
64
83
  ### Pure [Ruby version](https://rubygems.org/gems/auto-correct/versions/1.0.0) result:
65
84
 
66
85
  ```bash
@@ -76,6 +95,19 @@ Calculating -------------------------------------
76
95
  format_html 1.659k (± 1.7%) i/s - 8.300k in 5.003164s
77
96
  ```
78
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
+
79
111
  ## Know issues
80
112
 
81
113
  Bundler install error:
data/Rakefile CHANGED
@@ -55,12 +55,12 @@ task :bench do
55
55
  end
56
56
  x.report("format 100 chars") do |n|
57
57
  n.times do
58
- AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
58
+ AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
59
59
  end
60
60
  end
61
61
  x.report("format 400 chars") do |n|
62
62
  n.times do
63
- AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,预期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一直都积极推动经销商去库存,这将有利公司今年利润率复苏。")
63
+ AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,��期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一��都积极推动经销商去库存,这将有利公司今年利润率复苏。")
64
64
  end
65
65
  end
66
66
 
@@ -72,5 +72,25 @@ task :bench do
72
72
  end
73
73
  end
74
74
 
75
+ task :memory do
76
+ require "memory_profiler"
77
+ require "./lib/autocorrect-rb"
78
+
79
+ html = open("./test/fixtures/example.txt").read
80
+
81
+ report = MemoryProfiler.report do
82
+ 20_000.times do
83
+ AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
84
+ AutoCorrect.format_for(html, "text.html")
85
+ end
86
+ end
87
+
88
+ GC.start
89
+ report.pretty_print
90
+
91
+ puts "------------------------- Result Guide -------------------------"
92
+ puts "If [Total retained] have any bytes, there will have memory leak."
93
+ end
94
+
75
95
  task test: :compile
76
96
  task default: %i[test]
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2021"
3
3
  name = "autocorrect-rb"
4
- version = "2.4.0"
4
+ version = "2.5.0"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
  [lib]
@@ -1,4 +1,4 @@
1
- use magnus::{define_class, function, Error, Object};
1
+ use magnus::{define_class, function, method, Error, Module, Object};
2
2
 
3
3
  #[derive(Debug, Clone)]
4
4
  pub struct LineResult {
@@ -84,6 +84,23 @@ impl LintResult {
84
84
  }
85
85
  }
86
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
+
87
104
  pub fn format(input: String) -> String {
88
105
  autocorrect::format(&input)
89
106
  }
@@ -105,7 +122,7 @@ pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
105
122
  col: l.col,
106
123
  new: l.new.clone(),
107
124
  old: l.old.clone(),
108
- severity: l.severity.clone() as usize,
125
+ severity: l.severity as usize,
109
126
  })
110
127
  .collect::<_>(),
111
128
  error: result.error,
@@ -114,12 +131,21 @@ pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
114
131
  .unwrap()
115
132
  }
116
133
 
134
+ pub fn load_config(config_str: String) {
135
+ autocorrect::config::load(&config_str).unwrap();
136
+ }
137
+
117
138
  #[magnus::init(name = "autocorrect")]
118
139
  fn init() -> Result<(), Error> {
119
140
  let class = define_class("AutoCorrect", Default::default())?;
120
141
  class.define_singleton_method("format", function!(format, 1))?;
121
142
  class.define_singleton_method("format_for", function!(format_for, 2))?;
122
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))?;
123
149
 
124
150
  Ok(())
125
151
  }
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autocorrect-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Jason Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys