Class: OJAgent::HDOJAgent
Constant Summary collapse
- @@selector =
'#fixed_table table.table_text tr'- @@thead =
[:id, :date, :status, :pid, :time, :mem, :length, :lang, :user]
Constants included from OJAgent
Instance Method Summary collapse
-
#initialize ⇒ HDOJAgent
constructor
A new instance of HDOJAgent.
- #login(user, pass) ⇒ Object
- #status(pid) ⇒ Object
- #submit(pid, code, lang) ⇒ Object
Methods included from OJAgent
Constructor Details
#initialize ⇒ HDOJAgent
Returns a new instance of HDOJAgent.
3 4 5 6 7 8 9 10 11 |
# File 'lib/ojagent/hdoj_agent.rb', line 3 def initialize super 'http://acm.hdu.edu.cn', :cpp => 0, :c => 1, :mscpp => 2, :msc => 3, :pascal => 4, :java => 5 end |
Instance Method Details
#login(user, pass) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ojagent/hdoj_agent.rb', line 13 def login(user, pass) @user = user page = get '/' login_form = page.form_with :action => '/userloginex.php?action=login' login_form.set_fields :username => user, :userpass => pass login_form.submit end |
#status(pid) ⇒ Object
35 36 37 38 39 |
# File 'lib/ojagent/hdoj_agent.rb', line 35 def status(pid) parse_status '/status.php?user=' + user, @@selector, @@thead do |tr| tr[3] && tr[3].inner_text == pid end end |
#submit(pid, code, lang) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/ojagent/hdoj_agent.rb', line 22 def submit(pid, code, lang) page = get '/submit.php' submit_form = page.form_with :action => './submit.php?action=submit' submit_form.set_fields :problemid => pid, :language => languages[lang], :usercode => code submit_form.submit pid.to_s end |