lib/acclir/at_coder/task.rb in acclir-0.1.0 vs lib/acclir/at_coder/task.rb in acclir-0.2.0
- old
+ new
@@ -1,17 +1,17 @@
# frozen_string_literal: true
-require "open-uri"
-require "nokogiri"
-
module Acclir
module AtCoder
# AtCoder problem
class Task
SAMPLE_INPUT_TITLE = "Sample Input"
SAMPLE_OUTPUT_TITLE = "Sample Output"
+ PATH_REGEX_PROC = ->(contest_id) { %r{^/contests/#{contest_id}/tasks/(?<task>\w+)$} }
+ PATH_PROC = ->(contest_id, id) { "/contests/#{contest_id}/tasks/#{id}" }
+
attr_reader :contest_id, :id
def initialize(contest_id, id)
@contest_id = contest_id
@id = id
@@ -21,15 +21,13 @@
@samples ||= extract_samples.map { |input, output| Sample.new(input, output) }
end
private
- def url
- @url ||= ATCODER_TASK_URL_PROC.call(contest_id, id)
- end
-
def document
- @document ||= Nokogiri::HTML(URI.parse(url).open)
+ @document ||= Nokogiri::HTML(
+ Connection.get(PATH_PROC.call(contest_id, id)).body
+ )
end
def extract_samples
extract_sample_inputs.zip(extract_sample_outputs)
end