Chapter 15Templating Output with ERB

We’ve looked at writing data either in an unformatted way or into standard formats like XML, JSON, and CSV. Sometimes, though, we need to conform to more complex or more unusual formats, ones that don’t have ready-made libraries but that are nevertheless still text formats.

For example, imagine that we want to generate a financial report for a bar, outlining the purchases made by the bar in the past month. We want the final output to look something like this:

 
The Bistro Illegal
 
Sector RT 74
 
Lazgar Beta
 
 
Purchase ledger, October 2014
 
 
Generated: 4 October 2014, 12:49pm
 
 
Product Units Price
 
 
Ol' Janx Spirit 282 $27,918.00
 
Eau de Santraginus V 300 $600.00
 
Arcturan Mega-Gin 150 $7,500.00
 

Get Text Processing with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.