Class: OJAgent::RosalindAgent
- Defined in:
- lib/ojagent/rosalind_agent.rb
Constant Summary collapse
- @@close =
"\xc3\x97".force_encoding('utf-8')
Constants included from OJAgent
Instance Method Summary collapse
-
#initialize ⇒ RosalindAgent
constructor
A new instance of RosalindAgent.
- #login(user, pass) ⇒ Object
- #open(pid) ⇒ Object
- #status(page) ⇒ Object
- #submit(pid, ans, src = nil) ⇒ Object
Methods included from OJAgent
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 login(user, pass) @user = user page = get '/accounts/login/' login_form = page.form_with :id => 'id_form_login' login_form.set_fields :username => user, :password => pass login_form.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| = [] (page / "div.main div.alert-#{type}.flash-message").each do |alert| = alert.inner_text.strip.gsub(@@close, '').gsub(/\s+/, ' ') << unless .empty? end status[type] = unless .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 |