Question

>> description

=> [" name=\"margin-top\" content=\"1\" />\r\n", " name=\"oreintation\" content=\"horizontal\" />\r\n", " name=\"paper-height\" content=\"6\" />\r\n", " name=\"paper-width\" content=\"5\" />\r\n", " name=\"margin-left\" content=\"3\" />\r\n"]

description is of type array

I need key as margin-top value 1.
I need key as oreintation value oreintation and so on, how to get this done?

Was it helpful?

Solution

Use

result = {}
description.each{|val|
 result[val.split("\"")[1]] = val.split("\"")[3]
}
result # contains expected hash
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top