This is not a general purpose parser. It is a simple parser designed to convert a specific type
of CSV file to a specific XML format.
This requires Ruby 1.9.×. If you want to use it with early versions of ruby, use the FasterCSV gem and adjust the code as needed.
ChoiceID,Amount,Offer,Bullets
40112_existing,94.97,Digital + 1M + ULD,“NOW, GET MORE\n\n100+ channels of the best shows.\n\nInternet speeds up to 1Mbps.\n\nUnlimited long distance calling.”
It expects the Bullets column to include zero or more returns, and converts the paragraphs as follows:
- The first paragraph becomes the headline
- The following paragraphs are checked with a regular expression to place them into a “data”, “phone”, or “video” bullet.
- The services nodes are populated by testing with the same expression.
> cd /path_to_project
> ruby offer2xml.rb file_to_parse [optional_save_to_file]
If the optional argument is left off, the file name will be offers.xml and it will be saved in the same directory as the script.
> cd /path_to_project
> ruby test/offer_test.rb
That’s it. A very simple utility.