blob: ab65fd8314eb7d44984add3b7aead732666bf566 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# == Schema Information
# Schema version: 78
#
# Table name: censor_rules
#
# id :integer not null, primary key
# info_request_id :integer
# user_id :integer
# public_body_id :integer
# text :text not null
# replacement :text not null
# last_edit_editor :string(255) not null
# last_edit_comment :text not null
# created_at :datetime not null
# updated_at :datetime not null
#
# models/censor_rule.rb:
# Stores alterations to remove specific data from requests.
#
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: censor_rule.rb,v 1.12 2009-06-26 14:28:37 francis Exp $
class CensorRule < ActiveRecord::Base
belongs_to :info_request
belongs_to :user
belongs_to :public_body
def apply_to_text(text)
if text.nil?
return nil
end
text = text.gsub(self.text, self.replacement)
return text
end
def apply_to_binary(binary)
if binary.nil?
return nil
end
replacement = self.text.gsub(/./, 'x')
binary = binary.gsub(self.text, replacement)
return binary
end
def validate
if self.info_request.nil? && self.user.nil? && self.public_body.nil?
errors.add("Censor must apply to an info request a user or a body; ")
end
end
end
|