tournament_organizer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rake_tasks~ +7 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/tournament_organizer +73 -0
- data/lib/tournament_organizer.rb +6 -0
- data/lib/tournament_organizer/tournament.rb +74 -0
- data/lib/tournament_organizer/version.rb +3 -0
- data/templates/default.html.erb +36 -0
- data/test.html +1417 -0
- data/tournament_organizer.gemspec +38 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ae0b65d391dc3831d68ab1d14e74cf007a8e34377193091b6dd3b329b8bff3f
|
4
|
+
data.tar.gz: 8986e485c052989d97d20f53ddd4f72093d533efcfd40392745e077c9b560766
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4903fbf01b176305e35ea532e6031ab4b9acbd562d2f715d2775a69bc77546b5fe1431d37dceb08e7d462f49991c4f61dda45710c5c3fa1ab3d66e40cc757a55
|
7
|
+
data.tar.gz: e20e79471acbb6d55c2dfdae031a443dadb257ab1d694e074838b8b72f72f0be0f5f799bd5a17055d201239f2d2254cc20396e44773dc803db38a8d0626dcd03
|
data/.gitignore
ADDED
data/.rake_tasks~
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tournament_organizer (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
minitest (~> 5.0)
|
18
|
+
rake (~> 10.0)
|
19
|
+
tournament_organizer!
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# TournamentOrganizer
|
2
|
+
|
3
|
+
The goal is to make a **tournament** where all **players** play **each other** on differents **games** in differents **rounds** (not a the same time, of course..)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this to your Gemfile
|
8
|
+
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'tournament_organizer'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install tournament_organizer
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
~~~bash
|
25
|
+
$ tournament_organizer --games "Foot,Basket" --players "Jean,Yves,Alex" --output yaml
|
26
|
+
---
|
27
|
+
- - :players:
|
28
|
+
- Jean
|
29
|
+
- Yves
|
30
|
+
:game: Foot
|
31
|
+
- - :players:
|
32
|
+
- Alex
|
33
|
+
- Jean
|
34
|
+
:game: Foot
|
35
|
+
- - :players:
|
36
|
+
- Alex
|
37
|
+
- Yves
|
38
|
+
:game: Foot
|
39
|
+
~~~
|
40
|
+
|
41
|
+
Output format disponnible are YAML, JSON & HTML.
|
42
|
+
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
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).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tournament_organizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
57
|
+
|
58
|
+
## Code of Conduct
|
59
|
+
|
60
|
+
Everyone interacting in the TournamentOrganizer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tournament_organizer/blob/master/CODE_OF_CONDUCT.md).
|
61
|
+
|
62
|
+
## Todo
|
63
|
+
|
64
|
+
- [ ] Add option to set number of player per game
|
65
|
+
- [ ] Add Javascript to HTML output to click on winner
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tournament_organizer"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'tournament_organizer'
|
4
|
+
require 'optparse'
|
5
|
+
require 'erb'
|
6
|
+
require 'yaml'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
tournament = TournamentOrganizer::Tournament.new
|
12
|
+
output = 'yaml'
|
13
|
+
|
14
|
+
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: tournament_organizer [options]"
|
17
|
+
|
18
|
+
opts.separator ""
|
19
|
+
opts.separator "The goal is to make a tournament where all players play each other on differents games in differents rounds (not a the same time, of course..)"
|
20
|
+
opts.separator ""
|
21
|
+
opts.separator "Specific options:"
|
22
|
+
|
23
|
+
opts.on("-p", "--players PLAYERS", "Players separated by comma `,`") do |players|
|
24
|
+
tournament.add_players *players.split(',')
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-g", "--games GAMES", "Games separated by comma `,`") do |games|
|
28
|
+
tournament.add_games *games.split(',')
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-o", "--output-format [FORMAT]", "Ouput format (default is `YAML`)", "Can be `YAML`, `JSON`, `HTML` ") do |format|
|
32
|
+
output = format
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end.parse!
|
37
|
+
|
38
|
+
if tournament.players.empty?
|
39
|
+
puts "You must specify players"
|
40
|
+
exit
|
41
|
+
elsif tournament.games.empty?
|
42
|
+
puts "You must specify games"
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
case output
|
48
|
+
when 'yaml'
|
49
|
+
puts tournament.get_organization.to_yaml
|
50
|
+
when 'json'
|
51
|
+
puts tournament.get_organization.to_json
|
52
|
+
when 'html'
|
53
|
+
class ERBContext
|
54
|
+
def initialize(hash)
|
55
|
+
hash.each_pair do |key, value|
|
56
|
+
instance_variable_set('@' + key.to_s, value)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_binding
|
61
|
+
binding
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context = ERBContext.new({rounds: tournament.get_organization})
|
66
|
+
|
67
|
+
erb_file_path = File.join(File.dirname(File.dirname(__FILE__)),"templates/default.html.erb")
|
68
|
+
|
69
|
+
puts ERB.new(File.new(erb_file_path).read).result(context.get_binding)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module TournamentOrganizer
|
2
|
+
class Tournament
|
3
|
+
attr_reader :players, :games
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@players = []
|
7
|
+
@games = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_players *players
|
11
|
+
@players.push(*players)
|
12
|
+
@players.uniq!
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_games *games
|
16
|
+
@games.push(*games)
|
17
|
+
@games.uniq!
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_organization
|
21
|
+
organization = []
|
22
|
+
fights = self.get_all_fights
|
23
|
+
|
24
|
+
while not fights.empty?
|
25
|
+
round = []
|
26
|
+
|
27
|
+
|
28
|
+
player_on_round = []
|
29
|
+
|
30
|
+
# loop on all games
|
31
|
+
@games.shuffle.each do |game|
|
32
|
+
# quit loop if we use all fights
|
33
|
+
break if fights.empty?
|
34
|
+
|
35
|
+
# ensure than current fighters not already fight on this rouns
|
36
|
+
current_fights = fights.select{|f| !player_on_round.include?(f.first) and !player_on_round.include?(f.last)}
|
37
|
+
break if current_fights.empty?
|
38
|
+
|
39
|
+
current_fight = current_fights.first
|
40
|
+
|
41
|
+
round << {players: current_fight, game: game}
|
42
|
+
player_on_round.push(*current_fight)
|
43
|
+
|
44
|
+
fights.delete current_fight
|
45
|
+
end
|
46
|
+
|
47
|
+
organization << round
|
48
|
+
end
|
49
|
+
|
50
|
+
return organization
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_all_fights
|
54
|
+
fights = []
|
55
|
+
|
56
|
+
@players.each do |player|
|
57
|
+
fights.push(*self.get_fights_for(player))
|
58
|
+
end
|
59
|
+
|
60
|
+
return fights.uniq!
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def get_fights_for player
|
65
|
+
return [] unless @players.include?(player)
|
66
|
+
|
67
|
+
return @players.select{|other_player| other_player != player}.map {|other_player| [player, other_player].sort }
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Tournament</title>
|
5
|
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"/>
|
6
|
+
</head>
|
7
|
+
<body class="container-fluid">
|
8
|
+
<div class="row">
|
9
|
+
<div class="col">
|
10
|
+
<h1>Tournament</h1>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
<div class="row">
|
14
|
+
<div class="col">
|
15
|
+
<% @rounds.each_with_index do |round, round_number| %>
|
16
|
+
<h2>Round <%= round_number %></h2>
|
17
|
+
<div class="card-columns">
|
18
|
+
<% round.each do |fight| %>
|
19
|
+
<div class="card text-center border-dark">
|
20
|
+
<div class="card-header"><%= fight[:game] %></div>
|
21
|
+
<ul class="list-group list-group-flush">
|
22
|
+
<% fight[:players].each do |player| %>
|
23
|
+
<li class="list-group-item"><%= player %></li>
|
24
|
+
<% end %>
|
25
|
+
</ul>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
<footer>
|
33
|
+
<small>Created with love by <a href="https://github.com/madeindjs/tournament_organiser">Tournament Organizer</a></small>
|
34
|
+
</footer>
|
35
|
+
</body>
|
36
|
+
</html>
|