summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-08-13 16:20:52 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2010-08-13 16:20:52 +0200
commit9eef522553cb2de99388948dedf0cf5d698b635a (patch)
tree9944eda88d5fab3c290b68362624dc6b7b102e52 /data/rbot
parentf8f4f5909a45334ceac1b259a380e255b8e75357 (diff)
translator: support both pre-1.0 and post-1.0 Mechanize namespaces
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/translator.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/data/rbot/plugins/translator.rb b/data/rbot/plugins/translator.rb
index 2e7be919..66b70cee 100644
--- a/data/rbot/plugins/translator.rb
+++ b/data/rbot/plugins/translator.rb
@@ -39,6 +39,14 @@ class Translator
@cache = cache
end
+ # Many translators use Mechanize, which changed namespace around version 1.0
+ # To support both pre-1.0 and post-1.0 namespaces, we use these auxiliary
+ # method. The translator still needs to require 'mechanize' on initialization
+ # if it needs it.
+ def mechanize
+ return Mechanize if defined? Mechanize
+ return WWW::Mechanize
+ end
# whether the translator supports this direction
def support?(from, to)
@@ -113,7 +121,7 @@ class NiftyTranslator < Translator
end
def do_translate(text, from, to)
- @form ||= WWW::Mechanize.new.
+ @form ||= mechanize.new.
get('http://nifty.amikai.com/amitext/indexUTF8.jsp').
forms_with(:name => 'translateForm').last
@radio = @form.radiobuttons_with(:name => 'langpair').first
@@ -150,7 +158,7 @@ class ExciteTranslator < Translator
end
def open_form(name)
- WWW::Mechanize.new.get("http://www.excite.co.jp/world/#{name}").
+ mechanize.new.get("http://www.excite.co.jp/world/#{name}").
forms_with(:name => 'world').first
end
@@ -222,7 +230,7 @@ class BabelfishTranslator < Translator
end
def parse_page
- form = WWW::Mechanize.new.get('http://babelfish.altavista.com/babelfish/').
+ form = mechanize.new.get('http://babelfish.altavista.com/babelfish/').
forms_with(:name => 'frmTrText').first
lang_list = form.fields_with(:name => 'lp').first
[form, lang_list]