class RDStation::Error::Format
Constants
- ARRAY_OF_HASHES
- FLAT_HASH
- HASH_OF_ARRAYS
- HASH_OF_HASHES
- HASH_OF_MULTIPLE_TYPES
- SINGLE_HASH
Public Class Methods
new(errors)
click to toggle source
# File lib/rdstation/error/format.rb, line 13 def initialize(errors) @errors = errors end
Public Instance Methods
format()
click to toggle source
# File lib/rdstation/error/format.rb, line 17 def format return FLAT_HASH if flat_hash? return SINGLE_HASH if single_hash? return HASH_OF_ARRAYS if hash_of_arrays? return HASH_OF_HASHES if hash_of_hashes? return HASH_OF_MULTIPLE_TYPES if hash_of_multiple_types? ARRAY_OF_HASHES end
Private Instance Methods
flat_hash?()
click to toggle source
# File lib/rdstation/error/format.rb, line 35 def flat_hash? return unless @errors.is_a?(Hash) @errors.key?('error_type') end
hash_of_arrays?()
click to toggle source
# File lib/rdstation/error/format.rb, line 41 def hash_of_arrays? @errors.is_a?(Hash) && @errors.values.all? { |error| error.is_a? Array } end
hash_of_hashes?()
click to toggle source
# File lib/rdstation/error/format.rb, line 45 def hash_of_hashes? @errors.is_a?(Hash) && @errors.values.all? { |error| error.is_a? Hash } end
hash_of_multiple_types?()
click to toggle source
# File lib/rdstation/error/format.rb, line 49 def hash_of_multiple_types? @errors.is_a?(Hash) && @errors.values.any? { |error| error.is_a? Hash } && @errors.values.any? { |error| error.is_a? Array } end
single_hash?()
click to toggle source
# File lib/rdstation/error/format.rb, line 29 def single_hash? return unless @errors.is_a?(Hash) @errors.key?('error') || @errors.key?('message') end