Class: Format

Inherits:
Object
  • Object
show all
Defined in:
lib/format.rb

Overview

Allows for C-like source code to be formatted using several popular bracketing styles.

Author:

  • Arcterus

Version:

  • 2012-09-11

Class Method Summary collapse

Class Method Details

.ALLMANInteger

Allman bracketing style

Returns:

  • (Integer)

    the number designating the Allman bracketing style



166
167
168
# File 'lib/format.rb', line 166

def self.ALLMAN
    1
end

.format(file, options = {}) ⇒ Object

Formats the input file according to the input options.

Parameters:

  • file (String)

    the input file name

  • options (Hash) (defaults to: {})

    the options that determine what is to happen to the input file



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/format.rb', line 223

def self.format(file, options={})
    indent = options[:indentation]
    if indent == nil then
        indent = '    '
    end
    output = nil
    case options[:style]
    when self.ALLMAN
        output = File.new(file + '.allman', 'w+')
        self.allman(file, output, indent)
    when self.UNIX
        output = File.new(file + '.unix', 'w+')
        self.unix(file, output, indent)
    when self.JAVA
        output = File.new(file + '.sun', 'w+')
        self.java(file, output, indent)
    else
        puts 'Defaulting to Java style formatting...'
        output = File.new(file + '.sun', 'w+')
        self.java(file, output, indent)
    end
    output.close
end

.JAVAInteger

Java bracketing style

Returns:

  • (Integer)

    the number designating the Java bracketing style



186
187
188
# File 'lib/format.rb', line 186

def self.JAVA
    3
end

.SUNObject



193
194
195
# File 'lib/format.rb', line 193

def self.SUN
    self.JAVA
end

.UNIXInteger

UNIX bracketing style

Returns:

  • (Integer)

    the number designating the UNIX bracketing style



176
177
178
# File 'lib/format.rb', line 176

def self.UNIX
    2
end

.VERSIONString

Gives the current version of format.

Returns:

  • (String)

    the version of format



206
207
208
209
210
211
212
# File 'lib/format.rb', line 206

def self.VERSION
    if @@version == nil then
        file = File.dirname(__FILE__) + '/../VERSION'
        @@version = File.exists?(file) ? File.read(file) : ''
    end
    @@version
end

.WHITESMITHObject



197
198
199
# File 'lib/format.rb', line 197

def self.WHITESMITH
    4
end