jkproof 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cee32de691a9c30a7e5d4fb319128f7d1827650c8810e3c02194cbe268794301
4
- data.tar.gz: 5db6b4644f9345b152162b592bbd6ecdf4aa2c716e394bfaaaf1aafea8cdb921
3
+ metadata.gz: 92e378ab167a6bde805c9090a8f7747e0c54054a25cd4ae1d75bf48114c5ae4c
4
+ data.tar.gz: 05ec8e0297975639fae9803083d7873f22e7c916e8b5d4632343e091ff69740c
5
5
  SHA512:
6
- metadata.gz: c92b5916cdecd22ef8010a6f0cce2705dc4b8cdf1d35cccd4862917674fe230d63dda3bacf25603061f6669bb0da55ca0b483a3f0dc2846ddda8125124cfb183
7
- data.tar.gz: b654be09edc8ae6fc88f400c2fead7507f7a919359c3c98e26d9dbf72c34df7f7fa571102861857c79e965d539f52dfd4c54387f498ffe36cd640783a4ac2f48
6
+ metadata.gz: 35a643e68f7cc6cad00ec3354d28c2891afc23c67309f3712907ee99fecf5ac5d252ff274a0fbd9de96cfc191f2801e4003b8df3b71a0819119803b513a7bae9
7
+ data.tar.gz: ff2b85a22bb7d04869042b420b3c415ae77a18105a0488df9e483423b7d78380dc049e5a7c2b410b86c0b69991e711ca07d01d4eaf4e846129f5a0124bee2f0c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # ChangeLog
2
2
 
3
+ ## v1.2.3
4
+ - 辞書ファイルが所定のフォーマットに沿っていなかった場合に処理を継続するよう修正
5
+ - エラー理由・検出語数・辞書タイプを戻り値に追加した
6
+ - `type` の `yml` と `json` を `local` に統一した
7
+
8
+
9
+ ```ruby
10
+ response = {
11
+ message: "1 ERROR(s) : error reason.",
12
+ count: 2,
13
+ type: "yml or json",
14
+ words: [
15
+ { type: 'yahoo', correct: "correct1", wrong: "wrong1" },
16
+ { type: 'local', correct: "correct2", wrong: "wrong2" },
17
+ ],
18
+ }
19
+ ```
20
+
3
21
  ## v1.2.2
4
22
  - JSON形式に対応した
5
23
  - `Jkproof.detect_words_has_error(sentence, json_dictionary)` のように第二引数にJSONデータを渡すことで対応可能
data/Gemfile.lock CHANGED
@@ -1,11 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jkproof (1.2.0)
5
- activesupport
6
- dotenv
7
- highline
8
- xml-simple
4
+ jkproof (1.2.3)
5
+ activesupport (~> 5.2)
6
+ dotenv (~> 2.6)
7
+ xml-simple (~> 1.1)
9
8
 
10
9
  GEM
11
10
  remote: https://rubygems.org/
@@ -18,7 +17,6 @@ GEM
18
17
  concurrent-ruby (1.1.4)
19
18
  diff-lcs (1.3)
20
19
  dotenv (2.6.0)
21
- highline (2.0.0)
22
20
  i18n (1.5.1)
23
21
  concurrent-ruby (~> 1.0)
24
22
  minitest (5.11.3)
data/README.md CHANGED
@@ -113,15 +113,40 @@ NO_FILTER=""
113
113
  ```ruby
114
114
  # 検出された場合
115
115
  Jkproof.detect_words_has_error("検知したい文章")
116
- # => [{ type: "yml", wrong: WrongWord, correct:CorrectWord }]
116
+ # => [
117
+ # message: "",
118
+ # count: 1,
119
+ # type: "yml",
120
+ # words: { type: "local", wrong: WrongWord, correct:CorrectWord },
121
+ # ]
117
122
 
118
123
  # 検出されなかった場合
119
124
  Jkproof.detect_words_has_error("")
120
- # => []
125
+ # => [
126
+ # message: "",
127
+ # count: 0,
128
+ # type: "yml",
129
+ # words: [],
130
+ # ]
121
131
 
122
132
  # JSONを渡す場合
123
133
  Jkproof.detect_words_has_error("検知したい文章", json_dictionary)
124
- # => [{ type: "json", wrong: WrongWord, correct:CorrectWord }]
134
+ # => [
135
+ # message: "",
136
+ # count: 1,
137
+ # type: "json",
138
+ # words: { type: "local", wrong: WrongWord, correct:CorrectWord },
139
+ # ]
140
+
141
+ # エラーがあった場合
142
+ # -- 処理自体は継続し、Yahooもしくは辞書のうち検知できるほうのみ返す
143
+ # -- どちらも返せない場合は空の配列を返す
144
+ # => [
145
+ # message: "x ERROR(s) : error reason.",
146
+ # count: 1,
147
+ # type: "json",
148
+ # words: { type: "yahoo", wrong: WrongWord, correct:CorrectWord },
149
+ # ]
125
150
  ```
