precedences 1.4.1 → 1.6.1
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 +4 -4
- data/CHANGELOG +11 -0
- data/Manual/Manuel-fr.md +19 -0
- data/lib/precedences/precedence.rb +28 -9
- data/lib/precedences/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f38cb3d4a0d686152dba85df8e36c3bfb7f9c78e9a1e2167fe526cc8826a3b22
|
|
4
|
+
data.tar.gz: 302e835fa556e5a71ccd2896db769372eda815e1d73779a0feb4cb6055bf3bf1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18b50411d57cbc635d49ef76d8e2c1f5383411817b7abe084427a5dbfc300d23b12cbd5745bd911dbd0aecebe41b4bc414dbc7419291551d357bd7e9ea895476
|
|
7
|
+
data.tar.gz: 5a908f668ff5b34d262ca5a24ec437bf3dcc8049d67e06d900924417ce1d85b64867d7640e7813888e8752550ee3e572279e227295b1b508ad7942bdb7ac0274
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# 1.6.1
|
|
2
|
+
|
|
3
|
+
- Correction du bug quand classement par index et suppression
|
|
4
|
+
d’un item (trou)
|
|
5
|
+
- Ajout de la possibilité de définir une autre clé pour le
|
|
6
|
+
classement (`per_other_key`).
|
|
7
|
+
|
|
8
|
+
# 1.5.1
|
|
9
|
+
|
|
10
|
+
- Ajout de l’option `:cycle` pour `Q.select`
|
|
11
|
+
|
|
1
12
|
# 1.4.1
|
|
2
13
|
|
|
3
14
|
- option :filter à true pour le TTY::select
|
data/Manual/Manuel-fr.md
CHANGED
|
@@ -86,6 +86,25 @@ choix = precedencize(choices, file) do |q|
|
|
|
86
86
|
end
|
|
87
87
|
~~~
|
|
88
88
|
|
|
89
|
+
On peut aussi définir une autre clé que `:value` pour le tri, avec la propriété `per_other_key`
|
|
90
|
+
|
|
91
|
+
~~~ruby
|
|
92
|
+
require 'precedences'
|
|
93
|
+
|
|
94
|
+
#
|
|
95
|
+
# Des choix avec des valeurs spéciales
|
|
96
|
+
#
|
|
97
|
+
choices = [
|
|
98
|
+
{name:"La classe Integer" , pkey: :entier, value: Integer},
|
|
99
|
+
{name:"La classe Array" , pkey: :liste ,value: Array},
|
|
100
|
+
{name:"La classe Hash" , pkey: :table , value: Hash},
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
choix = precedencize(choices, file) do |q|
|
|
104
|
+
q.question "Choisis une classe"
|
|
105
|
+
q.per_other_key :pkey # <=== autre clé
|
|
106
|
+
end
|
|
107
|
+
~~~
|
|
89
108
|
|
|
90
109
|
|
|
91
110
|
## Options possibles
|
|
@@ -21,6 +21,7 @@ class Precedence
|
|
|
21
21
|
@per_page = nil
|
|
22
22
|
@default = 1
|
|
23
23
|
@precedences_per_index = false
|
|
24
|
+
@per_other_key = nil
|
|
24
25
|
@add_choice_cancel = nil
|
|
25
26
|
end
|
|
26
27
|
|
|
@@ -89,6 +90,10 @@ class Precedence
|
|
|
89
90
|
@precedences_per_index === true
|
|
90
91
|
end
|
|
91
92
|
|
|
93
|
+
def per_other_key?
|
|
94
|
+
not(@per_other_key.nil?)
|
|
95
|
+
end
|
|
96
|
+
|
|
92
97
|
def add_choice_cancel?
|
|
93
98
|
not(@add_choice_cancel.nil?)
|
|
94
99
|
end
|
|
@@ -135,6 +140,17 @@ class Precedence
|
|
|
135
140
|
end
|
|
136
141
|
def precedences_per_index=(value) ; precedences_per_index(value) end
|
|
137
142
|
|
|
143
|
+
def per_other_key(value = :__no_value)
|
|
144
|
+
if value == :__no_value
|
|
145
|
+
return @per_other_key
|
|
146
|
+
elsif not(value)
|
|
147
|
+
@per_other_key = nil
|
|
148
|
+
else
|
|
149
|
+
@per_other_key = value
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
def per_other_key=(value) ; per_other_key(value) end
|
|
153
|
+
|
|
138
154
|
##
|
|
139
155
|
# To add the cancel choice
|
|
140
156
|
#
|
|
@@ -178,16 +194,17 @@ class Precedence
|
|
|
178
194
|
#
|
|
179
195
|
# Main method whose sort items
|
|
180
196
|
#
|
|
181
|
-
# @
|
|
197
|
+
# @private
|
|
182
198
|
def sort_items(choices)
|
|
183
199
|
return choices unless File.exist?(filepath)
|
|
184
200
|
prec_ids = get_precedences_ids
|
|
185
201
|
if precedences_per_index?
|
|
186
202
|
choices_copy = choices.dup
|
|
187
|
-
choices =
|
|
188
|
-
|
|
203
|
+
choices = []
|
|
204
|
+
prec_ids.each do |id|
|
|
205
|
+
item = choices_copy[id.to_i - 1] || next
|
|
189
206
|
choices_copy[id.to_i - 1] = nil
|
|
190
|
-
item
|
|
207
|
+
choices << item
|
|
191
208
|
end
|
|
192
209
|
# On ajoute les choix restants
|
|
193
210
|
choices += choices_copy.compact
|
|
@@ -195,8 +212,9 @@ class Precedence
|
|
|
195
212
|
#
|
|
196
213
|
# Cas normal
|
|
197
214
|
#
|
|
215
|
+
key_prec = per_other_key? ? per_other_key : :value
|
|
198
216
|
choices.sort!{|a, b|
|
|
199
|
-
(prec_ids.index(a[
|
|
217
|
+
(prec_ids.index(a[key_prec].to_s)||10000) <=> (prec_ids.index(b[key_prec].to_s)||10000)
|
|
200
218
|
}
|
|
201
219
|
end
|
|
202
220
|
return choices
|
|
@@ -213,12 +231,13 @@ class Precedence
|
|
|
213
231
|
help: self.help,
|
|
214
232
|
default: get_default_value_index(choices),
|
|
215
233
|
filter: true,
|
|
234
|
+
cycle: true
|
|
216
235
|
}
|
|
217
236
|
end
|
|
218
237
|
|
|
219
238
|
# Save the values order in filepath file
|
|
220
239
|
#
|
|
221
|
-
# @
|
|
240
|
+
# @private
|
|
222
241
|
def set_precedences_ids(value)
|
|
223
242
|
if precedences_per_index?
|
|
224
243
|
#
|
|
@@ -244,7 +263,7 @@ class Precedence
|
|
|
244
263
|
|
|
245
264
|
# Get the values sorted if filepath exists.
|
|
246
265
|
#
|
|
247
|
-
# @
|
|
266
|
+
# @private
|
|
248
267
|
def get_precedences_ids
|
|
249
268
|
@get_precedences_ids ||= begin
|
|
250
269
|
File.exist?(filepath) ? File.read(filepath).split("\n") : []
|
|
@@ -256,7 +275,7 @@ class Precedence
|
|
|
256
275
|
# Raise an argument error otherwise.
|
|
257
276
|
# If it's a folder, set to .precedences file
|
|
258
277
|
#
|
|
259
|
-
# @
|
|
278
|
+
# @private
|
|
260
279
|
def filepath_validize_or_raises
|
|
261
280
|
File.exist?(File.dirname(filepath)) || raise(ArgumentError.new("Precedences incorrect file: its folder should exist."))
|
|
262
281
|
if File.exist?(filepath) && File.directory?(filepath)
|
|
@@ -269,7 +288,7 @@ class Precedence
|
|
|
269
288
|
##
|
|
270
289
|
# Check if given choices are valid. Raise an ArgumentError otherwise
|
|
271
290
|
#
|
|
272
|
-
# @
|
|
291
|
+
# @private
|
|
273
292
|
def choices_valid_or_raises(choices)
|
|
274
293
|
#
|
|
275
294
|
# On en aura besoin
|
data/lib/precedences/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- PhilippePerret
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: clir
|