Papy-tools 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+
3
+ module PapyTools
4
+
5
+ class FabriqueJoueur
6
+
7
+ def initialize()
8
+ end
9
+
10
+ def self.instance()
11
+ @instance||=new()
12
+ end
13
+
14
+ def construction(elt,nbrondes)
15
+ Joueur.new() do |j|
16
+ j.nb_rondes=nbrondes
17
+ j.place=elt[0].innerHTML.to_i
18
+ j.titre=get_titre(elt[1])
19
+ j.nom=get_nom(elt[2])
20
+ j.elo=elt[3].innerHTML
21
+ j.categorie=elt[4].innerHTML
22
+ j.pays=get_pays(elt[5])
23
+ j.ligue=elt[6].innerHTML
24
+ j.rondes=chargement_rondes(elt,nbrondes)
25
+ j.departages=chargement_departage(elt,nbrondes)
26
+ j.pts=elt[7+nbrondes].search("b").innerHTML
27
+ end
28
+ end
29
+
30
+ def chargement_rondes(elt,nbrondes)
31
+ indice=6+nbrondes
32
+ rondes=[]
33
+ elt[7..indice].each_with_index do |chaine,i|
34
+ ronde=Ronde.new(chaine.innerHTML,i+1)
35
+ rondes<< ronde
36
+ end
37
+ rondes
38
+ end
39
+
40
+ def chargement_departage(elt,nbrondes)
41
+ debut=8+nbrondes
42
+ fin=elt.length-1
43
+ departages=[]
44
+ elt[debut..fin].each do |departage|
45
+ departages<< departage.innerHTML
46
+ end
47
+ departages
48
+ end
49
+
50
+ def get_nom(elt)
51
+ elt.search("b").innerHTML
52
+ end
53
+
54
+ def get_titre(elt)
55
+ titre=elt.innerHTML
56
+ if titre=="&nbsp;"
57
+ ""
58
+ else
59
+ titre
60
+ end
61
+ end
62
+
63
+ def get_pays(elt)
64
+ elt.innerHTML
65
+ end
66
+
67
+
68
+ end
69
+
70
+ class FabriqueJoueurFFE< FabriqueJoueur
71
+
72
+
73
+ def get_pays(elt)
74
+ elts=elt.search('img')
75
+ return elt.inner_html unless elts.first
76
+ src=elts.first['src']
77
+ pays=src.split("\\").last
78
+ pays=pays.split(".").first
79
+ end
80
+
81
+
82
+
83
+ end
84
+
85
+ class FabriqueJoueurParListe
86
+
87
+ def initialize
88
+ end
89
+
90
+ def self.instance
91
+ @instance||=new()
92
+ end
93
+
94
+ def construction(elt)
95
+ Joueur.new do |j|
96
+ j.nom=elt[2].innerHTML
97
+ j.club=elt[7].innerHTML
98
+ end
99
+ end
100
+ end
101
+
102
+ end
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+
3
+ module PapyTools
4
+
5
+ class FabriqueTournoi
6
+
7
+
8
+ def initialize()
9
+ @doc
10
+ end
11
+
12
+ def self.instance()
13
+ @instance||=new()
14
+ end
15
+
16
+ def creation_joueur(elt,nombre_rondes)
17
+ FabriqueJoueur.instance.construction(elt,nombre_rondes)
18
+ end
19
+
20
+ def nombre_rondes()
21
+ @doc.at("tr.ligne").search("td.papi_small_c").length
22
+ end
23
+
24
+ def titre()
25
+ balisetitre=@doc.at("tr.papi_titre td").innerHTML
26
+ tableautitre=balisetitre.split("<br />")
27
+ (tableautitre[0])+":"+tableautitre[1]
28
+ end
29
+
30
+ def chargement_departages(elt)
31
+ debut=8+nombre_rondes()
32
+ fin=elt.length-1
33
+ departages=[]
34
+ elt[debut..fin].each { |departage| departages<< departage.innerHTML }
35
+ departages
36
+ end
37
+
38
+ def construction(doc,options={})
39
+ @doc=doc
40
+ joueurs=[]
41
+ @doc.at("tr.papi_small_t")["class"]="entete"
42
+ (@doc/"tr.papi_small_t").attr("class","entete")
43
+ (@doc/"tr.papi_small_c").attr("class","ligne")
44
+ (@doc/"tr.papi_small_f").attr("class","ligne")
45
+ (@doc/"tr.ligne").each do |elt|
46
+ joueur=creation_joueur(elt.search("td"),nombre_rondes())
47
+ joueurs << joueur
48
+ end
49
+ if options[:liste]
50
+ liste=options[:liste]
51
+ (liste/"tr.papi_liste_c").attr("class","ligne")
52
+ (liste/"tr.papi_liste_f").attr("class","ligne")
53
+ (liste/"tr.ligne").each do |elt|
54
+ joueur_liste=FabriqueJoueurParListe.instance.construction(elt.search("td"))
55
+ joueur=joueurs.find{|j| j.nom==joueur_liste.nom}
56
+ joueur.club=joueur_liste.club
57
+ end
58
+ end
59
+ Tournoi.new() do |t|
60
+ t.joueurs=joueurs
61
+ t.nombre_rondes=nombre_rondes()
62
+ t.departages=chargement_departages(@doc.at("tr.entete").search("td") )
63
+ t.titre=titre()
64
+ end
65
+
66
+ end
67
+
68
+ end
69
+
70
+ class FabriqueTournoiFFE< FabriqueTournoi
71
+
72
+ def titre()
73
+ tableautitre=(@doc/"tr.papi_titre td").map{|titre| titre.innerHTML}
74
+ (tableautitre[0])+":"+tableautitre[1]
75
+ end
76
+
77
+ def creation_joueur(elt,nombre_rondes)
78
+ FabriqueJoueurFFE.instance.construction(elt,nombre_rondes)
79
+ end
80
+
81
+ def nombre_rondes()
82
+ @doc.at("tr.entete").search("td.papi_c").length-3
83
+ end
84
+
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ module PapyTools
4
+
5
+ class Presentation
6
+
7
+
8
+
9
+ def initialize(tournoi,invisibles,filtres)
10
+
11
+ @tournoi=tournoi
12
+
13
+ filtres.each do |filtre,value|
14
+ case filtre
15
+ when :ligue
16
+ @joueurs_filtres=@tournoi.filtre_ligue(value)
17
+ when :premiers
18
+ @joueurs_filtres=@tournoi.filtre_premiers(value)
19
+ end
20
+ end
21
+ @joueurs_filtres||=@tournoi.joueurs
22
+ @joueurs=@tournoi.joueurs
23
+ @ligues=@joueurs.map{|j| j.ligue}.uniq.sort
24
+ @clubs=@joueurs.map{|j| j.club}.uniq.sort
25
+ @categories=@joueurs.map{|j| j.categorie}.uniq.sort
26
+ @invisibles=invisibles
27
+ @couleur={:default=>"ligneclaire"}
28
+ helpers=Module.constants.grep(/.*Helper/).map{|h| Kernel.const_get(h)}
29
+ helpers.each do |h|
30
+ extend h
31
+ end
32
+
33
+ end
34
+
35
+ def get_binding()
36
+ binding
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,135 @@
1
+ # encoding: utf-8
2
+
3
+ module PapyTools
4
+
5
+ class Tournoi
6
+
7
+ attr_accessor :joueurs,
8
+ :nombre_rondes,
9
+ :titre,
10
+ :departages
11
+
12
+ def initialize(&block)
13
+ @joueurs=[]
14
+ block.call(self) if block
15
+ end
16
+
17
+ def get_binding
18
+ binding
19
+ end
20
+
21
+ def nombre_joueurs
22
+ @joueurs.length
23
+ end
24
+
25
+ def filtre_premiers(arg)
26
+ arg=arg.to_i
27
+ @joueurs.select{|j| j.place<arg+1}
28
+ end
29
+
30
+ def filtre_ligue(arg)
31
+ @joueurs.select{|j| j.ligue == arg}
32
+ end
33
+
34
+ def to_a
35
+ [@joueurs.map{|j| j.to_a()},@nombre_rondes,@titre,@departages]
36
+ end
37
+ end
38
+
39
+ class Joueur
40
+
41
+ attr_accessor :rondes,
42
+ :place,
43
+ :titre,
44
+ :nom,
45
+ :elo,
46
+ :categorie,
47
+ :pays,
48
+ :ligue,
49
+ :nb_rondes,
50
+ :pts,
51
+ :departages,
52
+ :club
53
+
54
+
55
+
56
+ def initialize(&block)
57
+ block.call(self) if block
58
+ end
59
+
60
+ def to_a
61
+ [@rondes.map{|r| r.resultat_condense()},@place,@titre,@nom,@elo,@categorie,@pays,@ligue,@pts,@departages,@club]
62
+ end
63
+
64
+
65
+ end
66
+
67
+ class Ronde
68
+
69
+ attr_reader :exempt,
70
+ :forfait_prevenu,
71
+ :resultat_condense,
72
+ :resultat,
73
+ :couleur,
74
+ :proxyadversaire
75
+
76
+ attr_accessor :numeroronde
77
+
78
+ def initialize(chaine,numeroronde)
79
+ @numeroronde=numeroronde
80
+ @exempt=false
81
+ @forfait_prevenu=false
82
+ analyse_chaine(chaine) unless exemptouforfaitprevenu(chaine)
83
+ end
84
+
85
+
86
+ private
87
+ def analyse_chaine(chaine)
88
+ debut=1
89
+ @resultat=case
90
+ when chaine.include?("+")
91
+ "1-0"
92
+ when chaine.include?("-")
93
+ "0-1"
94
+ when chaine.include?("=")
95
+ "="
96
+ when chaine.include?("&gt;")
97
+ debut=4
98
+ "1-0( forfait)"
99
+ when chaine.include?("&lt;")
100
+ debut=4
101
+ "0-1( forfait)"
102
+ end
103
+ @couleur=if chaine.include?("N")
104
+ "N"
105
+ else
106
+ "B"
107
+ end
108
+ fin=chaine.length-2
109
+ @proxyadversaire=chaine[debut..fin]
110
+ @resultat_condense=chaine
111
+ end
112
+
113
+ def exemptouforfaitprevenu(chaine)
114
+ case
115
+ when chaine.include?("EXE")
116
+ @resultat_condense=chaine
117
+ @resultat="exempt"
118
+ @exempt=true
119
+ when chaine.include?("&nbsp;")
120
+ @resultat_condense=chaine
121
+ @resultat="forfait"
122
+ @forfait_prevenu=true
123
+ else
124
+ false
125
+ end
126
+ end
127
+
128
+
129
+ end
130
+
131
+ end
132
+
133
+
134
+
135
+
@@ -0,0 +1,183 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
+
5
+
6
+
7
+
8
+ <style type="text/css">
9
+
10
+ table #grille{
11
+ background: #F1EFE2;
12
+ font: normal 80%/1em Arial,Helvetica;
13
+ color: #382E1F;
14
+ margin: 0;
15
+ padding: 0 0 2em 0;
16
+ text-align: left;
17
+ line-height:1.3;
18
+ }
19
+
20
+ .invisible{
21
+ display:none;
22
+ }
23
+ table{
24
+ border-collapse:collapse;
25
+ }
26
+ tr{
27
+ color:#382E1F;
28
+ width: 600px;
29
+ }
30
+ tr.lignefonce{
31
+ background:#E6D6BD;
32
+ border:#FFFFFF solid 3px;
33
+ font-weight:bold;
34
+ }
35
+ tr.ligneclaire{
36
+ background:#F7EEDF;
37
+ border:#FFFFFF solid 3px;
38
+ color:#382E1F;
39
+ font-weight:normal;
40
+ }
41
+ td{
42
+ padding-top:3px;
43
+ padding-bottom:3px;
44
+ }
45
+
46
+ div.infobox{
47
+ position:relative;
48
+ width:100%;
49
+ z-index:0;
50
+ }
51
+ div.infobox:hover {
52
+ position:relative;
53
+ width:100%;
54
+ z-index:50;
55
+ }
56
+ div.infobox table{
57
+ float: right;
58
+ width:100%;
59
+ }
60
+ div.infobox table tr{
61
+
62
+ }
63
+
64
+
65
+ div.infobox .more{
66
+ display:none;
67
+ border:black solid 1px;
68
+ }
69
+ div.infobox:hover .more{
70
+ display:block;
71
+ position:absolute;
72
+ left:4px;
73
+ top:4px;
74
+ width:540px;
75
+ padding:10px 10px 10px 10px;
76
+ border:1px solid grey;
77
+ background-color:white;
78
+ color:#382E1F;
79
+ }
80
+
81
+ div.noir{
82
+ border: 1px solid #848484;
83
+ background-color:black;
84
+ float: left;
85
+ padding: 5px;
86
+ margin-top:4px;
87
+ margin-right:2px;
88
+ }
89
+ div.blanc{
90
+ border: 1px solid #848484;
91
+ background-color:white;
92
+ float: left;
93
+ padding: 5px;
94
+ margin-top:4px;
95
+ margin-right:2px;
96
+ }
97
+
98
+ </style>
99
+ </head>
100
+ <h2><%=@tournoi.titre%></h2>
101
+ <p>
102
+ <strong>Pointer</strong>
103
+ la souris sur le nom du joueur pour afficher le cadre de ses résultats.
104
+
105
+ </p>
106
+
107
+ <table id="grille">
108
+ <tr>
109
+ <td>Pl</td>
110
+ <td>&nbsp;</td>
111
+ <td>Nom</td>
112
+ <td>Elo</td>
113
+ <%unless @invisibles[:categorie]%>
114
+ <td>Cat.</td>
115
+ <%end%>
116
+ <%unless @invisibles[:pays]%>
117
+ <td>Fede</td>
118
+ <%end%>
119
+ <%unless @invisibles[:ligue]%>
120
+ <td>Ligue</td>
121
+ <%end%>
122
+ <%unless @invisibles[:club]%>
123
+ <td>club</td>
124
+ <%end%>
125
+ <%1.step(@tournoi.nombre_rondes,1) do |i|%>
126
+ <td>Rd<%=i%></td>
127
+ <%end%>
128
+ <td>Pts</td>
129
+ <%if @tournoi.departages && @invisibles[:departages]==false%>
130
+ <%@tournoi.departages.each do |departage| %>
131
+ <td><%=departage%></td>
132
+ <%end%>
133
+ <%end%>
134
+ </tr>
135
+ <%@joueurs_filtres.each do |j|%>
136
+ <tr class="<%=couleur_ligne(@couleur)%> joueur">
137
+ <td><%=j.place%></td>
138
+ <td><%=format_titre(j.titre)%></td>
139
+ <td><div class="infobox">
140
+ <%=j.nom%>
141
+ <div class="more">
142
+ <table>
143
+ <%j.rondes.each do |ronde|%>
144
+ <tr class=<%=couleurligne(ronde.numeroronde)%>>
145
+ <td><%=couleur_joueur(ronde,:div)%><%=j.nom%></td>
146
+ <td><%=j.elo%></td>
147
+ <td><%=ronde.resultat%>
148
+ <td><%=couleur_joueur_adversaire(ronde,:div)%>
149
+ <%=nom_adversaire(ronde,@joueurs)%>
150
+ </td>
151
+ <td><%=elo_adversaire(ronde,@joueurs)%></td>
152
+ </tr>
153
+ <%end%>
154
+ </table>
155
+ </div>
156
+ </div>
157
+ </td>
158
+ <td><%=j.elo%></td>
159
+ <%unless @invisibles[:categorie]%>
160
+ <td><%=j.categorie%></td>
161
+ <%end%>
162
+ <%unless @invisibles[:pays]%>
163
+ <td><%=j.pays%></td>
164
+ <%end%>
165
+ <%unless @invisibles[:ligue]%>
166
+ <td><%=j.ligue%></td>
167
+ <%end%>
168
+ <%unless @invisibles[:club]%>
169
+ <td><%=j.club%></td>
170
+ <%end%>
171
+ <%j.rondes.each do |ronde|%>
172
+ <td><%=ronde.resultat_condense()%></td>
173
+ <%end%>
174
+ <td><%=j.pts%></td>
175
+ <%if @tournoi.departages && @invisibles[:departages]==false%>
176
+ <%j.departages.each do |departage|%>
177
+ <td><%=departage%></td>
178
+ <%end%>
179
+ <%end%>
180
+ </tr>
181
+ <%end%>
182
+ </table>
183
+ </html>