query_police 0.1.3.beta → 0.1.4.beta
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 +4 -4
- data/lib/query_police/analysis.rb +3 -2
- data/lib/query_police/helper.rb +14 -1
- data/lib/query_police/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be9c9ecaea3622ddb4c569a289fba9ba8f6fde860bb5a987d1176cba557d4bf
|
4
|
+
data.tar.gz: 8bdf19f5812a8bc990835d808f5bbc17c17764ed7cd853f11dfd9ae8d4d32984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 877344423887126e3b8d19ede4755e3d73c07172376340227119975835ab474b2dad60779afe284f9a93551b3bf63aff47e8d76b38bf42e384de0937fced0f64
|
7
|
+
data.tar.gz: fedcc1df590836fc6e55e7e41bb1527300f05ce0c3b12faf5b32cffcecd607b0f36dd0739b787a64fcddf45e6da78a693b6706d86bc8e9707e9c073ff52679b7
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "analysis/dynamic_message"
|
4
|
+
require_relative "helper"
|
4
5
|
|
5
6
|
module QueryPolice
|
6
7
|
# This class is used to store analysis of a query and provide methods over them
|
@@ -190,8 +191,8 @@ module QueryPolice
|
|
190
191
|
suggestion = dynamic_message(opts.merge({ "type" => "suggestion" }))
|
191
192
|
tag_message << ["impact", impact(opts.merge({ "colours" => true }))]
|
192
193
|
tag_message << ["tag_score", score(opts.merge({ "colours" => true }))]
|
193
|
-
tag_message << ["message", message]
|
194
|
-
tag_message << ["suggestion", suggestion] if suggestion.present?
|
194
|
+
tag_message << ["message", Helper.word_wrap(message)]
|
195
|
+
tag_message << ["suggestion", Helper.word_wrap(suggestion)] if suggestion.present?
|
195
196
|
|
196
197
|
tag_message
|
197
198
|
end
|
data/lib/query_police/helper.rb
CHANGED
@@ -34,7 +34,20 @@ module QueryPolice
|
|
34
34
|
JSON.parse(File.read(rules_path))
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
def word_wrap(string, width = 100)
|
38
|
+
words = string.split
|
39
|
+
wrapped_string = " "
|
40
|
+
|
41
|
+
words.each do |word|
|
42
|
+
last_line_size = (wrapped_string.split("\n")[-1]&.size || 0)
|
43
|
+
wrapped_string = wrapped_string.strip + "\n" if (last_line_size + word.size) > width
|
44
|
+
wrapped_string += "#{word} "
|
45
|
+
end
|
46
|
+
|
47
|
+
wrapped_string.strip
|
48
|
+
end
|
49
|
+
|
50
|
+
module_function :flatten_hash, :logger, :load_config, :word_wrap
|
38
51
|
end
|
39
52
|
|
40
53
|
private_constant :Helper
|
data/lib/query_police/version.rb
CHANGED