Class: Hash

Inherits:
Object show all
Defined in:
lib/video_converter/hash.rb

Instance Method Summary collapse

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 |options, (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
    options[key] = value
    options
  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_keysObject



2
3
4
5
6
7
8
9
# File 'lib/video_converter/hash.rb', line 2

def deep_symbolize_keys
  inject({}) do |options, (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
    options[(key.to_sym rescue key) || key] = value
    options
  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