dansguardian 0.2.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +8 -0
- data/README.rdoc +12 -8
- data/example.rb +5 -2
- data/lib/dansguardian.rb +1 -1
- data/lib/dansguardian/config/filtergroup.rb +6 -0
- data/lib/dansguardian/list.rb +30 -7
- metadata +4 -4
data/Changelog
CHANGED
data/README.rdoc
CHANGED
@@ -21,14 +21,18 @@ the same author.
|
|
21
21
|
|
22
22
|
dgconf.filtergroup(1, :cached => true)
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
listfile = dgconf.filtergroup(1)[:weightedphraselist]
|
25
|
+
listobject = DansGuardian::List.new(:file => listfile)
|
26
|
+
pp listobject
|
27
|
+
|
28
|
+
listfile2 = "/etc/dansguardian/lists/phraselists/goodphrases/weighted_news"
|
29
|
+
listobject2 = DansGuardian::List.new(
|
30
|
+
:file => listfile2,
|
31
|
+
:file_encoding => Encoding.find('ISO-8859-5')
|
32
|
+
)
|
33
|
+
|
34
|
+
listobject2.read!
|
35
|
+
pp listobject2
|
32
36
|
|
33
37
|
== License
|
34
38
|
|
data/example.rb
CHANGED
@@ -26,8 +26,11 @@ listfile = dgconf.filtergroup(1)[:weightedphraselist]
|
|
26
26
|
listobject = DansGuardian::List.new(:file => listfile)
|
27
27
|
pp listobject
|
28
28
|
|
29
|
-
listfile2 = "/etc/dansguardian/lists/phraselists/
|
30
|
-
listobject2 = DansGuardian::List.new(
|
29
|
+
listfile2 = "/etc/dansguardian/lists/phraselists/pornography/weighted_russian"
|
30
|
+
listobject2 = DansGuardian::List.new(
|
31
|
+
:file => listfile2,
|
32
|
+
:file_encoding => Encoding.find('ISO-8859-5')
|
33
|
+
)
|
31
34
|
listobject2.read!
|
32
35
|
pp listobject2
|
33
36
|
|
data/lib/dansguardian.rb
CHANGED
@@ -58,6 +58,12 @@ module DansGuardian
|
|
58
58
|
parameter name
|
59
59
|
end
|
60
60
|
|
61
|
+
# may override the main config file
|
62
|
+
parameter :weightedphrasemode,
|
63
|
+
'0' => false,
|
64
|
+
'1' => :normal,
|
65
|
+
'2' => :singular
|
66
|
+
|
61
67
|
parameter :naughtynesslimit, :to_i
|
62
68
|
|
63
69
|
virtual :naughtyness do |confdata|
|
data/lib/dansguardian/list.rb
CHANGED
@@ -7,25 +7,26 @@ module DansGuardian
|
|
7
7
|
# DansGuardian::List.new(:file = '/path/to/list')
|
8
8
|
def initialize(h={})
|
9
9
|
if h.is_a? String
|
10
|
-
@init
|
10
|
+
@init = {:file => h}
|
11
|
+
@file_encoding = Encoding::BINARY
|
11
12
|
else
|
12
|
-
@init
|
13
|
+
@init = h
|
13
14
|
end
|
14
|
-
@items
|
15
|
-
@includes
|
16
|
-
@listcategory
|
17
|
-
|
15
|
+
@items = []
|
16
|
+
@includes = []
|
17
|
+
@listcategory = nil
|
18
18
|
#read! if @init[:file]
|
19
19
|
end
|
20
20
|
|
21
21
|
def filename; @init[:file]; end
|
22
|
+
def file_encoding; @init[:file_encoding]; end
|
22
23
|
|
23
24
|
# Reads the file and fill @items ad @includes .
|
24
25
|
# This method might be overridden for non-trivial list types (?)
|
25
26
|
def read!
|
26
27
|
File.foreach(@init[:file]) do |line|
|
28
|
+
line.force_encoding file_encoding
|
27
29
|
line.strip!
|
28
|
-
line.force_encoding Encoding::BINARY
|
29
30
|
# Special comment used to "categorize" DG message pages
|
30
31
|
if line =~ /^#listcategory:\s*"(.*)"/
|
31
32
|
@listcategory = $1
|
@@ -41,5 +42,27 @@ module DansGuardian
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
45
|
+
def each_line(opts={:exclude => []})
|
46
|
+
Enumerator.new do |yielder|
|
47
|
+
File.foreach(@init[:file]) do |line|
|
48
|
+
line.strip!
|
49
|
+
line.force_encoding file_encoding
|
50
|
+
case line
|
51
|
+
when /^#listcategory:\s*"(.*)"/
|
52
|
+
next if opts[:exclude].include? :listcategory
|
53
|
+
when /^[\s#]*\.Include/
|
54
|
+
next if opts[:exclude].include? :includes
|
55
|
+
when /^[\s#]*</
|
56
|
+
next if opts[:exclude].include? :items
|
57
|
+
when /^\s*#/
|
58
|
+
next if opts[:exclude].include? :comment_lines
|
59
|
+
when /^\s*$/
|
60
|
+
next if opts[:exclude].include? :blank_lines
|
61
|
+
end
|
62
|
+
yielder.yield line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
44
67
|
end
|
45
68
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Guido De Rosa
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-20 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|