[LRUG] SourceClassifier gem
Chris Lowis
chris.lowis at gmail.com
Mon Dec 8 12:35:31 PST 2008
Hi LRUG,
I chatted to some of you about this project after Ruby Manor. I've
finally got round to releasing it as a gem:
http://github.com/chrislo/sourceclassifier/tree/master
Basically, it uses a Classifier to identify programming languages. It
can be used, for example, in blogging software to do automatic
colourisation of source code snippets.
Here's an example:
require 'rubygems'
require 'sourceclassifier'
s = SourceClassifier.new
ruby_text = <<EOT
def my_sorting_function(a)
a.sort
end
EOT
c_text = <<EOT
#include <unistd.h>
int main() {
write(1, "hello world\n", 12);
return(0);
}
EOT
s.identify(ruby_text) #=> Ruby
s.identify(c_text) #=> Gcc
It's the first gem I've released, and I'm sure there's some teething
problems as a result. If anyone is interested, and would like to test
it for me - that'd be a big help!
Cheers,
Chris
--
Chris Lowis
http://blog.chrislowis.co.uk/
More information about the Chat
mailing list