My apologies if this has already been asked in a Ruby setting--I checked before posting but to be perfectly honest it has been a very long day and If I am missing the obvious, I apologize in advance!
I have the following string which contains a list of software packages installed on a system and for some reason I am having the hardest time parsing it. I know there has got to be a straight forward means of doing this in Ruby but I keep coming up short.
I would like to parse the below multi-line, tab-delimited, string into an array of arrays where I can then loop through each array element with an each_with_index and spit out the HTML code into my Rails app.
str = 'Product and/or Software Full Name 5242 [version 6.5.24] [Installed on: 12/31/2015]
Product and/or Software Full Name 5426 [version 22.4] [Installed on: 06/11/2013]
Product and/or Software Full Name 2451 [version 1.63] [Installed on: 12/17/2015]
Product and/or Software Full Name 5225 [version 43.22.51] [Installed on: 11/15/2011]
Product and/or Software Full Name 2420 [version 43.51-r2] [Installed on: 12/31/2015]'
The end result would be an array of arrays with 5 elements like so:
[["Product and/or Software Full Name 5245"],["version 6.5.24"], ["Installed on: 12/31/2015"],["Product and/or Software Full Name 5426"],["version 22.4"],["Installed on: 06/11/2013"],["Product and/or Software Full Name 2451"],["version 1.63"],["Installed on: 12/17/2015"]]
Please Note: Only 3 of 5 arrays are shown for brevity
I would prefer to strip out the brackets from both 'version' and 'Installed on' but I can do that with gsub separately if that cannot easily be baked into an answer.
Last thing is that there won't always be an 'Installed on' entry for every line in the multiline string, so the answer will need to take that into account as applicable.