Class: OJAgent::HDOJAgent

Inherits:
OJAgent
  • Object
show all
Defined in:
lib/ojagent/hdoj_agent.rb

Constant Summary collapse

@@selector =
'#fixed_table table.table_text tr'
@@thead =
[:id, :date, :status, :pid, :time, :mem, :length, :lang, :user]

Constants included from OJAgent

StandardAgents, VERSION

Instance Method Summary collapse

Methods included from OJAgent

all

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 (user, pass)
  @user = user
  page = get '/'
   = page.form_with :action => '/userloginex.php?action=login'
  .set_fields :username => user,
                        :userpass => pass
  .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