diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-10 17:23:13 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-15 15:47:08 +0100 |
commit | ccd7da2ca592db909e9ea12cf7135945f31ddd01 (patch) | |
tree | 79c4f588703aa3b548b4ab139223a1d70de4a6f3 | |
parent | 888b838921d4460cd2dbdf4a087ede1a04c39d6d (diff) |
Extract duplication in CensorRule
-rw-r--r-- | app/models/censor_rule.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index b346917ec..eda4e23af 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -64,13 +64,11 @@ class CensorRule < ActiveRecord::Base def apply_to_text!(text) return nil if text.nil? - to_replace = regexp? ? make_regexp : self.text text.gsub!(to_replace, replacement) end def apply_to_binary!(binary) return nil if binary.nil? - to_replace = regexp? ? make_regexp : text binary.gsub!(to_replace) { |match| match.gsub(/./, 'x') } end @@ -84,4 +82,10 @@ class CensorRule < ActiveRecord::Base info_request_id.nil? && user_id.nil? && public_body_id.nil? end + private + + def to_replace + regexp? ? make_regexp : text + end + end |