easy_rr 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7762e4842972c0d777c4e3c83ccdedee62bf3dab
4
- data.tar.gz: 6e12abd320223332cb5dba010e7d11ff8fae7428
3
+ metadata.gz: cd22717eefebca5d6593a89445e7430f93aa33be
4
+ data.tar.gz: f029d4489b183a05e84ce289f82398dd0a70eee9
5
5
  SHA512:
6
- metadata.gz: e12cc37f144cab915f1b82830ce3c21351863c7d3413fbc429c7ca52e884b49d7747392719015395da6026e796d4ce2bc70db66626b549907cafbed443f0eed8
7
- data.tar.gz: 20df0898201decaacc30aa31bb4c3570d5ef654a7f1893d53b93c89f830e64962b0252a1b04fe592b1d6fd79974125452c3273eb2c263ce2ad5aaf9b41774057
6
+ metadata.gz: 54af9b307a564a7ee858f1da68a0f99e7f79c5665cec6e9b712da367ea902e1c06189009a04370f5f4a01d1ff37b554033eff0f7c0cc3c5f63b8b3f3a1da8238
7
+ data.tar.gz: 618707a155eb57f167fd9bad63e7cda0f0cdfac92e2587e2f8ce19ec98d6d9a6d1951fa0b02fd19c80a03fe20948879f05446a56f1e036f24b837e37c88757ae
data/README.md CHANGED
@@ -1,9 +1,3 @@
1
- # EasyRr
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/easy_rr`. 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
1
  ## Installation
8
2
 
9
3
  Add this line to your application's Gemfile:
@@ -22,17 +16,89 @@ Or install it yourself as:
22
16
 
23
17
  ## Usage
24
18
 
25
- TODO: Write usage instructions here
19
+ Using easy_rr is very easy, as its name suggests. You just need to pass it an array and an integer to specify the amount of times that each participant will face each other.
20
+
21
+ It receives two parameters: an array and an integer.
22
+
23
+ The array consists of the users, teams, or participants that will be matched.
24
+ The integer is the amount of times each participant will face each other participant. This defaults to 1.
25
+
26
+ Here's a little example:
27
+
28
+ ```ruby
29
+
30
+ #You can pass an array
31
+ teams = [ "Colombia", "Peru", "Venezuela", "Brazil" ]
32
+
33
+ #Then you can call EasyRr to generate the matches
34
+ games = EasyRr.matches(teams)
35
+
36
+ #=> [[["Venezuela", "Brazil"], ["Peru", "Colombia"]], [["Peru", "Brazil"], ["Colombia", "Venezuela"]], [["Colombia", "Brazil"], ["Venezuela", "Peru"]]]
37
+ ```
38
+
39
+ By passing a second parameter you can specify the amount of times each participant will face each other participant, as said before.
40
+
41
+ So, in another little example:
42
+
43
+ ```ruby
44
+
45
+ #The array
46
+
47
+ teams = [ "Real Madrid", "Bayern Munchen", "Juventus", "F.C. Barcelona" ]
48
+
49
+ #Generate the matches, this time you pass 2 as the number of times they will face each other
50
+ games = EasyRr.matches(teams,2)
51
+
52
+ #=> [[["Bayern Munchen", "F.C. Barcelona"], ["Juventus", "Real Madrid"]], [["Juventus", "F.C. Barcelona"], ["Real Madrid", "Bayern Munchen"]], [["Real Madrid", "F.C. Barcelona"], ["Bayern Munchen", "Juventus"]], [["Bayern Munchen", "F.C. Barcelona"], ["Juventus", "Real Madrid"]], [["Juventus", "F.C. Barcelona"], ["Real Madrid", "Bayern Munchen"]], [["Real Madrid", "F.C. Barcelona"], ["Bayern Munchen", "Juventus"]]]
53
+ ```
54
+
55
+ If you want, you can also pass an ActiveRecord object, for instance:
56
+
57
+ ```ruby
58
+
59
+ #This can be the collection of participants
60
+
61
+ participants = Model.teams
62
+
63
+ #As this can also be passed
64
+
65
+ participants = User.all
66
+ ```
67
+
68
+ Either way, an array of integers can also be passed if you don't have the names of each participant but the ids.
69
+
70
+ ```ruby
26
71
 
27
- ## Development
72
+ #Array of ids
73
+ teams = [ 1,2,3,4 ]
28
74
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+ games = EasyRr.matches(teams)
76
+ => [[[2, 4], [3, 1]], [[3, 4], [1, 2]], [[1, 4], [2, 3]]]
77
+ ```
78
+
79
+ If the array passed is odd, the generated array will have one match where one of the teams is nil.
80
+
81
+ ```ruby
82
+
83
+ #Array of ids
84
+ teams = [ 1,2,3,4,5 ]
85
+
86
+ games = EasyRr.matches(teams)
87
+ => [[[2, nil], [3, 1], [4, 5]], [[3, nil], [4, 2], [5, 1]], [[4, nil], [5, 3], [1, 2]], [[5, nil], [1, 4], [2, 3]]]
88
+ ```
89
+
90
+ Finally, you can loop through the generated array and create each match in your database according to the model you have.
91
+
92
+ ```ruby
30
93
 
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).
94
+ teams = [ "Italy", "France", "Argentina", "Ghana" ]
32
95
 
33
- ## Contributing
96
+ teams.each do |j|
97
+ j.map { |x| Model.create("params_here") }
98
+ end
99
+ ```
34
100
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/easy_rr.
101
+ Enjoy.
36
102
 
37
103
 
38
104
  ## License
@@ -1,3 +1,3 @@
1
1
  module EasyRr
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/easy_rr.rb CHANGED
@@ -3,20 +3,28 @@ require "easy_rr/version"
3
3
  module EasyRr
4
4
  def self.matches(participants,*facingMatches)
5
5
 
6
+ if participants.class != Array
7
+ participants = participants.to_a
8
+ end
9
+
6
10
  fMatches = !facingMatches[0].nil? ? facingMatches[0] : 1
7
11
 
8
12
  if participants.size%2 != 0
9
13
  participants.push nil
10
14
  end
15
+
11
16
  length = participants.size
12
17
  last_e = participants.pop
18
+
13
19
  matches = ( ( ( fMatches*length )/2 ) + fMatches ).times.map do
14
20
  participants.rotate!
15
21
  [[participants.first, last_e]] + (1...(length / 2)).map { |j| [participants[j], participants[length - 1 - j]] }
16
22
  end
23
+
17
24
  unless last_e.nil?
18
25
  participants.push last_e
19
26
  end
27
+
20
28
  return matches
21
29
  end
22
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_rr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rosillo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-12 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler