aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-04-29 12:20:50 +0100
committerGareth Rees <gareth@mysociety.org>2015-05-12 16:13:16 +0100
commitf2b292f61a8494ce77dbf5bd7ced2b010d20b688 (patch)
treeec3e7c71c5474d1461163980ea2b15857fe7a664
parent6e3d6c35d1aab075096e2c2191e8941b4625ca04 (diff)
Extract text cleaning from #body method
-rw-r--r--app/models/outgoing_message.rb19
1 files changed, 10 insertions, 9 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index c2c8ef4f2..e59ca4bd4 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -141,21 +141,17 @@ class OutgoingMessage < ActiveRecord::Base
end
def body
- ret = read_attribute(:body)
- if ret.nil?
- return ret
- end
+ text = read_attribute(:body).dup
+ return text if text.nil?
- ret = ret.dup
- ret.strip!
- ret.gsub!(/(?:\n\s*){2,}/, "\n\n") # remove excess linebreaks that unnecessarily space it out
+ text = clean_text(text)
# Remove things from censor rules
unless info_request.nil?
- self.info_request.apply_censor_rules_to_text!(ret)
+ self.info_request.apply_censor_rules_to_text!(text)
end
- ret
+ text
end
def raw_body
@@ -332,6 +328,11 @@ class OutgoingMessage < ActiveRecord::Base
errors.add(:what_doing_dummy, _('Please choose what sort of reply you are making.'))
end
end
+
+ # remove excess linebreaks that unnecessarily space it out
+ def clean_text(text)
+ text.strip.gsub(/(?:\n\s*){2,}/, "\n\n")
+ end
end