Class: RHACK::Infoseek
Constant Summary collapse
- URI =
{:tr => 'http://translation.infoseek.co.jp/'}
Class Method Summary collapse
Instance Method Summary collapse
- #get_token(page) ⇒ Object
-
#initialize(frame = nil) ⇒ Infoseek
constructor
A new instance of Infoseek.
- #tr(text, direction = :from_ja, &block) ⇒ Object
Constructor Details
#initialize(frame = nil) ⇒ Infoseek
Returns a new instance of Infoseek.
158 159 160 |
# File 'lib/rhack/clients/examples.rb', line 158 def initialize frame=nil super :tr, frame, :eval => false end |
Class Method Details
.tr(*args, &block) ⇒ Object
182 |
# File 'lib/rhack/clients/examples.rb', line 182 def self.tr(*args, &block) new.tr *args, &block end |
Instance Method Details
#get_token(page) ⇒ Object
162 163 164 |
# File 'lib/rhack/clients/examples.rb', line 162 def get_token page @token = page.at('input[name=token]').value end |
#tr(text, direction = :from_ja, &block) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rhack/clients/examples.rb', line 166 def tr(text, direction=:from_ja, &block) if @token selector = direction.in([:from_ja, :from_jp, :to_en]) ? 1 : 0 body = {'ac' => 'Text', 'lng' => 'en', 'original' => text, 'selector' => selector, 'token' => @token, 'submit' => ' 翻訳'} @f.run(body, :proc_result => block) {|page| get_token page page.at('textarea[name=converted]').text }#.res else @f.run(:save_result => !block) {|page| get_token page tr text, direction, &block }#.res end end |