Class: CForces::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/codeforcesapi/CForces.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cID, pindex) ⇒ Problem

Returns a new instance of Problem.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/codeforcesapi/CForces.rb', line 16

def initialize(cID, pindex)
  @contest_id = cID.to_s
  @problem_index = pindex

  @url = loadURL(cID, pindex) 
  doc = Nokogiri::HTML(open(@url))
  
  @preTestInputs = Array.new
  @preTestOutputs  = Array.new

  doc.css('div.sample-test  div.input').each do |e|
    @preTestInputs << e.css('br').map{|item| item.previous.text}
  end

  doc.css('div.sample-test div.output').each do |e| 
    @preTestOutputs << e.css('br').map{|item| item.previous.text}
  end 

  @title = doc.css('div.title')[0].text.delete('.').split.join '_'
end

Instance Attribute Details

#contest_idObject (readonly)

Returns the value of attribute contest_id.



10
11
12
# File 'lib/codeforcesapi/CForces.rb', line 10

def contest_id
  @contest_id
end

#preTestInputsObject (readonly)

Returns the value of attribute preTestInputs.



10
11
12
# File 'lib/codeforcesapi/CForces.rb', line 10

def preTestInputs
  @preTestInputs
end

#preTestOutputsObject (readonly)

Returns the value of attribute preTestOutputs.



10
11
12
# File 'lib/codeforcesapi/CForces.rb', line 10

def preTestOutputs
  @preTestOutputs
end

#problem_indexObject (readonly)

Returns the value of attribute problem_index.



10
11
12
# File 'lib/codeforcesapi/CForces.rb', line 10

def problem_index
  @problem_index
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/codeforcesapi/CForces.rb', line 10

def title
  @title
end

Instance Method Details

#loadURL(cid, pindex) ⇒ Object



12
13
14
# File 'lib/codeforcesapi/CForces.rb', line 12

def loadURL(cid, pindex)
  ['http://codeforces.com/contest/', '/problem/'].join(cid.to_s) + pindex.to_s
end