Terse Ruby
A simple utility to allow you to write shorthand for Ruby classes; the utility will then convert this shorthand file into a genuine Ruby .rb file (either writing a new file or overwriting)
E.g. terse_file.txt contains :
req a_gem
c AClass
i AnInclude
d method1
Then Terse Ruby will write a new file terse_file.rb containing :
require "a_gem"
class AClass
include AnInclude
def method1
end
end
Keywords :
Terse Ruby will look through the supplied files and convert certain keywords at the start of lines :
c -> class
m -> module
r -> require (and will wrap the required item in " " if needed)
i -> include
d -> def
e -> end (method, class & module ends will be added if a subsequent method, class or module is detected, or is end-of-file)
a -> attr_accessor (and prefixes the variable name with : to make it a symbol)
r -> attr_reader (and prefixes the variable name with : to make it a symbol)
w -> attr_writer (and prefixes the variable name with : to make it a symbol)
All remaining text in the line is not altered, even if a matching keyword is present, because the keywords need to be at the beginning of the line (ignoring leading whitespace)
Flags :
v : verbose mode
o : overwrite - if the new file already exists, the existing file will be overwritten
Invokation :
terse_ruby can be directly invoked from the command-line with :
ruby -e "require 'terse_ruby'; TerseRuby.scan_files ARGV" [one or more files] [flags]
e.g.
ruby -e "require 'terse_ruby'; TerseRuby.scan_files ARGV" terse_file1.txt terse_file2.txt -o -v
Alternatively, the below two lines are all you need to run terse_ruby within your own Ruby file :
require "terse_ruby"
# (optionally add to ARGV here)
TerseRuby.scan_files ARGV
If ARGV have not been supplied, you'll need to add your args to ARGV, e.g. ARGV << "-v"; ARGV << "terse_file.txt"
Note that ARGV is not any ordinary array; terse_ruby uses the 'argv' gem which adds methods to the ARGV object;
therefore we must supply the ARGV object to TerseRuby.scan_files
Terse Java
Invoke in the same way as TerseRuby, but instead using the module name TerseJava; e.g.
ruby -e "require 'terse_ruby'; TerseRuby.scan_files ARGV" [one or more files] [flags]
or
TerseJava.scan_files ARGV
Keywords :
imp -> import
pk -> package
c -> class
impl -> implements
ex -> extends
int -> interface
ab -> abstract
e -> enum
st -> static
v -> void
m -> main
p -> public
pt -> protected
pv -> private
r -> return
s -> String
i -> Integer
b -> Boolean
f -> Float
fn -> final
Flags :
The same flags may be used as with Terse Ruby
Notes :
Constructors will not be made, as it is impossble to 100% accurately distinguish between a variable and a method in terse form.
Getters and setters will not be made, as it is impossble to 100% accurately distinguish between a variable and a method in terse form.
This is acceptable, as most IDEs are able to generate constructors and getters-and-setters.
Primitive types (int, float, etc.) will never be used; i -> Integer, f -> Float, etc.
Obvious class-beginnings will be given { (and } at the end of the file); obvious method endings (i.e. the 'return' keyword) will be given }
Because in terse form, there is ambiguity between methods and variables, some method starts will not gain { and some regular code lines will not gain ;
You should expect Java expanded from terse-form to contain compilation errors of this kind.