Life is good.
For those who didn't read the previous blog post, I killed my GNOME desktop and messed up a lot of other things and lived on an ancient version of KDE that was very reliable but ugly and slow (as old things often are).
A quick format and reinstall (after backing up documents of course)solved the issue!
To celebrate I decided to recreate cowsay (sudo apt-get install cowsay | cowsay hi) in Ruby!
The app it's self was extremely simple, print the usage, get the input and print the cow ascii along with the parsed input.
The problem lay in the fact that Ruby wouldn't parse the whitespace which was essential to render the cow properly, the script worked perfectly except it looked like the cow had been dismbowled and scattered across the console.
A quick visit to #ruby on the ubuntu irc network and great help from the user DMajrekar resulted in a perfected talking cow and now it is ready to take over the world!
Here's a preview of the program, code is below.

And the code:
#!usr/bin/ruby
puts "Cow say what?"
say = gets
say.chomp!
print " "
(say.length + 2).times{ print "_" }
print "\n< "+ say +" >\n "
(say.length + 2).times{ print "-" }
print "
\\ ^__^
\\ (oo)\\_______
(__)\\ )\\/\\
||----w |
|| ||
"
Not too bad eh? It's a little messy I guess but it is an entirely faithful reproduction of cowsay. You could swap the cow for any ascii character you like, I'll give some examples later!
Till next time...

0 comments:
Post a Comment