Class: Clicoder::AOJ

Inherits:
SiteBase show all
Defined in:
lib/clicoder/sites/aoj.rb

Instance Method Summary collapse

Methods inherited from SiteBase

#config, #copy_makefile, #copy_template, #download_description, #download_inputs, #download_outputs, #fetch_description, #fetch_inputs, #fetch_outputs, new_with_config, #prepare_directories, #start, #store_local_config, #xml_document

Methods included from Helper

#detect_main, #ext_to_language_name

Constructor Details

#initialize(problem_number) ⇒ AOJ

Returns a new instance of AOJ.



7
8
9
10
# File 'lib/clicoder/sites/aoj.rb', line 7

def initialize(problem_number)
  config.local['problem_number'] = problem_number
  @problem_id = "%04d" % problem_number
end

Instance Method Details

#description_xpathObject



43
44
45
# File 'lib/clicoder/sites/aoj.rb', line 43

def description_xpath
  '//div[@class="description"]'
end

#inputs_xpathObject



47
48
49
# File 'lib/clicoder/sites/aoj.rb', line 47

def inputs_xpath
  '//*[self::pre or self::div/pre][preceding-sibling::*[self::h2 or self::h3][1][text()="Sample Input"]]'
end

#loginObject



30
31
32
33
# File 'lib/clicoder/sites/aoj.rb', line 30

def 
  # no need to login for now
  yield
end

#open_submissionObject



26
27
28
# File 'lib/clicoder/sites/aoj.rb', line 26

def open_submission
  Launchy.open('http://judge.u-aizu.ac.jp/onlinejudge/status.jsp')
end

#outputs_xpathObject



51
52
53
# File 'lib/clicoder/sites/aoj.rb', line 51

def outputs_xpath
  '//*[self::pre or self::div/pre][preceding-sibling::*[self::h2 or self::h3][text()="Output for the Sample Input"]]'
end

#problem_urlObject



39
40
41
# File 'lib/clicoder/sites/aoj.rb', line 39

def problem_url
  "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=#{@problem_id}"
end

#site_nameObject



35
36
37
# File 'lib/clicoder/sites/aoj.rb', line 35

def site_name
  'aoj'
end

#submitObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/clicoder/sites/aoj.rb', line 12

def submit
  submit_url = 'http://judge.u-aizu.ac.jp/onlinejudge/servlet/Submit'
  post_params = {
    userID: config.get('aoj', 'user_id'),
    password: config.get('aoj', 'password'),
    problemNO: @problem_id,
    language: ext_to_language_name(File.extname(detect_main)),
    sourceCode: File.read(detect_main),
    submit: 'Send'
  }
  response = Net::HTTP.post_form(URI(submit_url), post_params)
  return response.body !~ /UserID or Password is Wrong/
end

#working_directoryObject



55
56
57
# File 'lib/clicoder/sites/aoj.rb', line 55

def working_directory
  @problem_id
end