Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion ruby_solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,41 @@
def refineParameters input
# If you want to use the input file before running the tests, uncomment the following line
# input = JSON.parse(File.read(File.join(File.dirname(File.absolute_path(__FILE__)), 'tests/challenge.json')))

output = parseHash(input)

# Write your code here.
return input
return output
end

def parseHash(hash)
hash.each do |k, v|
if(v.is_a?(Hash))
hash[k] = parseHash(v)
elsif(v.is_a?(Array))
v = v.map do |subValue|
convertType(subValue)
end

hash[k] = v
else
hash[k] = convertType(v)
end
end

hash
end

def convertType(value)
if( value.casecmp("true") == 0)
true
elsif ( value.casecmp("false") == 0)
false
elsif ((value.to_i != 0 || value == "0") && !value.include?("-"))
# to_i returns 0 if it can't parse the string. Checking for - means
# dates don't get automatically converted
value.to_i
else
value
end
end