Module: EpicHashCleaner
- Defined in:
- lib/epic_hash_cleaner.rb,
lib/epic_hash_cleaner/version.rb
Constant Summary collapse
- VERSION =
'0.1.1'.freeze
Class Method Summary collapse
-
.blank?(value) ⇒ Boolean
based on File activesupport/lib/active_support/core_ext/object/blank.rb rubocop:disable Style/DoubleNegation.
- .clean(hash) ⇒ Object
- .clean_array(array) ⇒ Object
- .clean_hash(hash) ⇒ Object
- .clean_value(value) ⇒ Object
Class Method Details
.blank?(value) ⇒ Boolean
based on File activesupport/lib/active_support/core_ext/object/blank.rb rubocop:disable Style/DoubleNegation
27 28 29 |
# File 'lib/epic_hash_cleaner.rb', line 27 def blank?(value) value.respond_to?(:empty?) ? !!value.empty? : !value end |
.clean(hash) ⇒ Object
6 7 8 9 |
# File 'lib/epic_hash_cleaner.rb', line 6 def clean(hash) return {} if hash.nil? clean_hash(hash) end |
.clean_array(array) ⇒ Object
15 16 17 |
# File 'lib/epic_hash_cleaner.rb', line 15 def clean_array(array) array.delete_if { |v| clean_value(v) } end |
.clean_hash(hash) ⇒ Object
11 12 13 |
# File 'lib/epic_hash_cleaner.rb', line 11 def clean_hash(hash) hash.delete_if { |_, v| clean_value(v) } end |
.clean_value(value) ⇒ Object
19 20 21 22 23 |
# File 'lib/epic_hash_cleaner.rb', line 19 def clean_value(value) clean_hash(value) if value.is_a?(Hash) clean_array(value) if value.is_a?(Array) blank?(value) if value != false end |