The calendar is gone.
Click here to view posts


Ruby formatter
Everyone has a preference on formatting code. I have found that there are a lot of very adamant people when it comes to the formatting of code. Unless a developer is using a language, like Python, that requires you to indent code it is up to the developer to correctly indent. When working with a team of people of you can have someone who does not care as much for strict formatting and you can have some one who is a formatting extremist.


To resolve some issues with other team members I have created a simple ruby formatter. I call it simple because it only formats one line at a time. There is not looking around at different lines, no knowledge of location in an object, or even scoping. I would like to create a rbchecker that would be like Pychecker, but this project is not that advanced. There is no parsing of ruby syntax, instead I am just looking for simple patterns. I am sure I missed a pattern or two but I have the option to create a back of the original file. I suggest turning on the back up for the first time you run this.

After I finished up a few test i figured i would look around to see if there were any other formatters. Turns out there are a few but, sine I am already done... Why not release it anyways?

Right now it is mostly comments, and no i did not run the formatter on it's self. I have been testing it on other projects of mine and koders.com ruby files.

Where to get it:

My svn http://svn.stephenbeckeriv.com/code/ruby_formatter/

How to use it:

Required:
-f file/location/e.rb
This can also be called with commas
-f file/location/e.rb,file/location/q.rb,file/location/w.rb
I am willing to change this if someone has a better idea.


Optional:
-s # will set using spaces with the size of an indent being #, the default is a tab
-b will create a backup of the file that is filename+",bk."+#{Time.now} I suggest using this when you run it for the first time.

ruby simple_formatter.rb -f /home/sbecker/test_file.rb
The only output should be "Done!"


ruby simple_formatter.rb -s 2 -f /home/sbecker/test_file.rb
Same formatted file now with two spaces instead of tabs


ruby simple_formatter.rb -b -f /home/sbecker/test_file.rb
Creates formated file as test_file.rb and the original file test_file.bk.#{Time.now}


I will be updating the code as a find more things that break it. Right now its worked for 95% of the code i tested it on. The only thing i know it does not work with currently is one line do end statements.