Module: ReplaceQuotes

Defined in:
lib/replace_quotes.rb,
lib/replace_quotes/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.update(path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/replace_quotes.rb', line 6

def self.update(path)
  return if StringInFile.present('"', path) != true
  path_old = path
  path_new = "#{path_old}.new"
  file_w = open(path_new, 'w')
  File.readlines(path_old).each do |line|
    single_quote = (line.include? "'")
    pound_cb = (line.include? '#{')
    if (single_quote == false) && (pound_cb == false)
      line_alt = line.tr('"', "'")
      file_w.write(line_alt)
    else
      file_w.write(line)
    end
  end
  file_w.close
  system("rm #{path_old}")
  system("mv #{path_new} #{path_old}")
end