Browse Source

Improve readability

pull/2674/head
Manny Dinssa 2 years ago
parent
commit
6c6d1322a0
  1. 13
      app/helpers/formatting_helper.rb
  2. 2
      app/models/form/question.rb
  3. 8
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  4. 8
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  5. 8
      app/services/bulk_upload/sales/year2023/row_parser.rb
  6. 8
      app/services/bulk_upload/sales/year2024/row_parser.rb

13
app/helpers/formatting_helper.rb

@ -1,13 +1,16 @@
module FormattingHelper module FormattingHelper
def ensure_punctuation(value) def format_ending(value)
return value if value.blank? return value if value.blank?
value.match?(/[[:punct:]]\z/) && !value.match?(/[%(){}\[\]]\z/) ? value : "#{value}." ends_with_any_punctuation = value.match?(/[[:punct:]]\z/)
ends_with_special_char = value.match?(/[%(){}\[\]]\z/)
ends_with_any_punctuation && !ends_with_special_char ? value : "#{value}."
end end
def downcase_first_letter(sentence) def downcase_first_letter(text)
return sentence if sentence.blank? return text if text.blank?
sentence[0].downcase + sentence[1..] text[0].downcase + text[1..]
end end
end end

2
app/models/form/question.rb

@ -207,7 +207,7 @@ class Form::Question
def error_display_label def error_display_label
label = error_label || check_answer_label || header || id.humanize label = error_label || check_answer_label || header || id.humanize
ensure_punctuation(label) format_ending(label)
end end
def unanswered_error_message def unanswered_error_message

8
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -544,9 +544,9 @@ private
fields.each do |field| fields.each do |field|
if setup_question?(question) if setup_question?(question)
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))), category: :setup)
else else
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field])))) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1608,7 +1608,7 @@ private
field_127.present? ? 1 : 0 field_127.present? ? 1 : 0
end end
def downcase(sentence) def downcase(text)
downcase_first_letter(sentence) downcase_first_letter(text)
end end
end end

8
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -568,9 +568,9 @@ private
fields.each do |field| fields.each do |field|
if setup_question?(question) if setup_question?(question)
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))), category: :setup)
else else
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field])))) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1643,7 +1643,7 @@ private
Organisation.find(bulk_upload.organisation_id) Organisation.find(bulk_upload.organisation_id)
end end
def downcase(sentence) def downcase(text)
downcase_first_letter(sentence) downcase_first_letter(text)
end end
end end

8
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -1271,13 +1271,13 @@ private
fields.each do |field| fields.each do |field|
if errors[field].none? if errors[field].none?
block_log_creation! block_log_creation!
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))), category: :setup)
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field])))) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1336,7 +1336,7 @@ private
end end
end end
def downcase(sentence) def downcase(text)
downcase_first_letter(sentence) downcase_first_letter(text)
end end
end end

8
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -1407,13 +1407,13 @@ private
fields.each do |field| fields.each do |field|
if errors[field].none? if errors[field].none?
block_log_creation! block_log_creation!
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field]))), category: :setup) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))), category: :setup)
end end
end end
else else
fields.each do |field| fields.each do |field|
unless errors.any? { |e| fields.include?(e.attribute) } unless errors.any? { |e| fields.include?(e.attribute) }
errors.add(field, I18n.t("validations.invalid_option", question: ensure_punctuation(downcase(QUESTIONS[field])))) errors.add(field, I18n.t("validations.invalid_option", question: format_ending(downcase(QUESTIONS[field]))))
end end
end end
end end
@ -1510,7 +1510,7 @@ private
Organisation.find(bulk_upload.organisation_id) Organisation.find(bulk_upload.organisation_id)
end end
def downcase(sentence) def downcase(text)
downcase_first_letter(sentence) downcase_first_letter(text)
end end
end end

Loading…
Cancel
Save