Class: PojOrg::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/poj_org/problem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Problem

Returns a new instance of Problem.



9
10
11
12
13
14
15
16
# File 'lib/poj_org/problem.rb', line 9

def initialize(id)
  @id = id
  html = Nokogiri::HTML(open(url))
  raise PojOrg::Errors::ProblemNotFound if html.xpath('/html/head/title').text == 'Error'
  @title              = html.xpath('/html/body/table[2]/tr/td/div[2]').text
  @time_limit_in_ms   = html.xpath('/html/body/table[2]/tr/td/div[3]/table/tr[1]/td[1]').text[/\d+/].to_i
  @memory_limit_in_kb = html.xpath('/html/body/table[2]/tr/td/div[3]/table/tr[1]/td[3]').text[/\d+/].to_i
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/poj_org/problem.rb', line 7

def id
  @id
end

#memory_limit_in_kbObject (readonly)

Returns the value of attribute memory_limit_in_kb.



7
8
9
# File 'lib/poj_org/problem.rb', line 7

def memory_limit_in_kb
  @memory_limit_in_kb
end

#time_limit_in_msObject (readonly)

Returns the value of attribute time_limit_in_ms.



7
8
9
# File 'lib/poj_org/problem.rb', line 7

def time_limit_in_ms
  @time_limit_in_ms
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/poj_org/problem.rb', line 7

def title
  @title
end

Instance Method Details

#urlObject



18
19
20
# File 'lib/poj_org/problem.rb', line 18

def url
  "http://poj.org/problem?id=#{id}"
end