Class: PojOrg::Code
- Inherits:
-
Object
- Object
- PojOrg::Code
- Defined in:
- lib/poj_org/code.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#length_in_byte ⇒ Object
readonly
Returns the value of attribute length_in_byte.
-
#memory_in_kb ⇒ Object
readonly
Returns the value of attribute memory_in_kb.
-
#problem_id ⇒ Object
readonly
Returns the value of attribute problem_id.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#submitted_at ⇒ Object
readonly
Returns the value of attribute submitted_at.
-
#time_in_ms ⇒ Object
readonly
Returns the value of attribute time_in_ms.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #fetch_content(password) ⇒ Object
-
#initialize(id) ⇒ Code
constructor
A new instance of Code.
- #url ⇒ Object
Constructor Details
#initialize(id) ⇒ Code
Returns a new instance of Code.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/poj_org/code.rb', line 11 def initialize(id) @id = id html = Nokogiri::HTML(open("http://poj.org/status?top=#{@id+1}")) raise PojOrg::Errors::CodeNotFound if html.xpath('/html/body/table[2]/tr[2]/td[1]').text.to_i != @id @username = html.xpath('/html/body/table[2]/tr[2]/td[2]').text @problem_id = html.xpath('/html/body/table[2]/tr[2]/td[3]').text.to_i @result = html.xpath('/html/body/table[2]/tr[2]/td[4]').text @memory_in_kb = html.xpath('/html/body/table[2]/tr[2]/td[5]').text.to_i @time_in_ms = html.xpath('/html/body/table[2]/tr[2]/td[6]').text.to_i @language = html.xpath('/html/body/table[2]/tr[2]/td[7]').text @length_in_byte = html.xpath('/html/body/table[2]/tr[2]/td[8]').text.to_i @submitted_at = html.xpath('/html/body/table[2]/tr[2]/td[9]').text end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def content @content end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def id @id end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def language @language end |
#length_in_byte ⇒ Object (readonly)
Returns the value of attribute length_in_byte.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def length_in_byte @length_in_byte end |
#memory_in_kb ⇒ Object (readonly)
Returns the value of attribute memory_in_kb.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def memory_in_kb @memory_in_kb end |
#problem_id ⇒ Object (readonly)
Returns the value of attribute problem_id.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def problem_id @problem_id end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def result @result end |
#submitted_at ⇒ Object (readonly)
Returns the value of attribute submitted_at.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def submitted_at @submitted_at end |
#time_in_ms ⇒ Object (readonly)
Returns the value of attribute time_in_ms.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def time_in_ms @time_in_ms end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
9 10 11 |
# File 'lib/poj_org/code.rb', line 9 def username @username end |
Instance Method Details
#fetch_content(password) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/poj_org/code.rb', line 29 def fetch_content(password) PojOrg::User.new(username, password).login do || html = Nokogiri::HTML(open(url, 'Cookie' => )) if html.xpath('/html/head/title').text == 'Error' raise PojOrg::Errors::CodeNotFound if html.xpath('/html/body/ul/li').text.include?('No such solution') raise PojOrg::Errors::AccessDenied if html.xpath('/html/body/ul/li').text.include?('Source request declined') raise PojOrg::Errors::Error end @content = html.xpath('/html/body/pre').text end end |
#url ⇒ Object
25 26 27 |
# File 'lib/poj_org/code.rb', line 25 def url "http://poj.org/showsource?solution_id=#{id}" end |