Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

25 lines
646 B

module FormattingHelper
def format_ending(text)
return text if text.blank?
modified_text = lowercase_first_letter(text)
ensure_sentence_ending(modified_text)
end
def ensure_sentence_ending(text)
return text if text.blank?
ends_with_any_punctuation = text.match?(/[[:punct:]]\z/)
ends_with_special_char = text.match?(/[%(){}\[\]]\z/)
ends_with_any_punctuation && !ends_with_special_char ? text : "#{text}."
end
def lowercase_first_letter(text)
first_word = text.split.first
return text if first_word == first_word.upcase
return text if text.blank?
text[0].downcase + text[1..]
end
end