Class: AtcoderGreedy::Contest
- Inherits:
-
Object
- Object
- AtcoderGreedy::Contest
- Defined in:
- lib/atcoder_greedy/command/create.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #create_contest_problem_urls(contest_name) ⇒ Object
- #create_contest_url(contest_name) ⇒ Object
- #create_directories ⇒ Object
- #create_templates ⇒ Object
-
#initialize(name) ⇒ Contest
constructor
A new instance of Contest.
Constructor Details
#initialize(name) ⇒ Contest
Returns a new instance of Contest.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/atcoder_greedy/command/create.rb', line 20 def initialize(name) @name = name puts "Create #{name} contest files" @base_url = create_contest_url(name) puts "Contest url is #{@base_url}" @problem_urls = create_contest_problem_urls(name) puts 'Create directories' create_directories create_templates puts 'Set up done.' end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
18 19 20 |
# File 'lib/atcoder_greedy/command/create.rb', line 18 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
18 19 20 |
# File 'lib/atcoder_greedy/command/create.rb', line 18 def url @url end |
Instance Method Details
#create_contest_problem_urls(contest_name) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/atcoder_greedy/command/create.rb', line 36 def create_contest_problem_urls(contest_name) urls = [] if (contest_name.include?('abc') && contest_name[3..5].to_i > 19) || (contest_name.include?('arc') && contest_name[3..5].to_i > 34) task_num = %w(a b c d) else task_num = %w(1 2 3 4) end 4.times do |i| urls.push(name: "#{PROBLEM_NAMES[i]}", path: @base_url + "/tasks/#{contest_name}_#{task_num[i]}") end urls end |
#create_contest_url(contest_name) ⇒ Object
32 33 34 |
# File 'lib/atcoder_greedy/command/create.rb', line 32 def create_contest_url(contest_name) 'http://' + contest_name + '.contest.atcoder.jp' end |
#create_directories ⇒ Object
86 87 88 89 |
# File 'lib/atcoder_greedy/command/create.rb', line 86 def create_directories # コンテストディレクトリ作成 FileUtils.mkdir(@name) end |
#create_templates ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/atcoder_greedy/command/create.rb', line 51 def create_templates @problem_urls.each_with_index do |url, pro_i| problem_dir = "./#{@name}" # urlからインプット、アウトプットパラメータをとってきてファイルにしまう charset = nil html = open(url[:path]) do |f| charset = f.charset f.read end doc = Nokogiri::HTML.parse(html, nil, charset) in_file = File.new(problem_dir + "/input_#{PROBLEM_NAMES[pro_i]}.txt", 'w') params = doc.xpath('//pre') params.shift params.each_with_index do |p, i| if i % 2 == 0 in_file.puts "-- Example #{i/2}" in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}" else in_file.puts "-- Answer #{(i-1)/2}" in_file.puts "#{p.text.gsub(/\r\n?/, "\n").strip}" end end in_file.close solve_file_content = SOLVE_TEMPLATE.clone solve_file_content.gsub!(/CONTEST/, @name.upcase) solve_file_content.gsub!(/PROBLEM/, url[:name].upcase) solve_file = File.new(problem_dir + "/#{url[:name]}.rb", 'w') solve_file.print solve_file_content solve_file.close end end |