diff options
author | francis <francis> | 2008-10-27 18:18:29 +0000 |
---|---|---|
committer | francis <francis> | 2008-10-27 18:18:29 +0000 |
commit | 083693f0edb27b7e281e4d5469e901fd72125642 (patch) | |
tree | 493efc716f6cb10a174c7b62285b55ec75ebb05d /app/models/censor_rule.rb | |
parent | 52e145fd3928d9c17a2f1b06c076ea075b289297 (diff) |
Code to flexibly remove text from requests, configured via database.
Diffstat (limited to 'app/models/censor_rule.rb')
-rw-r--r-- | app/models/censor_rule.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb new file mode 100644 index 000000000..acc4349e6 --- /dev/null +++ b/app/models/censor_rule.rb @@ -0,0 +1,33 @@ +# 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.1 2008-10-27 18:18:30 francis Exp $ + +class CensorRule < ActiveRecord::Base + belongs_to :info_request + belongs_to :user + belongs_to :public_body + + def apply_to_text(text) + text.gsub!(self.text, self.replacement) + return text + end + def apply_to_binary(binary) + replacement = self.text.gsub(/./, 'x') + 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 + + + |