Here is the code so far:
require 'rubygems'
require 'fastercsv'
require 'highline/import'
def ukquotes(the_string)
#RTF specific: converting double to single quotes
the_string.gsub! /\‘d2(.*)\‘d3/m, “\'d4$1\'d5”
the_string.gsub! /(\W)’/, “$1\'d4”
the_string.gsub! /’(\W)/, “\'d5$1”
the_string.gsub! /(\W)d"/, “$1\'d4”
the_string.gsub! /"(\W)/, “\'d5$1”
the_string.gsub! /(\w)’(\w)/, “$1\'d5$2”
end
def ukspell(the_string)
#Converting US to UK spelling
csvdata=File.open(“UK-US_spellingdiff.csv”, “r”)
FasterCSV.parse(csvdata) do |row|
usword, ukword = *row
the_string.gsub! /\b#{usword}\b/, ‘\b#{ukword}\b’
end
end
unless File.exists?(“UK-US_spellingdiff.csv”)
raise “CSV file does not exist”
break
end
if agree(“You are about to perform this edit list on #{Dir.pwd}.
Proceed?”, true)
directory = ask("Name of directory to write edited files to? ",
lambda{|q| q.gsub /\W/, ‘_’})
else
break
end
unless agree(“Will write to:#{Dir.pwd}/#{directory}. Proceed?”, true)
break
end
Dir.mkdir("#{Dir.pwd}/#{directory}")
Dir.glob("*.rtf").each do |filename|
newfile = File.open(filename, “r”){|f| f.read}.ukquotes.ukspell
newfilename = “CT_CW_”+ filename
File.open(directory/newfilename, “w”){|n| puts(newfile)}
end
Produces this error message:
cw-replace.rb:44: private method `ukquotes' called for
# (NoMethodError)
from cw-replace.rb:43:in `each'