Class: MonadicExceptions::ResultSanitizer
- Inherits:
-
Object
- Object
- MonadicExceptions::ResultSanitizer
- Defined in:
- lib/result_sanitizer.rb
Overview
ResultSanitizer hold methods responsible to perform string transformations on the exception name
Instance Method Summary collapse
-
#apply_transformations_to_string(input, transformations) ⇒ String
This function apply any number of transformations (a proc that receive the value and return the transformed value) into a string input.
-
#remove_non_ascii_characters(input) ⇒ String
Without any character outside the ascii range.
- #treat_exception_name(exception) ⇒ Symbol
Instance Method Details
#apply_transformations_to_string(input, transformations) ⇒ String
This function apply any number of transformations (a proc that receive the value and return the transformed value) into a string input.
27 28 29 30 31 32 33 34 35 |
# File 'lib/result_sanitizer.rb', line 27 def apply_transformations_to_string(input, transformations) modified_string = input.dup transformations.each do |transformation| modified_string = transformation.call(modified_string) end modified_string end |
#remove_non_ascii_characters(input) ⇒ String
Returns without any character outside the ascii range.
18 19 20 |
# File 'lib/result_sanitizer.rb', line 18 def remove_non_ascii_characters(input) input.gsub(/[^\x00-\x7F]/, '') end |
#treat_exception_name(exception) ⇒ Symbol
8 9 10 11 12 13 14 |
# File 'lib/result_sanitizer.rb', line 8 def treat_exception_name(exception) apply_transformations_to_string(exception, [ proc { |x| x.downcase }, proc { |x| remove_non_ascii_characters(x) }, proc { |x| x.to_sym } ]) end |