# Parsing a string from a database and executing the result

**URL:** <https://www.ruby-forum.com/t/parsing-a-string-from-a-database-and-executing-the-result/181689>\
**Category:** Rails\
**Created:** [January 16, 2010, 2:53am UTC](https://www.ruby-forum.com/t/parsing-a-string-from-a-database-and-executing-the-result/181689 "2010-01-16T02:53:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/87869e/32.png) [@daz](https://www.ruby-forum.com/u/daz)\
**Post date:** [January 16, 2010, 2:53am UTC](https://www.ruby-forum.com/t/parsing-a-string-from-a-database-and-executing-the-result/181689/1 "2010-01-16T02:53:39Z")

</div>

Hi,

I originally posted this question in the ruby forum thinking that I had  
a design that would work and just needed help implementing it. However,  
I’ve been advised to try here for an alternative way to solve my  
problem…without creating the security hole that my method does.

I’d like to accomplish the following:

I’ve got a “macro” that is generating a bunch of reports. The reports  
contain lines like “the number of people in this group are X and they  
have spent a total of Y on your product this year”. The problem is, I  
can’t substitute X and Y for their real values at the time the macro  
runs, because I don’t know what filters the user will apply when viewing  
the reports. So I need a way  
to do the calculations and substitute in the values when the user views  
the report, and to recalculate these each time the user changes the  
filter (e.g. show me only people older than 30).

The controller will be pulling together a “@results” variable, but will  
not necessarily know what kinds of stats need to be pulled from it.  
That’s why i’d like to be able to do things like “the number of people  
in this group are `@results.size` and they spent  
`@results.collect(&:spend).sum` on your product this year”.

My original design is in this post:  
[http://www.ruby-forum.com/topic/202016#880654](http://www.ruby-forum.com/topic/202016#880654)

Any better suggestions would be very much welcome.

Thanks in advance

Dave
