Hello,
I have the following problem.
There exists a really ugly debug log file which has mysql query
statements.
Looking through the log makes it hard to understand esp while providing
reports to bosses/mgrs etc. so I have decided to make it more “English”.
I
have over 40 queries, each that can be called in different ways, for
instance:
- select foo1, foo2 from foo where foo1=… etc
- select foo1 from foo where foo1= etc
The basic parsing would be
/select(.)\s+from\s+(.)(?:\s+where\s+(.*)$)/ #
its a bit more advanced, but its solved and hence not a problem
#captures[1] will be the table name
- Each table/view is its own class with a to_english method that does
the
translation - An abstract class that parses a line from the log file, extracts the
table or view (in this case foo) from the match and generates an object
using eval “#{table.capitalize}.new captures” - The to_english method generates an English representation of the
object
based on logic that uses information from the various captures passed
in.
The idea is to have a list of objects that I iterate over and do a
#to_english
My questions are:
- Should I organize this differently and run away from eval?
- Since there are over 40 odd classes, is there a better way to require
them other than:
Dir.glob(“qry*”).each { |r| require r }
Thank you,
Jayanth