Class: Clicoder::AtCoder

Inherits:
SiteBase show all
Defined in:
lib/clicoder/sites/atcoder.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(contest_id, task_id) ⇒ AtCoder

Returns a new instance of AtCoder.



9
10
11
12
13
14
# File 'lib/clicoder/sites/atcoder.rb', line 9

def initialize(contest_id, task_id)
  config.local['contest_id'] = contest_id
  config.local['task_id'] = task_id
  @contest_id = contest_id
  @task_id = task_id
end

Instance Method Details

#description_xpathObject



50
51
52
# File 'lib/clicoder/sites/atcoder.rb', line 50

def description_xpath
  '//div[@id="task-statement"]'
end

#inputs_xpathObject



54
55
56
# File 'lib/clicoder/sites/atcoder.rb', line 54

def inputs_xpath
  '//pre[preceding-sibling::h3[1][contains(text(), "入力例")]]'
end

#loginObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/clicoder/sites/atcoder.rb', line 30

def 
  Mechanize.start do |m|
     = m.get("http://#{@contest_id}.contest.atcoder.jp/login")
    contest_home_page = .form_with(action: '/login') do |f|
      f.field_with(name: 'name').value = config.get('atcoder', 'user_id')
      f.field_with(name: 'password').value = config.get('atcoder', 'password')
    end.click_button

    yield m, contest_home_page
  end
end

#open_submissionObject



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

def open_submission
  Launchy.open("http://#{@contest_id}.contest.atcoder.jp/submissions/me")
end

#outputs_xpathObject



58
59
60
# File 'lib/clicoder/sites/atcoder.rb', line 58

def outputs_xpath
  '//pre[preceding-sibling::h3[1][contains(text(), "出力例")]]'
end

#problem_urlObject



46
47
48
# File 'lib/clicoder/sites/atcoder.rb', line 46

def problem_url
  "http://#{@contest_id}.contest.atcoder.jp/tasks/#{@task_id}"
end

#site_nameObject



42
43
44
# File 'lib/clicoder/sites/atcoder.rb', line 42

def site_name
  'atcoder'
end

#submitObject



16
17
18
19
20
21
22
23
24
# File 'lib/clicoder/sites/atcoder.rb', line 16

def submit
   do |mechanize, contest_page|
    problem_page = mechanize.get(problem_url)
    submit_page = problem_page.link_with(href: /submit/).click
    submit_page.form_with(action: /submit/) do |f|
      f.field_with(name: 'source_code').value = File.read(detect_main)
    end.click_button
  end
end

#working_directoryObject



62
63
64
# File 'lib/clicoder/sites/atcoder.rb', line 62

def working_directory
  @task_id
end