Class: CssConvertor::Command

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

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Command

Returns a new instance of Command.



3
4
5
# File 'lib/css_convertor/command.rb', line 3

def initialize(filepath)
  @filepath = filepath
end

Instance Method Details

#convertObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/css_convertor/command.rb', line 9

def convert
  css = ''

  puts CssConvertor.style("\nOpening file..", :color=>:yellow)
  File.open(@filepath, 'r') {|f| css = f.read}
  puts CssConvertor.style("Opening file..OK", :color=>:green)

  puts CssConvertor.style("\nScanning and replacing..", :color=>:yellow)
  css = CssConvertor.replace(css)
  puts CssConvertor.style("Scanning and replacing..OK", :color=>:green)

  puts CssConvertor.style("\nWriting to new file..", :color=>:yellow)
  new_filename = rtl_filename
  File.open(new_filename, 'w') {|f| f << css}
  puts CssConvertor.style("Writing to new file..OK", :color=>:green)
  puts CssConvertor.style("\nDONE. Check: #{new_filename}", 
                         :color=>:green, :bold=>true)
rescue Exception => e
  puts CssConvertor.style("\nTerminating because of these errors:", :color=>:red)
  puts CssConvertor.style(e.message, :color=>:red)
  puts e.backtrace
end

#rtl_filenameObject



6
7
8
# File 'lib/css_convertor/command.rb', line 6

def rtl_filename
  @filepath.gsub(/(.*?).css/) {"#{$1}-rtl.css"}
end