dansguardian 0.2.3 → 0.4.0

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.
data/Changelog CHANGED
@@ -1,3 +1,11 @@
1
+ 0.4.0 (2011-02-20)
2
+
3
+ * filtergroup: :weightedphrasemode (may override the main config)
4
+
5
+ 0.3.0 (2011-02-17)
6
+
7
+ * lists: file encoding support
8
+
1
9
  0.2.3 (2011-02-16)
2
10
 
3
11
  * slight doc fixes
@@ -21,14 +21,18 @@ the same author.
21
21
 
22
22
  dgconf.filtergroup(1, :cached => true)
23
23
 
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(listfile2)
30
- listobject2.read!
31
- pp listobject2
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/goodphrases/weighted_news"
30
- listobject2 = DansGuardian::List.new(listfile2)
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
 
@@ -5,7 +5,7 @@ autoload :Set, 'set'
5
5
  require 'configfiles'
6
6
 
7
7
  module DansGuardian
8
- VERSION = '0.2.3'
8
+ VERSION = '0.4.0'
9
9
 
10
10
  autoload :Config, 'dansguardian/config'
11
11
  autoload :Parser, 'dansguardian/parser'
@@ -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|
@@ -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 = {:file => h}
10
+ @init = {:file => h}
11
+ @file_encoding = Encoding::BINARY
11
12
  else
12
- @init = h
13
+ @init = h
13
14
  end
14
- @items = []
15
- @includes = []
16
- @listcategory = nil
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
- - 2
8
- - 3
9
- version: 0.2.3
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-16 00:00:00 +00:00
17
+ date: 2011-02-20 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency