key-word-filter-on 0.0.1 → 0.0.2
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/.DS_Store +0 -0
- data/README.md +18 -10
- data/key-word-filter-on.gemspec +5 -1
- data/lib/filter_key_word_on/key_word.rb +65 -138
- data/lib/generators/key_word_filter_on/migration/migration_generator.rb +0 -1
- data/lib/key-word-filter-on/key_word_filters.da +1 -1
- data/lib/key-word-filter-on/version.rb +1 -1
- metadata +24 -16
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.travis.yml +0 -9
- data/key_word_filter.gemspec +0 -22
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecc7d356476a60acceb8404cdb000c42ccbaf650
|
4
|
+
data.tar.gz: a5dc87425847e3cdeb3658ce08b39deef790c7be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36fc75ed51d547ada0193edd7f6303a8856d20fe0d846354a8a7d3be688a349787c89ef631ad7a889a51d93095fb1371a2b470f80afda90b7da4c34eb6e1dff2
|
7
|
+
data.tar.gz: 5704fac0c56c67e61e17715d871148433814a78babcb6a6600327e2dea7b5e2b5447651cd4c374c7946ad9ccb93cefc21414b542b8dce34757a6949276635c7c
|
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
@@ -8,22 +8,30 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
gem 'key-word-filter-on'
|
10
10
|
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
11
|
Or install it yourself as:
|
16
12
|
|
17
13
|
$ gem install key-word-filter-on
|
18
14
|
|
15
|
+
rails g key_word_filter_on:migration
|
16
|
+
|
17
|
+
User:
|
18
|
+
|
19
|
+
|
19
20
|
## Usage
|
20
21
|
|
21
|
-
|
22
|
+
content = FilterKeyWordOn.handle_word("content", "*")
|
23
|
+
|
24
|
+
or
|
25
|
+
|
26
|
+
alias :origin_save :save
|
27
|
+
|
28
|
+
def save
|
29
|
+
self.content = FilterKeyWordOn.handle_word(comment.content, "*")
|
30
|
+
self.origin_save
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
22
35
|
|
23
36
|
## Contributing
|
24
37
|
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/key-word-filter-on.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["wtuyuupe@163.com"]
|
7
7
|
gem.description = %q{Filter sensitive keyword method.}
|
8
8
|
gem.summary = %q{Filtering illegal characters and sensitive words.}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "https://github.com/tonglijia/key_word_filter_on"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -14,4 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "key-word-filter-on"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = KeyWordFilterOn::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "activerecord", ">= 3.1"
|
19
|
+
|
20
|
+
|
17
21
|
end
|
@@ -1,162 +1,89 @@
|
|
1
1
|
module FilterKeyWordOn
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
base.send :
|
6
|
-
base.send :extend, ClassMethods # 引入类方法
|
3
|
+
def self.included(base)
|
4
|
+
base.send :include, InstanceMethods
|
5
|
+
base.send :extend, ClassMethods
|
7
6
|
end
|
8
7
|
|
9
|
-
module InstanceMethods
|
10
|
-
#TODO
|
11
|
-
end#InstanceMethods
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
#TODO
|
15
|
-
end#ClassMethods
|
16
8
|
class KeyWordFilter < ActiveRecord::Base
|
17
9
|
attr_accessible :content, :replace
|
18
10
|
end
|
19
11
|
|
20
12
|
content, replace = ''
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# ==== 参数
|
26
|
-
# * <tt>content</tt> - 过滤内容
|
27
|
-
#
|
28
|
-
# ==== 示例
|
29
|
-
#
|
30
|
-
# KeyWordFilter.replace_content(content)
|
31
|
-
#
|
32
|
-
# ==== 返回
|
33
|
-
# true/false
|
34
|
-
#
|
35
|
-
def self.replace_content(content)
|
36
|
-
return handle_word(content)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
# 查询关键字生成数据, 多维数组伸平
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# 作者: 佟立家
|
44
|
-
# 最后更新时间: 2011-12-31
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# ==== 返回
|
48
|
-
# ['1','1']
|
49
|
-
#
|
50
|
-
def self.replacement_hash
|
51
|
-
Hash[*FilterKeyWordOn::KeyWordFilter.all.collect{|re| [re.content,re.replace] }.flatten]
|
52
|
-
end
|
53
|
-
|
13
|
+
|
14
|
+
def self.replacement_hash
|
15
|
+
Hash[FilterKeyWordOn::KeyWordFilter.all.collect{|re| [re.content,re.replace] }]
|
16
|
+
end
|
54
17
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
#
|
63
|
-
# ==== 示例
|
64
|
-
#
|
65
|
-
#
|
66
|
-
# ==== 返回
|
67
|
-
#
|
68
|
-
def self.filter_word_tree(object = nil)
|
69
|
-
word_tree = Array.new(256) << 0
|
70
|
-
object = replacement_hash if object.nil?
|
71
|
-
object.each do |word,replace|
|
72
|
-
temp = word_tree
|
73
|
-
bytes = word.bytes.to_a
|
74
|
-
len = bytes.size
|
18
|
+
def self.filter_word_tree(object = nil)
|
19
|
+
word_tree = Array.new(256) << 0
|
20
|
+
object = replacement_hash if object.nil?
|
21
|
+
object.each do |word,replace|
|
22
|
+
temp = word_tree
|
23
|
+
bytes = word.bytes.to_a
|
24
|
+
len = bytes.size
|
75
25
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
else
|
85
|
-
end
|
86
|
-
temp = temp[asicc_code][0]
|
26
|
+
bytes.each_with_index do |asicc_code,arr_index|
|
27
|
+
if arr_index < len - 1
|
28
|
+
if temp[asicc_code].nil?
|
29
|
+
node = [Array.new(256),0]
|
30
|
+
temp[asicc_code] = node
|
31
|
+
elsif temp[asicc_code] == 1
|
32
|
+
node = [Array.new(256),1]
|
33
|
+
temp[asicc_code] = node
|
87
34
|
else
|
88
|
-
temp[asicc_code] = 1
|
89
35
|
end
|
36
|
+
temp = temp[asicc_code][0]
|
37
|
+
else
|
38
|
+
temp[asicc_code] = 1
|
90
39
|
end
|
91
40
|
end
|
92
|
-
[word_tree,0]
|
93
|
-
|
94
41
|
end
|
42
|
+
[word_tree,0]
|
43
|
+
end
|
95
44
|
|
45
|
+
def self.handle_word(do_words,replace = true,word_tree = nil,word_hash = nil)
|
46
|
+
word_tree = filter_word_tree if word_tree.nil?
|
47
|
+
word_hash = replacement_hash if word_hash.nil?
|
48
|
+
temp = word_tree
|
49
|
+
nodeTree = word_tree
|
50
|
+
words = []
|
51
|
+
word = []
|
52
|
+
to_replace= []
|
53
|
+
a = 0
|
54
|
+
byte_words = do_words.bytes.to_a
|
55
|
+
while a < byte_words.size
|
56
|
+
index = byte_words[a]
|
57
|
+
temp = temp[0][index]
|
58
|
+
if temp.nil?
|
59
|
+
temp = nodeTree
|
60
|
+
a = a - word.size
|
61
|
+
word = []
|
62
|
+
to_replace = []
|
63
|
+
elsif temp == 1 or temp[1] == 1
|
64
|
+
word << index
|
65
|
+
to_replace << a
|
66
|
+
words << word
|
96
67
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
# 作者: 佟立家
|
102
|
-
# 最后更新时间: 2011-12-31
|
103
|
-
#
|
104
|
-
# ==== 参数
|
105
|
-
# * <tt>do_words</tt> -
|
106
|
-
# * <tt>replace</tt> -
|
107
|
-
# * <tt>word_tree</tt> -
|
108
|
-
# * <tt>word_hash</tt> -
|
109
|
-
#
|
110
|
-
# ==== 示例
|
111
|
-
#
|
112
|
-
# KeyWordFilter.replace_content(content)
|
113
|
-
#
|
114
|
-
# ==== 返回
|
115
|
-
# true/false
|
116
|
-
#
|
117
|
-
def self.handle_word(do_words,replace = true,word_tree = nil,word_hash = nil)
|
118
|
-
word_tree = filter_word_tree if word_tree.nil?
|
119
|
-
word_hash = replacement_hash if word_hash.nil?
|
120
|
-
temp = word_tree
|
121
|
-
nodeTree = word_tree
|
122
|
-
words = []
|
123
|
-
word = []
|
124
|
-
to_replace= []
|
125
|
-
a = 0
|
126
|
-
byte_words = do_words.bytes.to_a
|
127
|
-
while a < byte_words.size
|
128
|
-
index = byte_words[a]
|
129
|
-
temp = temp[0][index]
|
130
|
-
if temp.nil?
|
131
|
-
temp = nodeTree
|
132
|
-
a = a - word.size
|
133
|
-
word = []
|
134
|
-
to_replace = []
|
135
|
-
elsif temp == 1 or temp[1] == 1
|
136
|
-
word << index
|
137
|
-
to_replace << a
|
138
|
-
words << word
|
139
|
-
|
140
|
-
if replace
|
141
|
-
replace_word = word_hash[word.pack("C*").force_encoding("UTF-8")].bytes.to_a
|
142
|
-
byte_words[(a-to_replace.size + 1),to_replace.size] = replace_word
|
143
|
-
a = (a - to_replace.size + 1) + (replace_word.size - 1)
|
144
|
-
else
|
145
|
-
a = a - word.size + 1
|
146
|
-
end
|
147
|
-
word = []
|
148
|
-
to_replace = []
|
149
|
-
temp = nodeTree
|
68
|
+
if replace
|
69
|
+
replace_word = word_hash[word.pack("C*").force_encoding("UTF-8")].bytes.to_a
|
70
|
+
byte_words[(a-to_replace.size + 1),to_replace.size] = replace_word
|
71
|
+
a = (a - to_replace.size + 1) + (replace_word.size - 1)
|
150
72
|
else
|
151
|
-
word
|
152
|
-
to_replace << a
|
73
|
+
a = a - word.size + 1
|
153
74
|
end
|
154
|
-
|
75
|
+
word = []
|
76
|
+
to_replace = []
|
77
|
+
temp = nodeTree
|
78
|
+
else
|
79
|
+
word << index
|
80
|
+
to_replace << a
|
155
81
|
end
|
156
|
-
|
157
|
-
words.collect{|e| e.collect{|ch|ch.chr}.join }
|
82
|
+
a += 1
|
158
83
|
end
|
84
|
+
return byte_words.pack("C*").force_encoding("UTF-8") if replace
|
85
|
+
words.collect{|e| e.collect{|ch|ch.chr}.join }
|
86
|
+
end
|
159
87
|
|
160
|
-
end
|
161
|
-
|
88
|
+
end
|
162
89
|
|
metadata
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: key-word-filter-on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- lijia.tong
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
14
27
|
description: Filter sensitive keyword method.
|
15
28
|
email:
|
16
29
|
- wtuyuupe@163.com
|
@@ -18,9 +31,7 @@ executables: []
|
|
18
31
|
extensions: []
|
19
32
|
extra_rdoc_files: []
|
20
33
|
files:
|
21
|
-
- .
|
22
|
-
- .rspec
|
23
|
-
- .travis.yml
|
34
|
+
- .DS_Store
|
24
35
|
- CHANGELOG
|
25
36
|
- Gemfile
|
26
37
|
- Guardfile
|
@@ -30,7 +41,6 @@ files:
|
|
30
41
|
- README.rdoc
|
31
42
|
- Rakefile
|
32
43
|
- key-word-filter-on.gemspec
|
33
|
-
- key_word_filter.gemspec
|
34
44
|
- lib/filter_key_word_on/key_word.rb
|
35
45
|
- lib/generators/key_word_filter_on/migration/migration_generator.rb
|
36
46
|
- lib/generators/key_word_filter_on/migration/templates/active_record/migration.rb
|
@@ -39,29 +49,27 @@ files:
|
|
39
49
|
- lib/key-word-filter-on/version.rb
|
40
50
|
- rails/init.rb
|
41
51
|
- uninstall.rb
|
42
|
-
homepage:
|
52
|
+
homepage: https://github.com/tonglijia/key_word_filter_on
|
43
53
|
licenses: []
|
54
|
+
metadata: {}
|
44
55
|
post_install_message:
|
45
56
|
rdoc_options: []
|
46
57
|
require_paths:
|
47
58
|
- lib
|
48
59
|
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
60
|
requirements:
|
51
|
-
- -
|
61
|
+
- - '>='
|
52
62
|
- !ruby/object:Gem::Version
|
53
63
|
version: '0'
|
54
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
65
|
requirements:
|
57
|
-
- -
|
66
|
+
- - '>='
|
58
67
|
- !ruby/object:Gem::Version
|
59
68
|
version: '0'
|
60
69
|
requirements: []
|
61
70
|
rubyforge_project:
|
62
|
-
rubygems_version:
|
71
|
+
rubygems_version: 2.0.3
|
63
72
|
signing_key:
|
64
|
-
specification_version:
|
73
|
+
specification_version: 4
|
65
74
|
summary: Filtering illegal characters and sensitive words.
|
66
75
|
test_files: []
|
67
|
-
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/key_word_filter.gemspec
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
$:.push File.dirname(__FILE__) + '/lib'
|
2
|
-
require 'key-word-filter-on/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = %q{key-word-filter-on}
|
6
|
-
gem.authors = ["Lijia.Tong"]
|
7
|
-
gem.date = %q{2012-08-05}
|
8
|
-
gem.description = %q{Filter sensitive keyword method.}
|
9
|
-
gem.summary = "Filtering illegal characters and sensitive words."
|
10
|
-
gem.email = %q{wtuyuupe@163.com}
|
11
|
-
gem.homepage = 'http://hi.baidu.com/new/user_tony'
|
12
|
-
|
13
|
-
gem.add_runtime_dependency 'rails', '~> 3.0'
|
14
|
-
gem.add_development_dependency 'rspec', '~> 2.6'
|
15
|
-
|
16
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
-
gem.files = `git ls-files`.split("\n")
|
18
|
-
# gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
gem.name = "key-word-filter-on"
|
20
|
-
gem.require_paths = ['lib']
|
21
|
-
gem.version = KeyWordFilterOn::VERSION
|
22
|
-
end
|