poj_org 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,14 @@
1
1
  class PojOrg::Problem
2
- def initialize(id)
3
- @id = id
2
+ attr_accessor :id, :title, :time_limit_in_ms, :memory_limit_in_kb
3
+ def initialize(new_id)
4
+ self.id = new_id
5
+ html = open(url).read
6
+ self.title = html[/(?<=<div class="ptt" lang="en-US">).+?(?=<\/div>)/]
7
+ self.time_limit_in_ms = html[/(?<=<b>Time Limit:<\/b>)\s*\d+/].to_i
8
+ self.memory_limit_in_kb = html[/(?<=<b>Memory Limit:<\/b>)\s*\d+/].to_i
4
9
  end
5
10
 
6
11
  def url
7
- "http://poj.org/problem?id=#{@id}"
8
- end
9
-
10
- def details
11
- html = open(url).read
12
- details = {
13
- :title => html[/(?<=<div class="ptt" lang="en-US">).+?(?=<\/div>)/],
14
- :time_limit_in_ms => html[/(?<=<b>Time Limit:<\/b>)\s*\d+/].to_i,
15
- :memory_limit_in_kb => html[/(?<=<b>Memory Limit:<\/b>)\s*\d+/].to_i
16
- }
12
+ "http://poj.org/problem?id=#{id}"
17
13
  end
18
14
  end
@@ -2,24 +2,22 @@ require 'open-uri'
2
2
  require 'cgi'
3
3
 
4
4
  class PojOrg::Source
5
- def initialize(id)
6
- @id = id
7
- end
5
+ attr_accessor :id, :user, :time_in_ms, :memory_in_kb, :language, :source
8
6
 
9
- def url
10
- "http://poj.org/showsource?solution_id=#{@id}"
7
+ def initialize(new_id)
8
+ self.id = new_id
9
+ if PojOrg::authenticated?
10
+ cookie = PojOrg::login
11
+ html = open(url, 'Cookie' => cookie).read
12
+ self.user = (/<td><b>User:.+?<a.+?>(.+?)<\/a><\/td>/).match(html)[1]
13
+ self.time_in_ms = (/<td><b>Time:.+?(\d+)MS<\/td>/).match(html)[1].to_i
14
+ self.memory_in_kb = (/<td><b>Memory:.+?(\d+)K<\/td>/).match(html)[1].to_i
15
+ self.language = (/<td><b>Language:<\/b>\s*(.+?)<\/td>/).match(html)[1]
16
+ self.source = CGI.unescapeHTML((/<pre.+?>(.+)<\/pre>/m).match(html)[1])
17
+ end
11
18
  end
12
19
 
13
- def details
14
- return nil unless PojOrg::authenticated?
15
- cookie = PojOrg::login
16
- html = open(url, 'Cookie' => cookie).read
17
- details = {
18
- :user => (/<td><b>User:.+?<a.+?>(.+?)<\/a><\/td>/).match(html)[1],
19
- :time_in_ms => (/<td><b>Time:.+?(\d+)MS<\/td>/).match(html)[1].to_i,
20
- :memory_in_kb => (/<td><b>Memory:.+?(\d+)K<\/td>/).match(html)[1].to_i,
21
- :language => (/<td><b>Language:<\/b>\s*(.+?)<\/td>/).match(html)[1],
22
- :source => CGI.unescapeHTML((/<pre.+?>(.+)<\/pre>/m).match(html)[1])
23
- }
20
+ def url
21
+ "http://poj.org/showsource?solution_id=#{id}"
24
22
  end
25
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poj_org
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: