aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/censor_rule.rb
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-08-01 14:39:18 +0100
committerRobin Houston <robin.houston@gmail.com>2012-08-01 14:39:18 +0100
commit67a3a43cc26f8ad7218f33a13af04c3c74347866 (patch)
tree3fc5f27905332ba4647915eb5823d3d37615fe4c /app/models/censor_rule.rb
parentc1d2580892033d28ff05f3d47cee78aaef963c29 (diff)
parentcc3268df4c9de319ea16aa99238e3c4c40dae7c5 (diff)
Merge branch 'develop' into wdtk
Diffstat (limited to 'app/models/censor_rule.rb')
-rw-r--r--app/models/censor_rule.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
index a477d2568..cedbd767e 100644
--- a/app/models/censor_rule.rb
+++ b/app/models/censor_rule.rb
@@ -9,6 +9,7 @@
# public_body_id :integer
# text :text not null
# replacement :text not null
+# regexp :boolean
# last_edit_editor :string(255) not null
# last_edit_comment :text not null
# created_at :datetime not null
@@ -28,6 +29,8 @@ class CensorRule < ActiveRecord::Base
belongs_to :user
belongs_to :public_body
+ named_scope :regexps, {:conditions => {:regexp => true}}
+
def binary_replacement
self.text.gsub(/./, 'x')
end
@@ -36,8 +39,10 @@ class CensorRule < ActiveRecord::Base
if text.nil?
return nil
end
- text.gsub!(self.text, self.replacement)
+ to_replace = regexp? ? Regexp.new(self.text, Regexp::MULTILINE) : self.text
+ text.gsub!(to_replace, self.replacement)
end
+
def apply_to_binary!(binary)
if binary.nil?
return nil
@@ -45,9 +50,8 @@ class CensorRule < ActiveRecord::Base
binary.gsub!(self.text, self.binary_replacement)
end
-
def validate
- if self.info_request.nil? && self.user.nil? && self.public_body.nil?
+ if !self.regexp? && 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