Class: VBSMin
Overview
Global VBSmin class
Constant Summary
Constants included from Version
Instance Attribute Summary collapse
-
#diff_size ⇒ Integer
readonly
Saved size (in bytes).
-
#input_size ⇒ Integer
readonly
Size (in bytes) of the original file.
-
#min_filepath ⇒ String
readonly
Path of the minified file.
-
#original_filepath ⇒ String
readonly
Path of the original file.
-
#output_size ⇒ Integer
readonly
Size (in bytes) of the minified file.
Instance Method Summary collapse
-
#initialize ⇒ VBSMin
constructor
Instantiate a VBSmin object.
-
#minify(filepath) ⇒ String
Minify a VBScript file (make a minified copy: file.min.vbs).
Constructor Details
#initialize ⇒ VBSMin
Instantiate a VBSmin object
29 30 31 32 33 34 35 |
# File 'lib/vbsmin.rb', line 29 def initialize @input_size = nil @output_size = nil @diff_size = nil @original_filepath = nil @min_filepath = nil end |
Instance Attribute Details
#diff_size ⇒ Integer (readonly)
Returns Saved size (in bytes).
20 21 22 |
# File 'lib/vbsmin.rb', line 20 def diff_size @diff_size end |
#input_size ⇒ Integer (readonly)
Returns Size (in bytes) of the original file.
14 15 16 |
# File 'lib/vbsmin.rb', line 14 def input_size @input_size end |
#min_filepath ⇒ String (readonly)
Returns Path of the minified file.
26 27 28 |
# File 'lib/vbsmin.rb', line 26 def min_filepath @min_filepath end |
#original_filepath ⇒ String (readonly)
Returns Path of the original file.
23 24 25 |
# File 'lib/vbsmin.rb', line 23 def original_filepath @original_filepath end |
#output_size ⇒ Integer (readonly)
Returns Size (in bytes) of the minified file.
17 18 19 |
# File 'lib/vbsmin.rb', line 17 def output_size @output_size end |
Instance Method Details
#minify(filepath) ⇒ String
Minify a VBScript file (make a minified copy: file.min.vbs)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vbsmin.rb', line 40 def minify(filepath) @original_filepath = filepath # Count number of line of input input_lines = File.readlines(filepath).length # File streaming File.open(min_ext, 'w') do |output| File.foreach(filepath).with_index(1) do |line, i| eol = ':' # End of file char # Remove inline comment (must be before whitespace striping) line = inline_comment(line) # Remove leading and trailing whitespaces: null, horizontal tab, line feed, # vertical tab, form feed, carriage return, space line.strip! # Remove comments except inline ones (must be after whitespace striping) line = '' if /^(?:'|REM\b)/i =~ line # Remove space when several spaces between two keywords line = internal_space(line) # Remove line splitting line[-1] = '' && eol = '' if line[-2..] == ' _' # Write processed line unless it is a blank line or the last line unless line.empty? output.write(line) output.write(eol) unless i == input_lines end end end calc_size return @min_filepath end |