|
Prev: Slide Show (S9) Gem Now Includes S5 Support (Including Built-InGradient Themes)
Next: rainbow tables
From: Michael Lommel on 5 Jul 2008 13:24 Here is the code so far: <code> 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 </code> Produces this error message: <code> cw-replace.rb:44: private method `ukquotes' called for #<String:0x7755d8> (NoMethodError) from cw-replace.rb:43:in `each' </code> -- Posted via http://www.ruby-forum.com/.
From: Robert Klemme on 5 Jul 2008 13:32 On 05.07.2008 19:24, Michael Lommel wrote: > Here is the code so far: > > <code> > 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 ^^^ error line > newfilename = "CT_CW_"+ filename > File.open(directory/newfilename, "w"){|n| puts(newfile)} > end > </code> > > Produces this error message: > > <code> > cw-replace.rb:44: private method `ukquotes' called for > #<String:0x7755d8> (NoMethodError) > from cw-replace.rb:43:in `each' > </code> You're defining #ukquotes in main (like a global function) but you use it as an instance method. Either place it in class String or call it like a function. Cheers robert
From: Robert Klemme on 5 Jul 2008 13:32 On 05.07.2008 19:24, Michael Lommel wrote: > Here is the code so far: > > <code> > 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 ^^^ error line > newfilename = "CT_CW_"+ filename > File.open(directory/newfilename, "w"){|n| puts(newfile)} > end > </code> > > Produces this error message: > > <code> > cw-replace.rb:44: private method `ukquotes' called for > #<String:0x7755d8> (NoMethodError) > from cw-replace.rb:43:in `each' > </code> You're defining #ukquotes in main (like a global function) but you use it as an instance method. Either place it in class String or call it like a function. Cheers robert
From: Robert Klemme on 5 Jul 2008 13:33 On 05.07.2008 19:24, Michael Lommel wrote: > Here is the code so far: > > <code> > 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 ^^^ error line > newfilename = "CT_CW_"+ filename > File.open(directory/newfilename, "w"){|n| puts(newfile)} > end > </code> > > Produces this error message: > > <code> > cw-replace.rb:44: private method `ukquotes' called for > #<String:0x7755d8> (NoMethodError) > from cw-replace.rb:43:in `each' > </code> You're defining #ukquotes in main (like a global function) but you use it as an instance method. Either place it in class String or call it like a function. Cheers robert
From: Robert Klemme on 5 Jul 2008 13:33 On 05.07.2008 19:33, Robert Klemme wrote: Sorry for the noise. My newsreader fooled my. robert
|
Next
|
Last
Pages: 1 2 Prev: Slide Show (S9) Gem Now Includes S5 Support (Including Built-InGradient Themes) Next: rainbow tables |