Module: DeepTest::Option::Hash

Defined in:
lib/deep_test/option.rb

Class Method Summary collapse

Class Method Details

.from_string(string) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/deep_test/option.rb', line 28

def self.from_string(string)
  hash = {}
  string.split(/,/).each do |pair|
    key, unevaled_value = pair.split(/:/)
    value = eval(unevaled_value)
    value = value.gsub(/%20/, " ") if ::String === value
    hash[key.to_sym] = value
  end
  hash
end

.to_string(hash) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/deep_test/option.rb', line 19

def self.to_string(hash)
  pairs = []
  hash.each do |key, value|
    value = value.gsub(/ /,'%20') if (::String === value)
    pairs << "#{key}:#{value.inspect}"
  end
  pairs.join(",")
end