126
151
 
127
152
  ## Development
data/jkproof.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  ex2.use JSON) Jkproof.detect_words_has_error(sentence, json)
18
18
  EOF
19
19
  spec.homepage = 'https://github.com/tosite0345/jkproof'
20
- spec.license = "MIT"
20
+ spec.license = 'MIT'
21
21
 
22
22
  # spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
23
23
  # spec.description = %q{TODO: Write a longer description or delete this line.}
@@ -18,37 +18,55 @@ module Jkproof
18
18
 
19
19
  @yahoo_words = []
20
20
  @buf = buf
21
- fetch_yahoo_lint_words
22
21
  end
23
22
 
24
23
  def fetch_wrong_words
24
+ error_messages = []
25
25
  wrong_words = []
26
26
  excluded_correct_word = @buf
27
27
 
28
+ begin
29
+ fetch_yahoo_lint_words
30
+ rescue StandardError => e
31
+ error_messages.push "yahoo api. (#{e})"
32
+ end
33
+
28
34
  # 正しいワードを取り除く
29
- @dictionary_words.each do |word|
30
- # 誤りのある単語の文字数 > 正しい単語の文字数の場合、先に検知する
31
- wrongs = fetch_wrong_words_than_long_correct_word(word['correct'], word['wrongs'])
32
- wrongs.each do |wrong|
33
- if excluded_correct_word.include?(wrong)
34
- wrong_words.push(type: @type, correct: word['correct'], wrong: wrong)
35
- excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
35
+ begin
36
+ @dictionary_words.each do |word|
37
+ # 誤りのある単語の文字数 > 正しい単語の文字数の場合、先に検知する
38
+ wrongs = fetch_wrong_words_than_long_correct_word(word['correct'], word['wrongs'])
39
+ wrongs.each do |wrong|
40
+ if excluded_correct_word.include?(wrong)
41
+ wrong_words.push(type: 'local', correct: word['correct'], wrong: wrong)
42
+ excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
43
+ end
36
44
  end
45
+ # 正しいワードを取り除く
46
+ excluded_correct_word = excluded_correct_word.gsub(word['correct'], '****')
37
47
  end
38
- # 正しいワードを取り除く
39
- excluded_correct_word = excluded_correct_word.gsub(word['correct'], '****')
40
- end
41
48
 
42
- @dictionary_words.each do |word|
43
- correct_word = word['correct']
44
- word['wrongs'].each do |wrong|
45
- if excluded_correct_word.include?(wrong)
46
- wrong_words.push(type: @type, wrong: wrong, correct: correct_word)
47
- excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
49
+ @dictionary_words.each do |word|
50
+ correct_word = word['correct']
51
+ word['wrongs'].each do |wrong|
52
+ if excluded_correct_word.include?(wrong)
53
+ wrong_words.push(type: 'local', wrong: wrong, correct: correct_word)
54
+ excluded_correct_word = excluded_correct_word.gsub(wrong, '####')
55
+ end
48
56
  end
49
57
  end
58
+ rescue StandardError => e
59
+ error_messages.push "yml or json dictionary. (#{e})"
50
60
  end
51
- wrong_words.concat(@yahoo_words).uniq
61
+
62
+ messages = error_messages.empty? ? '' : "#{error_messages.count} ERROR(s) : #{error_messages.join(', ')}"
63
+ words = wrong_words.concat(@yahoo_words).uniq
64
+ {
65
+ message: messages,
66
+ count: words.size,
67
+ type: @type,
68
+ words: words
69
+ }
52
70
  end
53
71
 
54
72
  private
@@ -64,8 +82,13 @@ module Jkproof
64
82
  # ローカルの辞書データを使う場合
65
83
  yml_path = ENV['DICTIONARY_YML_PATH']
66
84
  begin
67
- @type ='yml'
68
- @dictionary_words = yml_path.blank? ? [] : YAML.load_file(yml_path)
85
+ if yml_path.blank?
86
+ @dictionary_words = []
87
+ @type = 'none'
88
+ else
89
+ @dictionary_words = YAML.load_file(yml_path)
90
+ @type = 'yml'
91
+ end
69
92
  rescue StandardError => e
70
93
  raise "#{e}(file_path: '#{yml_path}')"
71
94
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jkproof
4
- VERSION = '1.2.2' # バージョンアップ
4
+ VERSION = '1.2.3' # バージョンアップ
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jkproof
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tosite