precedences 1.5.1 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -0
- data/Manual/Manuel-fr.md +19 -0
- data/lib/precedences/precedence.rb +27 -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
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
|
@@ -219,7 +237,7 @@ class Precedence
|
|
219
237
|
|
220
238
|
# Save the values order in filepath file
|
221
239
|
#
|
222
|
-
# @
|
240
|
+
# @private
|
223
241
|
def set_precedences_ids(value)
|
224
242
|
if precedences_per_index?
|
225
243
|
#
|
@@ -245,7 +263,7 @@ class Precedence
|
|
245
263
|
|
246
264
|
# Get the values sorted if filepath exists.
|
247
265
|
#
|
248
|
-
# @
|
266
|
+
# @private
|
249
267
|
def get_precedences_ids
|
250
268
|
@get_precedences_ids ||= begin
|
251
269
|
File.exist?(filepath) ? File.read(filepath).split("\n") : []
|
@@ -257,7 +275,7 @@ class Precedence
|
|
257
275
|
# Raise an argument error otherwise.
|
258
276
|
# If it's a folder, set to .precedences file
|
259
277
|
#
|
260
|
-
# @
|
278
|
+
# @private
|
261
279
|
def filepath_validize_or_raises
|
262
280
|
File.exist?(File.dirname(filepath)) || raise(ArgumentError.new("Precedences incorrect file: its folder should exist."))
|
263
281
|
if File.exist?(filepath) && File.directory?(filepath)
|
@@ -270,7 +288,7 @@ class Precedence
|
|
270
288
|
##
|
271
289
|
# Check if given choices are valid. Raise an ArgumentError otherwise
|
272
290
|
#
|
273
|
-
# @
|
291
|
+
# @private
|
274
292
|
def choices_valid_or_raises(choices)
|
275
293
|
#
|
276
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: 2024-03-
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clir
|