@@ -9,6 +9,22 @@ module Logic
9
9
module Predicates
10
10
# rubocop:disable Metrics/ModuleLength
11
11
module Methods
12
+ def self . uuid_format ( version )
13
+ ::Regexp . new ( <<~FORMAT . chomp , ::Regexp ::IGNORECASE )
14
+ \\ A[0-9A-F]{8}-[0-9A-F]{4}-#{ version } [0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\\ z
15
+ FORMAT
16
+ end
17
+
18
+ UUIDv1 = uuid_format ( 1 )
19
+
20
+ UUIDv2 = uuid_format ( 2 )
21
+
22
+ UUIDv3 = uuid_format ( 3 )
23
+
24
+ UUIDv4 = uuid_format ( 4 )
25
+
26
+ UUIDv5 = uuid_format ( 5 )
27
+
12
28
def []( name )
13
29
method ( name )
14
30
end
@@ -204,32 +220,29 @@ def format?(regex, input)
204
220
end
205
221
206
222
def case? ( pattern , input )
223
+ # rubocop:disable Style/CaseEquality
207
224
pattern === input
225
+ # rubocop:enable Style/CaseEquality
208
226
end
209
227
210
228
def uuid_v1? ( input )
211
- uuid_v1_format = /\A [0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z /i
212
- format? ( uuid_v1_format , input )
229
+ format? ( UUIDv1 , input )
213
230
end
214
231
215
232
def uuid_v2? ( input )
216
- uuid_v2_format = /\A [0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z /i
217
- format? ( uuid_v2_format , input )
233
+ format? ( UUIDv2 , input )
218
234
end
219
235
220
236
def uuid_v3? ( input )
221
- uuid_v3_format = /\A [0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z /i
222
- format? ( uuid_v3_format , input )
237
+ format? ( UUIDv3 , input )
223
238
end
224
239
225
240
def uuid_v4? ( input )
226
- uuid_v4_format = /\A [0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z /i
227
- format? ( uuid_v4_format , input )
241
+ format? ( UUIDv4 , input )
228
242
end
229
243
230
244
def uuid_v5? ( input )
231
- uuid_v5_format = /\A [0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}\z /i
232
- format? ( uuid_v5_format , input )
245
+ format? ( UUIDv5 , input )
233
246
end
234
247
235
248
def uri? ( schemes , input )
0 commit comments