On Wed, 2 Nov 2005, Daniel Sheppard wrote:

> My solution only acts on one 'line' at a time, by calling enumerating
> over the content. However, if you pass in an array with multiple lines
> in each index, it can use that too. Matches are based on the punctuation

I don't quite understand that -- it seems to
reject {|x| String === x}
knock the strings out of arrays.

> structure and word count of the lines. This works really well for the
> example given, but may not in other situations.
> 
> http://members.iinet.net.au/~soxbox/ruby_quiz_53/dryer.rb
> http://members.iinet.net.au/~soxbox/ruby_quiz_53/array_sync_enum.rb
> 
> The lambda names in the output all suck completely which always makes
> the output longer than the input, but I don't have the time to make them
> prettier. It would be easy enough to do a find/replace on the lambda
> names to make something more useful. I've tried as much as possible to
> ensure that the generated output will match the generated input exactly.

I've not really got into that bit yet, but to use a block for that
is a novel suggestion.
> 
> It runs in O(n!) time in regards to line length, so putting an essay
> through this would take FOREVER. I would have been better off not using

:-)  Maybe some duplicate checking up front might help.

> the "generate every regex that matches this line" approach - but I
> neglected to throw anything with a decent line-length at it until late
> in the piece, and then I couldn't be bothered changing it. Just getting
> a list of tokens for each line and then matching up the lines with the
> most matching tokens would have sufficed. Doofus.
> 
> Here's the output generated for the quiz sample input.
> 
> %CREATE_TABLE_ = lambda do |arg0|
> %    "CREATE TABLE `"+arg0+"` ("
> %end
> %_id_int_11_NOT_NULL_auto_increment_ = lambda do ||
> %    "`id` int(11) NOT NULL auto_increment,"
> %end
        [...]
> 	<%=CREATE_TABLE_["authors"]%>
> 	  <%=_id_int_11_NOT_NULL_auto_increment_[]%>
> 	  <%=_varchar_NOT_NULL_default_["firstname","50"]%>
        [...]
> 	  <%=_description_text_NOT_NULL_[]%>
> 	  <%=PRIMARY_KEY_id_[]%>
> 	<%=_TYPE_MyISAM_AUTO_INCREMENT_["3"]%>
        [...]


I think this is the first one using erb.

        Thank you,
        Hugh