codeforcesapi 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODk3ZjcxY2VhNmYzODI5OWRkZjZlN2FhNTg3ZTZiY2VjMWU5ZjBmZA==
5
+ data.tar.gz: !binary |-
6
+ MTExMGVlOWExZWU0NTlkMjAxNzUzMmZhNDk1ZGYxZDA5YzJhZmY2MA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YjI0MTljNzQ2YjVjYmNlOGQwODgzMmE0MWI0ZjI4YmZhM2I3ZmVhZjRmMTg3
10
+ MTJhNmY1YWE4OWVhOTRlMjNiODUzNDdlNDY4Y2Q1YjgyZGMwZDVkODI3Zjlh
11
+ YzJlYzAyNWU5OWM2NWI0YmE2YmNjNmFlNWExZWRhMTRjODU2Yjc=
12
+ data.tar.gz: !binary |-
13
+ Mzg1NTM3ZTg0ZTA2YTMxOGIzMTYyNzQzZmM5YWM1ODU0YjliMGM0MmRlYjli
14
+ YmMwMDY5ZTk3YjcyY2JkZmU3YWNmMjMyNGU2Y2QwNjhjMTgyMTk1MzMxZDE4
15
+ MTU2YzVhY2IzNGE3MjgxMTJjMDFjMWU3YjBkYmE4YmIzZWUyNjg=
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.10.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codeforcesapi.gemspec
4
+ gemspec
5
+ gem 'nokogiri'
6
+ gem 'json'
7
+
@@ -0,0 +1,36 @@
1
+ # Codeforcesapi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codeforcesapi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'codeforcesapi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install codeforcesapi
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codeforcesapi.
36
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "codeforcesapi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'codeforcesapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "codeforcesapi"
8
+ spec.version = Codeforcesapi::VERSION
9
+ spec.authors = ["windinhishair"]
10
+ spec.email = ["xibaiyu@msn.com"]
11
+
12
+ spec.summary = %q{ruby wrapper for codeforces api }
13
+ spec.description = %q{ruby wrapper for codeforces api }
14
+ spec.homepage = "https://github.com/WindInHisHair/codeforcesap"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "http://rubygems.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ end
@@ -0,0 +1,16 @@
1
+ require "codeforcesapi/version"
2
+ require_relative "codeforcesapi/CForces.rb"
3
+
4
+
5
+ module Codeforcesapi
6
+ # Your code goes here...
7
+ #
8
+ #
9
+ def self.problem(contestID, problemIndex)
10
+ CForces::Problem.new(contestID, problemIndex)
11
+ end
12
+
13
+ def self.user(u)
14
+ CForces::User.new(u)
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+
5
+ module CForces
6
+ class User
7
+
8
+ attr :name, :rank, :rating
9
+
10
+ def initialize(user)
11
+ @url = 'https://codeforces.com/api/user.info?handles='+user
12
+
13
+ @user = JSON.parse(open(@url).read)
14
+
15
+ if @user['status'] == 'OK'
16
+ @rank = @user['result'].first['rank']
17
+ @rating = @user['result'].first['rating']
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'json'
4
+ require_relative './API/user.rb'
5
+
6
+ module CForces
7
+
8
+ class Problem
9
+
10
+ attr :preTestInputs, :preTestOutputs, :title, :contest_id, :problem_index
11
+
12
+ def loadURL(cid, pindex)
13
+ ['http://codeforces.com/contest/', '/problem/'].join(cid.to_s) + pindex.to_s
14
+ end
15
+
16
+ def initialize(cID, pindex)
17
+ @contest_id = cID.to_s
18
+ @problem_index = pindex
19
+
20
+ @url = loadURL(cID, pindex)
21
+ doc = Nokogiri::HTML(open(@url))
22
+
23
+ @preTestInputs = Array.new
24
+ @preTestOutputs = Array.new
25
+
26
+ doc.css('div.sample-test div.input').each do |e|
27
+ @preTestInputs << e.css('br').map{|item| item.previous.text}
28
+ end
29
+
30
+ doc.css('div.sample-test div.output').each do |e|
31
+ @preTestOutputs << e.css('br').map{|item| item.previous.text}
32
+ end
33
+
34
+ @title = doc.css('div.title')[0].text.delete('.').split.join '_'
35
+ end
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,3 @@
1
+ module Codeforcesapi
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codeforcesapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - windinhishair
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: ! 'ruby wrapper for codeforces api '
42
+ email:
43
+ - xibaiyu@msn.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - codeforcesapi.gemspec
56
+ - lib/codeforcesapi.rb
57
+ - lib/codeforcesapi/API/user.rb
58
+ - lib/codeforcesapi/CForces.rb
59
+ - lib/codeforcesapi/version.rb
60
+ homepage: https://github.com/WindInHisHair/codeforcesap
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: ruby wrapper for codeforces api
83
+ test_files: []