# Ruby DSL for invoices

**URL:** <https://www.ruby-forum.com/t/ruby-dsl-for-invoices/70847>\
**Category:** Ruby\
**Created:** [October 3, 2006, 1:31pm UTC](https://www.ruby-forum.com/t/ruby-dsl-for-invoices/70847 "2006-10-03T13:31:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 3, 2006, 1:31pm UTC](https://www.ruby-forum.com/t/ruby-dsl-for-invoices/70847/1 "2006-10-03T13:31:17Z")

</div>

Hi DSL fans,

I’ve been playing around with DSLs recently, inspired by the dynamism  
you get for free with Ruby, and thought I’d try writing one.

This is my first effort:  
[http://svn.edendevelopment.co.uk/public/invoice\_dsl/](http://svn.edendevelopment.co.uk/public/invoice_dsl/)

Check out the README.txt for more details. Basically it allows you to  
write an invoice in fairly natural language syntax, like this:

new\_invoice do  
address ‘Test Client, Street, ZIP’  
code ‘2006-45’  
date ‘3rd Oct’

```
work_at 50 do
  spent 3.on('Morning meeting')
  spent 0.5.on('Making the coffee for the boss').on('3rd Sept')
end

```

end

And you end up with  
[http://svn.edendevelopment.co.uk/public/invoice\_dsl/2006-45.pdf](http://svn.edendevelopment.co.uk/public/invoice_dsl/2006-45.pdf)

It’s work in progress, so suggestions for improvements are welcome.  
Feel free to adapt it for your needs, but please send me any  
significant patches or new templates so we can spread the love.

Original blog post is here:  
[http://blog.edendevelopment.co.uk/articles/2006/10/03/domain-specific-language-for-invoices](http://blog.edendevelopment.co.uk/articles/2006/10/03/domain-specific-language-for-invoices)

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 5, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/ruby-dsl-for-invoices/70847/2 "2006-10-05T14:16:40Z")

</div>

removed\_email\_address@domain.invalid wrote:

> [http://svn.edendevelopment.co.uk/public/invoice\_dsl/](http://svn.edendevelopment.co.uk/public/invoice_dsl/)

I’ve updated the DSL to support time and currency:

i = new\_invoice do  
1.pound | 1.5.euros

work\_at 20.pounds / hour do  
spent 2.hours.on(‘Some work’)  
spent 2.days.on(‘More work’) # Note: assumes a day is 8 hours long  
end  
end

print i.total.in.pounds # prints ‘360.00’  
print i.total.in.euros # prints ‘540.00’

Blog post:  
[http://blog.edendevelopment.co.uk/articles/2006/10/05/invoice-dsl-now-supports-time-and-currency](http://blog.edendevelopment.co.uk/articles/2006/10/05/invoice-dsl-now-supports-time-and-currency)
