Class: ElectionBuddy::ErrorFormatter
- Inherits:
-
Object
- Object
- ElectionBuddy::ErrorFormatter
- Defined in:
- lib/election_buddy/error_formatter.rb
Overview
Formats error messages from hash responses
Class Method Summary collapse
-
.format(error_hash) ⇒ String?
Formats error messages from a hash into a human-readable string.
Class Method Details
.format(error_hash) ⇒ String?
Formats error messages from a hash into a human-readable string
15 16 17 18 19 20 21 22 23 |
# File 'lib/election_buddy/error_formatter.rb', line 15 def self.format(error_hash) return if error_hash.nil? || error_hash.empty? error_hash.map do |key, value| formatted_key = key.gsub("_", " ").split.map(&:capitalize).join(" ") formatted_value = value.is_a?(Array) ? value.join(", ") : value "#{formatted_key}: #{formatted_value}" end.join(", ") end |