Created
April 30, 2018 16:15
-
-
Save nanosplit/924f2619d95ce1c5735a8e3f6f2904b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def arrayify(string) | |
if string.class == Array | |
string.to_a.map{ |v1| | |
if v1.class == Array | |
v1.map{ |v2| | |
if v2.class == Symbol | |
v2 | |
elsif v2.class == Array | |
v2.map{|k| | |
if k.class == Hash | |
k.map{|k,v| {k => arrayify(v)}} | |
else | |
k.strip | |
end | |
} | |
elsif v2.class == Hash | |
v2.map{ |key,value| | |
if value.class == Array || value.class == Hash | |
{key => arrayify(value)} | |
else | |
{key => value.strip} | |
end | |
} | |
else | |
v2.strip | |
end | |
} | |
elsif v1.class == Hash | |
v1.map{|k,v| {k => arrayify(v)}} | |
else | |
v1.split(',').join(',').split(',').map(&:strip) | |
end | |
}.flatten | |
elsif string.class == Hash | |
string.map{|k,v| | |
{k => arrayify(v)} | |
} | |
else | |
string.split(',').join(',').split(',').map(&:strip) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment