precedences 1.6.1 → 1.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f38cb3d4a0d686152dba85df8e36c3bfb7f9c78e9a1e2167fe526cc8826a3b22
4
- data.tar.gz: 302e835fa556e5a71ccd2896db769372eda815e1d73779a0feb4cb6055bf3bf1
3
+ metadata.gz: 1a735e7b8f40a271f4259c8a4c3057d6a2836f2db06ab4ca89e094a8ced4b6f8
4
+ data.tar.gz: 7ebd0aafee4fa270219b8f46c83ca2e3fc0ad3870997277ba91ac4dcdd45f1aa
5
5
  SHA512:
6
- metadata.gz: 18b50411d57cbc635d49ef76d8e2c1f5383411817b7abe084427a5dbfc300d23b12cbd5745bd911dbd0aecebe41b4bc414dbc7419291551d357bd7e9ea895476
7
- data.tar.gz: 5a908f668ff5b34d262ca5a24ec437bf3dcc8049d67e06d900924417ce1d85b64867d7640e7813888e8752550ee3e572279e227295b1b508ad7942bdb7ac0274
6
+ metadata.gz: 8518f9fd7c03c3204c4930cd6faa99feb28d48e34d7d44d8fb1681fdc4d18407ef9649a4873784e1554d97d33b333f0fb2943c13d1eb98e049e8442c6ebc5f04
7
+ data.tar.gz: d0c399a24bf4178581e8c0573dd515f3b8ef9d1fa31b0ed09fc9cce013abe61476e7e2d224d26fccd865f322938f115cb26052ea632c5d35763544fd2a033a43
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.7.0
2
+
3
+ - Possiblité d’ajouter des menus hors classement à l’aide
4
+ de la méthode block #add (ou son alias #add_choice)
5
+
1
6
  # 1.6.1
2
7
 
3
8
  - Correction du bug quand classement par index et suppression
data/Manual/Manuel-fr.md CHANGED
@@ -106,6 +106,7 @@ choix = precedencize(choices, file) do |q|
106
106
  end
107
107
  ~~~
108
108
 
109
+ <a name="options"></a>
109
110
 
110
111
  ## Options possibles
111
112
 
@@ -161,6 +162,14 @@ choix = precedencize(choices, precfile) do |q|
161
162
  q.default = "premier"
162
163
  # ou q.default "premier"
163
164
  # => Sélectionnera le choix "Choix premier"
165
+
166
+ # Ajout de menus à la fin, jamais classés
167
+ q.add "Dernier menu", :last
168
+ q.add_choice "Tout dernier", :very_last
169
+
170
+ # Ajout de menus au début, jamais classés
171
+ q.add_choice "Tout premier".bleu, :very_first, **{at_top:true}
172
+ q.add("Premier", :first, {at_top: true})
164
173
 
165
174
  end
166
175
 
@@ -187,3 +196,9 @@ end
187
196
  ~~~
188
197
 
189
198
  > 😃 Noter qu’on peut en fait se servir de ce menu pour ajouter n’importe quel autre menu que “Renoncer”.
199
+
200
+
201
+
202
+ #### Ajouter un menu quelconque
203
+
204
+ Utiliser les méthodes `#add` ou `#add_choice` (alias). Cf. ci-dessus [Options possibles](#options).
data/Manual/Manuel-fr.pdf CHANGED
Binary file
data/Rakefile CHANGED
@@ -4,7 +4,8 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ # t.test_files = FileList["test/**/*_test.rb"]
8
+ t.test_files = FileList["test/**/precedences_test.rb"]
8
9
  end
9
10
 
10
11
  task :default => :test
@@ -169,16 +169,42 @@ class Precedence
169
169
  @add_choice_cancel = params
170
170
  end
171
171
 
172
+ ##
173
+ # To add any choice not precedencized
174
+ #
175
+ # @param name [String] The menu name
176
+ # @param value [Any] Then value of the menu
177
+ # @param params [Hash]
178
+ # :at_top If true, add the item at the top
179
+ # Else (default) add at the bottom
180
+ #
181
+ attr_reader :added_choices_before
182
+ attr_reader :added_choices_after
183
+ def add(name, value, **params)
184
+ @added_choices_before = []
185
+ @added_choices_after = []
186
+ name.is_a?(String) || raise(ArgumentError.new("First argument should be a String."))
187
+ lechoix = {name: name, value: value}
188
+ if params[:at_top]
189
+ @added_choices_before << lechoix
190
+ else
191
+ @added_choices_after << lechoix
192
+ end
193
+ end
194
+ alias :add_choice :add
195
+
172
196
  private
173
197
 
174
198
  ##
175
199
  # = main =
200
+ # @private
176
201
  #
177
202
  def prepare_choices(choices)
178
203
  #
179
204
  # Classement des choix par précédence
180
205
  #
181
206
  choices = sort_items(choices)
207
+
182
208
  #
183
209
  # Faut-il ajouter un choix cancel ?
184
210
  #
@@ -186,6 +212,17 @@ class Precedence
186
212
  add_method = (@add_choice_cancel[:position] == :down) ? :push : :unshift
187
213
  choices.send(add_method, @add_choice_cancel)
188
214
  end
215
+
216
+ #
217
+ # Y a-t-il des menus à ajouter ?
218
+ #
219
+ if added_choices_before && not(added_choices_before.empty?)
220
+ choices = added_choices_before + choices
221
+ end
222
+ if added_choices_after && not(added_choices_after.empty?)
223
+ choices = choices + added_choices_after
224
+ end
225
+
189
226
  #
190
227
  # On retourne les choix préparés
191
228
  #
@@ -1,3 +1,3 @@
1
1
  module Precedences
2
- VERSION = "1.6.1"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: precedences
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhilippePerret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-25 00:00:00.000000000 Z
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clir