The Accidental Rubyist

invalid byte sequence in UTF-8

ecto script: inter.rb

leave a comment »

To learn how to do hyperlinking with inter.rb see this.

#!/usr/bin/env ruby
file = ARGV[0];
text = File.open(file,"r").readlines.join;
urlmap = {"w" => "http://en.wikipedia.org/wiki/%s",
"g" => "http://google.com/search?q=%s",
"dict" => "http://m-w.com/dictionary/%s",
"http" => "http:%s",
"th" => "http://thesaurus.reference.com/search?q=%s"
}
text.gsub!(/\[\[(\w+?):(.+?)\]\]/) { |match|
path=urlmap[$1]
if path == nil then
puts "%s not found in urlmap" % $1
match
else
str = $2.split('|')
if str.size == 1 then
str %s') % [str[0], str[1]]
end
}
#puts text
File.open(file, "w").puts text;

Source of inter.rb (Escapes, i.e., \ or \, are disappearing despite all attempts to print them)

Advertisements

Written by totalrecall

February 28, 2007 at 7:00 pm

Posted in ecto, ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: