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.
24 lines
562 B
24 lines
562 B
3 months ago
|
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)
|
||
|
return text if text.blank?
|
||
|
|
||
|
text[0].downcase + text[1..]
|
||
|
end
|
||
|
end
|