Class: Hash
Instance Method Summary collapse
- #deep_join(separator) ⇒ Object
- #deep_join!(separator) ⇒ Object
- #deep_shellescape_values(safe_keys = []) ⇒ Object
- #deep_shellescape_values!(safe_keys = []) ⇒ Object
- #deep_symbolize_keys ⇒ Object
- #deep_symbolize_keys! ⇒ Object
Instance Method Details
#deep_join(separator) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/video_converter/hash.rb', line 35 def deep_join(separator) map do |key, value| case value.class.to_s when 'TrueClass' key when 'FalseClass', 'NilClass' nil when 'Array' value.map { |v| "#{key} #{v}"} when 'Hash' value.deep_join(separator) else "#{key} #{value}" end end.join(separator) end |
#deep_join!(separator) ⇒ Object
52 53 54 |
# File 'lib/video_converter/hash.rb', line 52 def deep_join!(separator) self.replace(self.deep_join(separator)) end |
#deep_shellescape_values(safe_keys = []) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/video_converter/hash.rb', line 15 def deep_shellescape_values(safe_keys = []) inject({}) do |, (key, value)| if safe_keys.include?(key) value elsif value.is_a? Array value = value.map { |v| v.is_a?(Hash) ? v.deep_shellescape_values(safe_keys) : v.shellescape } elsif value.is_a? Hash value = value.deep_shellescape_values(safe_keys) elsif value.is_a?(String) && !value.empty? value = value.shellescape end [key] = value end end |
#deep_shellescape_values!(safe_keys = []) ⇒ Object
31 32 33 |
# File 'lib/video_converter/hash.rb', line 31 def deep_shellescape_values!(safe_keys = []) self.replace(self.deep_shellescape_values(safe_keys)) end |
#deep_symbolize_keys ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/video_converter/hash.rb', line 2 def deep_symbolize_keys inject({}) do |, (key, value)| value = value.map { |v| v.is_a?(Hash) ? v.deep_symbolize_keys : v } if value.is_a? Array value = value.deep_symbolize_keys if value.is_a? Hash [(key.to_sym rescue key) || key] = value end end |
#deep_symbolize_keys! ⇒ Object
11 12 13 |
# File 'lib/video_converter/hash.rb', line 11 def deep_symbolize_keys! self.replace(self.deep_symbolize_keys) end |