aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/censor_rule.rb
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-07-13 11:19:54 +0100
committerSeb Bacon <seb.bacon@gmail.com>2012-07-13 11:19:54 +0100
commit67df820b1d41402a413d1899cfdbdb4da69f7685 (patch)
treee81bff73aec870ba03bea0218d77c7e54a703c82 /app/models/censor_rule.rb
parent39fdae7de23244b47581c197e1d78506aebf5af1 (diff)
parent2257aad346959a843b58c61758b5daf4a58688da (diff)
Merge branch 'feature/czech-website-support' into develop
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