poj_org 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +1,34 @@
1
1
  require 'net/http'
2
2
 
3
3
  class PojOrg
4
- @@user = nil
5
- @@password = nil
6
- @@authenticated = false
4
+ @@user = nil
5
+ @@password = nil
6
+ @@authenticated = false
7
7
 
8
- def self.authenticate(user, password)
9
- if login(user, password)
10
- @@user = user
11
- @@password = password
12
- @@authenticated = true
13
- else
14
- @@authenticated = false
15
- end
8
+ def self.authenticate(user, password)
9
+ if login(user, password)
10
+ @@user = user
11
+ @@password = password
12
+ @@authenticated = true
13
+ else
14
+ @@authenticated = false
16
15
  end
16
+ end
17
17
 
18
- def self.authenticated?
19
- @@authenticated
20
- end
18
+ def self.authenticated?
19
+ @@authenticated
20
+ end
21
21
 
22
- private
22
+ private
23
23
 
24
- def self.login(user = nil, password = nil)
25
- login = Net::HTTP.post_form(
26
- URI('http://poj.org/login'),
27
- 'user_id1' => user || @@user,
28
- 'password1' => password || @@password
29
- )
30
- login.body['failed'] ? false : login['set-cookie']
31
- end
24
+ def self.login(user = nil, password = nil)
25
+ login = Net::HTTP.post_form(
26
+ URI('http://poj.org/login'),
27
+ 'user_id1' => user || @@user,
28
+ 'password1' => password || @@password
29
+ )
30
+ login.body['failed'] ? false : login['set-cookie']
31
+ end
32
32
  end
33
33
 
34
34
  require 'poj_org/problem'
@@ -1,18 +1,18 @@
1
1
  class PojOrg::Problem
2
- def initialize(id)
3
- @id = id
4
- end
2
+ def initialize(id)
3
+ @id = id
4
+ end
5
5
 
6
- def url
7
- "http://poj.org/problem?id=#{@id}"
8
- end
6
+ def url
7
+ "http://poj.org/problem?id=#{@id}"
8
+ end
9
9
 
10
- def details
11
- html = Net::HTTP.get(URI(url))
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
- }
17
- end
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
+ }
17
+ end
18
18
  end
@@ -1,20 +1,25 @@
1
+ require 'open-uri'
1
2
  require 'cgi'
2
3
 
3
4
  class PojOrg::Source
4
- def initialize(id)
5
- @id = id
6
- end
5
+ def initialize(id)
6
+ @id = id
7
+ end
7
8
 
8
- def details
9
- return nil unless PojOrg::authenticated?
10
- cookie = PojOrg::login
11
- showsource = Net::HTTP.new('poj.org').get("/showsource?solution_id=#{@id}", {'Cookie' => cookie})
12
- details = {
13
- :user => (/<td><b>User:.+?<a.+?>(.+?)<\/a><\/td>/).match(showsource.body)[1],
14
- :time_in_ms => (/<td><b>Time:.+?(\d+)MS<\/td>/).match(showsource.body)[1].to_i,
15
- :memory_in_kb => (/<td><b>Memory:.+?(\d+)K<\/td>/).match(showsource.body)[1].to_i,
16
- :language => (/<td><b>Language:<\/b>\s*(.+?)<\/td>/).match(showsource.body)[1],
17
- :source => CGI.unescapeHTML((/<pre.+?>(.+)<\/pre>/m).match(showsource.body)[1])
18
- }
19
- end
9
+ def url
10
+ "http://poj.org/showsource?solution_id=#{@id}"
11
+ end
12
+
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
+ }
24
+ end
20
25
  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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Fetch details of problem of source code from poj.org
15
15
  email: pinepara@gmail.com
@@ -20,7 +20,7 @@ files:
20
20
  - lib/poj_org.rb
21
21
  - lib/poj_org/problem.rb
22
22
  - lib/poj_org/source.rb
23
- homepage: http://rubygems.org/gems/poj_org
23
+ homepage: https://github.com/pinepara/poj_org
24
24
  licenses: []
25
25
  post_install_message:
26
26
  rdoc_options: []