Class: Tranexp::Http
Constant Summary collapse
- PostURL =
"http://www.tranexp.com:2000/Translate/result.shtml"
Instance Method Summary collapse
-
#method_missing(meth, *args, &blk) ⇒ Object
Support calls like #from_nor_to_eng, or #from_eng_to_.
- #translate(text, from, to = "eng") ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
Support calls like #from_nor_to_eng, or #from_eng_to_
20 21 22 23 24 25 26 |
# File 'lib/tranexp/http.rb', line 20 def method_missing(meth, *args, &blk) if meth.to_s =~ /^from_([a-z]+)_to_([a-z]+)$/ from, to = $1, $2 return translate(args.first, from, to) end super end |
Instance Method Details
#translate(text, from, to = "eng") ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tranexp/http.rb', line 5 def translate(text, from, to="eng") @agent ||= WWW::Mechanize.new page = @agent.post(PostURL, { :from => from, :to => to, :text => text, :keyb => "non", "Submit.x" => 33, "Submit.y" => 9, :translation => "" }) clean_up page.forms[1]['translation'] end |