Class: Swallow::RuleSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ruleset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ RuleSet

Returns a new instance of RuleSet.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruleset.rb', line 9

def initialize(filename)
  @rules = YAML.load_file(filename)
  @rules.each do |rule|
    if rule[:folder] != nil then
      if rule[:domains] != nil then
        # replace the string domain list with a regexp domain list
        rule[:domains] = rule[:domains].map { |i| Regexp.quote(i) }
      end
      if rule[:to] != nil then
        # replace the string to list with a regexp to list
        rule[:to] = rule[:to].map { |i| Regexp.quote(i) }
      end
      if rule[:from] != nil then
        # replace the string from list with a regexp from list
        rule[:from] = rule[:from].map { |i| Regexp.quote(i) }
      end
    end
  end
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



7
8
9
# File 'lib/ruleset.rb', line 7

def rules
  @rules
end

Instance Method Details

#to_sObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/ruleset.rb', line 28

def to_s
  s = String.new("Rules Hash Holds:\n")
  @rules.each { |rule|
    s << "#{rule[:folder]}"
    s << "#{rule[:to]}" if rule[:to] != nil
    s << "#{rule[:from]}" if rule[:from] != nil
    s <<  "#{rule[:domains]}" if rules[:domains] != nil
  }
  s
end