Class: OJAgent::RosalindAgent

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

Constant Summary collapse

@@close =
"\xc3\x97".force_encoding('utf-8')

Constants included from OJAgent

StandardAgents, VERSION

Instance Method Summary collapse

Methods included from OJAgent

all

Constructor Details

#initialize ⇒ RosalindAgent

Returns a new instance of RosalindAgent.



3
4
5
# File 'lib/ojagent/rosalind_agent.rb', line 3

def initialize
  super 'http://rosalind.info'
end

Instance Method Details

#login(user, pass) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/ojagent/rosalind_agent.rb', line 7

def (user, pass)
  @user = user
  page = get '/accounts/login/'
   = page.form_with :id => 'id_form_login'
  .set_fields :username => user,
                        :password => pass
  .submit
end

#open(pid) ⇒ Object



16
17
18
# File 'lib/ojagent/rosalind_agent.rb', line 16

def open(pid)
  get "/problems/#{pid}/dataset/"
end

#status(page) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ojagent/rosalind_agent.rb', line 30

def status(page)
  status = {}
  [:error, :warning, :info, :success].each do |type|
    messages = []
    (page / "div.main div.alert-#{type}.flash-message").each do |alert|
      message = alert.inner_text.strip.gsub(@@close, '').gsub(/\s+/, ' ')
      messages << message unless message.empty?
    end
    status[type] = messages unless messages.empty?
  end
  status[:status] = status[:success] && !status[:error] ? 'Correct' : 'Wrong'
  status
end

#submit(pid, ans, src = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/ojagent/rosalind_agent.rb', line 20

def submit(pid, ans, src = nil)
  page = get "/problems/#{pid}/"
  submit_form = page.form_with :id => 'id_form_submission'
  submit_form.file_upload_with(:name => 'output_file').file = ans
  submit_form.file_upload_with(:name => 'code').file = src if src
  submit_form.submit
end