Class: Slicker
- Inherits:
-
Object
- Object
- Slicker
- Defined in:
- lib/slicker.rb
Class Method Summary collapse
- .protect(params, config = {}) ⇒ Object
- .walk_array(array, config) ⇒ Object
- .walk_hash(hash, config) ⇒ Object
Class Method Details
.protect(params, config = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/slicker.rb', line 5 def self.protect(params, config = {}) if params.is_a?(String) Sanitize.clean(params, config) elsif params.is_a?(Array) walk_array(params, config) elsif params.is_a?(Hash) walk_hash(params, config) end end |
.walk_array(array, config) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/slicker.rb', line 28 def self.walk_array(array, config) array.each_with_index do |el,i| if el.is_a? String array[i] = Sanitize.clean(el, config) elsif el.is_a? Hash array[i] = walk_hash(el, config) elsif el.is_a? Array array[i] = walk_array(el, config) end end array end |
.walk_hash(hash, config) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/slicker.rb', line 15 def self.walk_hash(hash, config) hash.keys.each do |key| if hash[key].is_a? String hash[key] = Sanitize.clean(hash[key], config) elsif hash[key].is_a? Hash hash[key] = walk_hash(hash[key], config) elsif hash[key].is_a? Array hash[key] = walk_array(hash[key], config) end end hash end |