class Tabs2spaces::Converter
Public Class Methods
new(folder, options)
click to toggle source
# File lib/tabs2spaces.rb, line 6 def initialize(folder, options) @folder = folder || "./" @options = options end
Public Instance Methods
convert()
click to toggle source
# File lib/tabs2spaces.rb, line 61 def convert if @options[:convertion].nil? simple_convert else convert_between end end
convert_between()
click to toggle source
# File lib/tabs2spaces.rb, line 53 def convert_between @options[:inversed] = true simple_convert @options[:inversed] = false @options[:number] = @options[:convertion] simple_convert end
file_expand(file)
click to toggle source
# File lib/tabs2spaces.rb, line 11 def file_expand(file) number = @options[:number] unless @options[:inversed] puts "Expanding tabs on: " + file return `expand -i -t #{number} #{file}` else puts "Unexpanding spaces on: " + file return `unexpand --first-only -t #{number} #{file}` end end
file_expand_and_write(file)
click to toggle source
# File lib/tabs2spaces.rb, line 34 def file_expand_and_write(file) file_write file, file_expand(file) end
file_write(file, data)
click to toggle source
# File lib/tabs2spaces.rb, line 22 def file_write(file, data) begin new_file = File.open(file, "w") do |f| f.puts data end rescue IOError => e puts e ensure new_file.close unless new_file == nil end end
folder_expand_and_write(folder)
click to toggle source
# File lib/tabs2spaces.rb, line 38 def folder_expand_and_write(folder) files = File.join(@folder, '**', @options[:pattern]) Dir.glob(files).each do |file| file_expand_and_write file end end
simple_convert()
click to toggle source
# File lib/tabs2spaces.rb, line 45 def simple_convert unless File.directory?(@folder) file_expand_and_write @folder else folder_expand_and_write(@folder) end end