code-ruby 1.9.1 → 1.9.3
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/date.rb +37 -6
- data/lib/code/object/list.rb +697 -0
- data/lib/code/object/time.rb +30 -6
- data/lib/code.rb +1 -0
- data/spec/code/format_spec.rb +2 -2
- data/spec/code/object/list_spec.rb +4 -0
- data/spec/code_spec.rb +6 -0
- metadata +1 -2
- data/spec/code/object/time_spec.rb +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 22952473dbe9b9dae4c19097315ed02cd5ffd54760b4769e9bb103d1460f0a56
|
|
4
|
+
data.tar.gz: 91bcb3130986a3fbee06a08f5c814121f4efbe54bb4a8c193e399befceb4a465
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 444ad49c72cc55a137333d7906955a750de131d32e81dd971e4627217618c3b4be318b4483ad30d266e217cb677c379ecbc3aa1abf410db843e3262a9e8cf644
|
|
7
|
+
data.tar.gz: 154153bc86d78b3f34e1bab45ba094fa1b481146f7e654a049a90311d7483dba7850e86934bc1598193199d163ed788fdc201dfa3fc54e97c4b2376188a0abab
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.3
|
data/lib/code/object/date.rb
CHANGED
|
@@ -81,6 +81,7 @@ class Code
|
|
|
81
81
|
code_operator = args.fetch(:operator, nil).to_code
|
|
82
82
|
code_arguments = args.fetch(:arguments, []).to_code
|
|
83
83
|
code_value = code_arguments.code_first
|
|
84
|
+
code_second = code_arguments.code_second
|
|
84
85
|
|
|
85
86
|
case code_operator.to_s
|
|
86
87
|
when "after?"
|
|
@@ -96,8 +97,15 @@ class Code
|
|
|
96
97
|
sig(args)
|
|
97
98
|
code_future?
|
|
98
99
|
when "format"
|
|
99
|
-
sig(args) { String }
|
|
100
|
-
|
|
100
|
+
sig(args) { [String.maybe, { locale: String.maybe }] }
|
|
101
|
+
|
|
102
|
+
if code_value.is_a?(Dictionary)
|
|
103
|
+
code_format(nil, locale: code_value.code_get(:locale))
|
|
104
|
+
elsif code_second.something?
|
|
105
|
+
code_format(code_value, locale: code_second.code_get(:locale))
|
|
106
|
+
else
|
|
107
|
+
code_format(code_value)
|
|
108
|
+
end
|
|
101
109
|
when "tomorrow"
|
|
102
110
|
sig(args)
|
|
103
111
|
code_tomorrow
|
|
@@ -323,6 +331,7 @@ class Code
|
|
|
323
331
|
code_operator = args.fetch(:operator, nil).to_code
|
|
324
332
|
code_arguments = args.fetch(:arguments, []).to_code
|
|
325
333
|
code_value = code_arguments.code_first
|
|
334
|
+
code_second = code_arguments.code_second
|
|
326
335
|
|
|
327
336
|
case code_operator.to_s
|
|
328
337
|
when "after?"
|
|
@@ -407,8 +416,15 @@ class Code
|
|
|
407
416
|
sig(args)
|
|
408
417
|
code_sunday?
|
|
409
418
|
when "format"
|
|
410
|
-
sig(args) { String }
|
|
411
|
-
|
|
419
|
+
sig(args) { [String.maybe, { locale: String.maybe }] }
|
|
420
|
+
|
|
421
|
+
if code_value.is_a?(Dictionary)
|
|
422
|
+
code_format(nil, locale: code_value.code_get(:locale))
|
|
423
|
+
elsif code_second.something?
|
|
424
|
+
code_format(code_value, locale: code_second.code_get(:locale))
|
|
425
|
+
else
|
|
426
|
+
code_format(code_value)
|
|
427
|
+
end
|
|
412
428
|
when "january?"
|
|
413
429
|
sig(args)
|
|
414
430
|
code_january?
|
|
@@ -684,10 +700,25 @@ class Code
|
|
|
684
700
|
code_month.code_twelve?
|
|
685
701
|
end
|
|
686
702
|
|
|
687
|
-
def code_format(format)
|
|
703
|
+
def code_format(format, locale: nil)
|
|
688
704
|
code_format = format.to_code
|
|
705
|
+
code_locale = locale.to_code
|
|
706
|
+
|
|
707
|
+
requested_locale = code_locale.raw&.to_s
|
|
708
|
+
locale = requested_locale&.presence_in(LOCALES)&.to_sym || I18n.locale
|
|
709
|
+
locale = I18n.locale unless I18n.available_locales.include?(locale.to_sym)
|
|
710
|
+
|
|
711
|
+
format = code_format.raw || :default
|
|
712
|
+
format = format.to_sym if I18n.exists?("date.formats.#{format}", locale)
|
|
713
|
+
|
|
714
|
+
String.new(I18n.l(raw, format: format, locale: locale))
|
|
715
|
+
end
|
|
716
|
+
|
|
717
|
+
def code_format_locale_from_arguments(code_arguments)
|
|
718
|
+
code_options = code_arguments.raw[1].to_code
|
|
719
|
+
return Nothing.new unless code_options.is_a?(Dictionary)
|
|
689
720
|
|
|
690
|
-
|
|
721
|
+
code_options.code_get(:locale)
|
|
691
722
|
end
|
|
692
723
|
|
|
693
724
|
def code_hour
|
data/lib/code/object/list.rb
CHANGED
|
@@ -160,6 +160,303 @@ class Code
|
|
|
160
160
|
when "first"
|
|
161
161
|
sig(args) { Integer.maybe }
|
|
162
162
|
code_first(code_value)
|
|
163
|
+
when "second"
|
|
164
|
+
sig(args)
|
|
165
|
+
code_second
|
|
166
|
+
when "third"
|
|
167
|
+
sig(args)
|
|
168
|
+
code_third
|
|
169
|
+
when "fourth"
|
|
170
|
+
sig(args)
|
|
171
|
+
code_fourth
|
|
172
|
+
when "fifth"
|
|
173
|
+
sig(args)
|
|
174
|
+
code_fifth
|
|
175
|
+
when "sixth"
|
|
176
|
+
sig(args)
|
|
177
|
+
code_sixth
|
|
178
|
+
when "seventh"
|
|
179
|
+
sig(args)
|
|
180
|
+
code_seventh
|
|
181
|
+
when "eighth"
|
|
182
|
+
sig(args)
|
|
183
|
+
code_eighth
|
|
184
|
+
when "ninth"
|
|
185
|
+
sig(args)
|
|
186
|
+
code_ninth
|
|
187
|
+
when "tenth"
|
|
188
|
+
sig(args)
|
|
189
|
+
code_tenth
|
|
190
|
+
when "eleventh"
|
|
191
|
+
sig(args)
|
|
192
|
+
code_eleventh
|
|
193
|
+
when "twelfth"
|
|
194
|
+
sig(args)
|
|
195
|
+
code_twelfth
|
|
196
|
+
when "thirteenth"
|
|
197
|
+
sig(args)
|
|
198
|
+
code_thirteenth
|
|
199
|
+
when "fourteenth"
|
|
200
|
+
sig(args)
|
|
201
|
+
code_fourteenth
|
|
202
|
+
when "fifteenth"
|
|
203
|
+
sig(args)
|
|
204
|
+
code_fifteenth
|
|
205
|
+
when "sixteenth"
|
|
206
|
+
sig(args)
|
|
207
|
+
code_sixteenth
|
|
208
|
+
when "seventeenth"
|
|
209
|
+
sig(args)
|
|
210
|
+
code_seventeenth
|
|
211
|
+
when "eighteenth"
|
|
212
|
+
sig(args)
|
|
213
|
+
code_eighteenth
|
|
214
|
+
when "nineteenth"
|
|
215
|
+
sig(args)
|
|
216
|
+
code_nineteenth
|
|
217
|
+
when "twentieth"
|
|
218
|
+
sig(args)
|
|
219
|
+
code_twentieth
|
|
220
|
+
when "twenty_first"
|
|
221
|
+
sig(args)
|
|
222
|
+
code_twenty_first
|
|
223
|
+
when "twenty_second"
|
|
224
|
+
sig(args)
|
|
225
|
+
code_twenty_second
|
|
226
|
+
when "twenty_third"
|
|
227
|
+
sig(args)
|
|
228
|
+
code_twenty_third
|
|
229
|
+
when "twenty_fourth"
|
|
230
|
+
sig(args)
|
|
231
|
+
code_twenty_fourth
|
|
232
|
+
when "twenty_fifth"
|
|
233
|
+
sig(args)
|
|
234
|
+
code_twenty_fifth
|
|
235
|
+
when "twenty_sixth"
|
|
236
|
+
sig(args)
|
|
237
|
+
code_twenty_sixth
|
|
238
|
+
when "twenty_seventh"
|
|
239
|
+
sig(args)
|
|
240
|
+
code_twenty_seventh
|
|
241
|
+
when "twenty_eighth"
|
|
242
|
+
sig(args)
|
|
243
|
+
code_twenty_eighth
|
|
244
|
+
when "twenty_ninth"
|
|
245
|
+
sig(args)
|
|
246
|
+
code_twenty_ninth
|
|
247
|
+
when "thirtieth"
|
|
248
|
+
sig(args)
|
|
249
|
+
code_thirtieth
|
|
250
|
+
when "thirty_first"
|
|
251
|
+
sig(args)
|
|
252
|
+
code_thirty_first
|
|
253
|
+
when "thirty_second"
|
|
254
|
+
sig(args)
|
|
255
|
+
code_thirty_second
|
|
256
|
+
when "thirty_third"
|
|
257
|
+
sig(args)
|
|
258
|
+
code_thirty_third
|
|
259
|
+
when "thirty_fourth"
|
|
260
|
+
sig(args)
|
|
261
|
+
code_thirty_fourth
|
|
262
|
+
when "thirty_fifth"
|
|
263
|
+
sig(args)
|
|
264
|
+
code_thirty_fifth
|
|
265
|
+
when "thirty_sixth"
|
|
266
|
+
sig(args)
|
|
267
|
+
code_thirty_sixth
|
|
268
|
+
when "thirty_seventh"
|
|
269
|
+
sig(args)
|
|
270
|
+
code_thirty_seventh
|
|
271
|
+
when "thirty_eighth"
|
|
272
|
+
sig(args)
|
|
273
|
+
code_thirty_eighth
|
|
274
|
+
when "thirty_ninth"
|
|
275
|
+
sig(args)
|
|
276
|
+
code_thirty_ninth
|
|
277
|
+
when "fortieth"
|
|
278
|
+
sig(args)
|
|
279
|
+
code_fortieth
|
|
280
|
+
when "forty_first"
|
|
281
|
+
sig(args)
|
|
282
|
+
code_forty_first
|
|
283
|
+
when "forty_second"
|
|
284
|
+
sig(args)
|
|
285
|
+
code_forty_second
|
|
286
|
+
when "forty_third"
|
|
287
|
+
sig(args)
|
|
288
|
+
code_forty_third
|
|
289
|
+
when "forty_fourth"
|
|
290
|
+
sig(args)
|
|
291
|
+
code_forty_fourth
|
|
292
|
+
when "forty_fifth"
|
|
293
|
+
sig(args)
|
|
294
|
+
code_forty_fifth
|
|
295
|
+
when "forty_sixth"
|
|
296
|
+
sig(args)
|
|
297
|
+
code_forty_sixth
|
|
298
|
+
when "forty_seventh"
|
|
299
|
+
sig(args)
|
|
300
|
+
code_forty_seventh
|
|
301
|
+
when "forty_eighth"
|
|
302
|
+
sig(args)
|
|
303
|
+
code_forty_eighth
|
|
304
|
+
when "forty_ninth"
|
|
305
|
+
sig(args)
|
|
306
|
+
code_forty_ninth
|
|
307
|
+
when "fiftieth"
|
|
308
|
+
sig(args)
|
|
309
|
+
code_fiftieth
|
|
310
|
+
when "fifty_first"
|
|
311
|
+
sig(args)
|
|
312
|
+
code_fifty_first
|
|
313
|
+
when "fifty_second"
|
|
314
|
+
sig(args)
|
|
315
|
+
code_fifty_second
|
|
316
|
+
when "fifty_third"
|
|
317
|
+
sig(args)
|
|
318
|
+
code_fifty_third
|
|
319
|
+
when "fifty_fourth"
|
|
320
|
+
sig(args)
|
|
321
|
+
code_fifty_fourth
|
|
322
|
+
when "fifty_fifth"
|
|
323
|
+
sig(args)
|
|
324
|
+
code_fifty_fifth
|
|
325
|
+
when "fifty_sixth"
|
|
326
|
+
sig(args)
|
|
327
|
+
code_fifty_sixth
|
|
328
|
+
when "fifty_seventh"
|
|
329
|
+
sig(args)
|
|
330
|
+
code_fifty_seventh
|
|
331
|
+
when "fifty_eighth"
|
|
332
|
+
sig(args)
|
|
333
|
+
code_fifty_eighth
|
|
334
|
+
when "fifty_ninth"
|
|
335
|
+
sig(args)
|
|
336
|
+
code_fifty_ninth
|
|
337
|
+
when "sixtieth"
|
|
338
|
+
sig(args)
|
|
339
|
+
code_sixtieth
|
|
340
|
+
when "sixty_first"
|
|
341
|
+
sig(args)
|
|
342
|
+
code_sixty_first
|
|
343
|
+
when "sixty_second"
|
|
344
|
+
sig(args)
|
|
345
|
+
code_sixty_second
|
|
346
|
+
when "sixty_third"
|
|
347
|
+
sig(args)
|
|
348
|
+
code_sixty_third
|
|
349
|
+
when "sixty_fourth"
|
|
350
|
+
sig(args)
|
|
351
|
+
code_sixty_fourth
|
|
352
|
+
when "sixty_fifth"
|
|
353
|
+
sig(args)
|
|
354
|
+
code_sixty_fifth
|
|
355
|
+
when "sixty_sixth"
|
|
356
|
+
sig(args)
|
|
357
|
+
code_sixty_sixth
|
|
358
|
+
when "sixty_seventh"
|
|
359
|
+
sig(args)
|
|
360
|
+
code_sixty_seventh
|
|
361
|
+
when "sixty_eighth"
|
|
362
|
+
sig(args)
|
|
363
|
+
code_sixty_eighth
|
|
364
|
+
when "sixty_ninth"
|
|
365
|
+
sig(args)
|
|
366
|
+
code_sixty_ninth
|
|
367
|
+
when "seventieth"
|
|
368
|
+
sig(args)
|
|
369
|
+
code_seventieth
|
|
370
|
+
when "seventy_first"
|
|
371
|
+
sig(args)
|
|
372
|
+
code_seventy_first
|
|
373
|
+
when "seventy_second"
|
|
374
|
+
sig(args)
|
|
375
|
+
code_seventy_second
|
|
376
|
+
when "seventy_third"
|
|
377
|
+
sig(args)
|
|
378
|
+
code_seventy_third
|
|
379
|
+
when "seventy_fourth"
|
|
380
|
+
sig(args)
|
|
381
|
+
code_seventy_fourth
|
|
382
|
+
when "seventy_fifth"
|
|
383
|
+
sig(args)
|
|
384
|
+
code_seventy_fifth
|
|
385
|
+
when "seventy_sixth"
|
|
386
|
+
sig(args)
|
|
387
|
+
code_seventy_sixth
|
|
388
|
+
when "seventy_seventh"
|
|
389
|
+
sig(args)
|
|
390
|
+
code_seventy_seventh
|
|
391
|
+
when "seventy_eighth"
|
|
392
|
+
sig(args)
|
|
393
|
+
code_seventy_eighth
|
|
394
|
+
when "seventy_ninth"
|
|
395
|
+
sig(args)
|
|
396
|
+
code_seventy_ninth
|
|
397
|
+
when "eightieth"
|
|
398
|
+
sig(args)
|
|
399
|
+
code_eightieth
|
|
400
|
+
when "eighty_first"
|
|
401
|
+
sig(args)
|
|
402
|
+
code_eighty_first
|
|
403
|
+
when "eighty_second"
|
|
404
|
+
sig(args)
|
|
405
|
+
code_eighty_second
|
|
406
|
+
when "eighty_third"
|
|
407
|
+
sig(args)
|
|
408
|
+
code_eighty_third
|
|
409
|
+
when "eighty_fourth"
|
|
410
|
+
sig(args)
|
|
411
|
+
code_eighty_fourth
|
|
412
|
+
when "eighty_fifth"
|
|
413
|
+
sig(args)
|
|
414
|
+
code_eighty_fifth
|
|
415
|
+
when "eighty_sixth"
|
|
416
|
+
sig(args)
|
|
417
|
+
code_eighty_sixth
|
|
418
|
+
when "eighty_seventh"
|
|
419
|
+
sig(args)
|
|
420
|
+
code_eighty_seventh
|
|
421
|
+
when "eighty_eighth"
|
|
422
|
+
sig(args)
|
|
423
|
+
code_eighty_eighth
|
|
424
|
+
when "eighty_ninth"
|
|
425
|
+
sig(args)
|
|
426
|
+
code_eighty_ninth
|
|
427
|
+
when "ninetieth"
|
|
428
|
+
sig(args)
|
|
429
|
+
code_ninetieth
|
|
430
|
+
when "ninety_first"
|
|
431
|
+
sig(args)
|
|
432
|
+
code_ninety_first
|
|
433
|
+
when "ninety_second"
|
|
434
|
+
sig(args)
|
|
435
|
+
code_ninety_second
|
|
436
|
+
when "ninety_third"
|
|
437
|
+
sig(args)
|
|
438
|
+
code_ninety_third
|
|
439
|
+
when "ninety_fourth"
|
|
440
|
+
sig(args)
|
|
441
|
+
code_ninety_fourth
|
|
442
|
+
when "ninety_fifth"
|
|
443
|
+
sig(args)
|
|
444
|
+
code_ninety_fifth
|
|
445
|
+
when "ninety_sixth"
|
|
446
|
+
sig(args)
|
|
447
|
+
code_ninety_sixth
|
|
448
|
+
when "ninety_seventh"
|
|
449
|
+
sig(args)
|
|
450
|
+
code_ninety_seventh
|
|
451
|
+
when "ninety_eighth"
|
|
452
|
+
sig(args)
|
|
453
|
+
code_ninety_eighth
|
|
454
|
+
when "ninety_ninth"
|
|
455
|
+
sig(args)
|
|
456
|
+
code_ninety_ninth
|
|
457
|
+
when "one_hundredth"
|
|
458
|
+
sig(args)
|
|
459
|
+
code_one_hundredth
|
|
163
460
|
when "sample"
|
|
164
461
|
sig(args) { Integer.maybe }
|
|
165
462
|
code_sample(code_value)
|
|
@@ -643,6 +940,406 @@ class Code
|
|
|
643
940
|
end
|
|
644
941
|
end
|
|
645
942
|
|
|
943
|
+
def code_nth(index)
|
|
944
|
+
raw[index] || Nothing.new
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
def code_second
|
|
948
|
+
code_nth(1)
|
|
949
|
+
end
|
|
950
|
+
|
|
951
|
+
def code_third
|
|
952
|
+
code_nth(2)
|
|
953
|
+
end
|
|
954
|
+
|
|
955
|
+
def code_fourth
|
|
956
|
+
code_nth(3)
|
|
957
|
+
end
|
|
958
|
+
|
|
959
|
+
def code_fifth
|
|
960
|
+
code_nth(4)
|
|
961
|
+
end
|
|
962
|
+
|
|
963
|
+
def code_sixth
|
|
964
|
+
code_nth(5)
|
|
965
|
+
end
|
|
966
|
+
|
|
967
|
+
def code_seventh
|
|
968
|
+
code_nth(6)
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
def code_eighth
|
|
972
|
+
code_nth(7)
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
def code_ninth
|
|
976
|
+
code_nth(8)
|
|
977
|
+
end
|
|
978
|
+
|
|
979
|
+
def code_tenth
|
|
980
|
+
code_nth(9)
|
|
981
|
+
end
|
|
982
|
+
|
|
983
|
+
def code_eleventh
|
|
984
|
+
code_nth(10)
|
|
985
|
+
end
|
|
986
|
+
|
|
987
|
+
def code_twelfth
|
|
988
|
+
code_nth(11)
|
|
989
|
+
end
|
|
990
|
+
|
|
991
|
+
def code_thirteenth
|
|
992
|
+
code_nth(12)
|
|
993
|
+
end
|
|
994
|
+
|
|
995
|
+
def code_fourteenth
|
|
996
|
+
code_nth(13)
|
|
997
|
+
end
|
|
998
|
+
|
|
999
|
+
def code_fifteenth
|
|
1000
|
+
code_nth(14)
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
def code_sixteenth
|
|
1004
|
+
code_nth(15)
|
|
1005
|
+
end
|
|
1006
|
+
|
|
1007
|
+
def code_seventeenth
|
|
1008
|
+
code_nth(16)
|
|
1009
|
+
end
|
|
1010
|
+
|
|
1011
|
+
def code_eighteenth
|
|
1012
|
+
code_nth(17)
|
|
1013
|
+
end
|
|
1014
|
+
|
|
1015
|
+
def code_nineteenth
|
|
1016
|
+
code_nth(18)
|
|
1017
|
+
end
|
|
1018
|
+
|
|
1019
|
+
def code_twentieth
|
|
1020
|
+
code_nth(19)
|
|
1021
|
+
end
|
|
1022
|
+
|
|
1023
|
+
def code_twenty_first
|
|
1024
|
+
code_nth(20)
|
|
1025
|
+
end
|
|
1026
|
+
|
|
1027
|
+
def code_twenty_second
|
|
1028
|
+
code_nth(21)
|
|
1029
|
+
end
|
|
1030
|
+
|
|
1031
|
+
def code_twenty_third
|
|
1032
|
+
code_nth(22)
|
|
1033
|
+
end
|
|
1034
|
+
|
|
1035
|
+
def code_twenty_fourth
|
|
1036
|
+
code_nth(23)
|
|
1037
|
+
end
|
|
1038
|
+
|
|
1039
|
+
def code_twenty_fifth
|
|
1040
|
+
code_nth(24)
|
|
1041
|
+
end
|
|
1042
|
+
|
|
1043
|
+
def code_twenty_sixth
|
|
1044
|
+
code_nth(25)
|
|
1045
|
+
end
|
|
1046
|
+
|
|
1047
|
+
def code_twenty_seventh
|
|
1048
|
+
code_nth(26)
|
|
1049
|
+
end
|
|
1050
|
+
|
|
1051
|
+
def code_twenty_eighth
|
|
1052
|
+
code_nth(27)
|
|
1053
|
+
end
|
|
1054
|
+
|
|
1055
|
+
def code_twenty_ninth
|
|
1056
|
+
code_nth(28)
|
|
1057
|
+
end
|
|
1058
|
+
|
|
1059
|
+
def code_thirtieth
|
|
1060
|
+
code_nth(29)
|
|
1061
|
+
end
|
|
1062
|
+
|
|
1063
|
+
def code_thirty_first
|
|
1064
|
+
code_nth(30)
|
|
1065
|
+
end
|
|
1066
|
+
|
|
1067
|
+
def code_thirty_second
|
|
1068
|
+
code_nth(31)
|
|
1069
|
+
end
|
|
1070
|
+
|
|
1071
|
+
def code_thirty_third
|
|
1072
|
+
code_nth(32)
|
|
1073
|
+
end
|
|
1074
|
+
|
|
1075
|
+
def code_thirty_fourth
|
|
1076
|
+
code_nth(33)
|
|
1077
|
+
end
|
|
1078
|
+
|
|
1079
|
+
def code_thirty_fifth
|
|
1080
|
+
code_nth(34)
|
|
1081
|
+
end
|
|
1082
|
+
|
|
1083
|
+
def code_thirty_sixth
|
|
1084
|
+
code_nth(35)
|
|
1085
|
+
end
|
|
1086
|
+
|
|
1087
|
+
def code_thirty_seventh
|
|
1088
|
+
code_nth(36)
|
|
1089
|
+
end
|
|
1090
|
+
|
|
1091
|
+
def code_thirty_eighth
|
|
1092
|
+
code_nth(37)
|
|
1093
|
+
end
|
|
1094
|
+
|
|
1095
|
+
def code_thirty_ninth
|
|
1096
|
+
code_nth(38)
|
|
1097
|
+
end
|
|
1098
|
+
|
|
1099
|
+
def code_fortieth
|
|
1100
|
+
code_nth(39)
|
|
1101
|
+
end
|
|
1102
|
+
|
|
1103
|
+
def code_forty_first
|
|
1104
|
+
code_nth(40)
|
|
1105
|
+
end
|
|
1106
|
+
|
|
1107
|
+
def code_forty_second
|
|
1108
|
+
code_nth(41)
|
|
1109
|
+
end
|
|
1110
|
+
|
|
1111
|
+
def code_forty_third
|
|
1112
|
+
code_nth(42)
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
def code_forty_fourth
|
|
1116
|
+
code_nth(43)
|
|
1117
|
+
end
|
|
1118
|
+
|
|
1119
|
+
def code_forty_fifth
|
|
1120
|
+
code_nth(44)
|
|
1121
|
+
end
|
|
1122
|
+
|
|
1123
|
+
def code_forty_sixth
|
|
1124
|
+
code_nth(45)
|
|
1125
|
+
end
|
|
1126
|
+
|
|
1127
|
+
def code_forty_seventh
|
|
1128
|
+
code_nth(46)
|
|
1129
|
+
end
|
|
1130
|
+
|
|
1131
|
+
def code_forty_eighth
|
|
1132
|
+
code_nth(47)
|
|
1133
|
+
end
|
|
1134
|
+
|
|
1135
|
+
def code_forty_ninth
|
|
1136
|
+
code_nth(48)
|
|
1137
|
+
end
|
|
1138
|
+
|
|
1139
|
+
def code_fiftieth
|
|
1140
|
+
code_nth(49)
|
|
1141
|
+
end
|
|
1142
|
+
|
|
1143
|
+
def code_fifty_first
|
|
1144
|
+
code_nth(50)
|
|
1145
|
+
end
|
|
1146
|
+
|
|
1147
|
+
def code_fifty_second
|
|
1148
|
+
code_nth(51)
|
|
1149
|
+
end
|
|
1150
|
+
|
|
1151
|
+
def code_fifty_third
|
|
1152
|
+
code_nth(52)
|
|
1153
|
+
end
|
|
1154
|
+
|
|
1155
|
+
def code_fifty_fourth
|
|
1156
|
+
code_nth(53)
|
|
1157
|
+
end
|
|
1158
|
+
|
|
1159
|
+
def code_fifty_fifth
|
|
1160
|
+
code_nth(54)
|
|
1161
|
+
end
|
|
1162
|
+
|
|
1163
|
+
def code_fifty_sixth
|
|
1164
|
+
code_nth(55)
|
|
1165
|
+
end
|
|
1166
|
+
|
|
1167
|
+
def code_fifty_seventh
|
|
1168
|
+
code_nth(56)
|
|
1169
|
+
end
|
|
1170
|
+
|
|
1171
|
+
def code_fifty_eighth
|
|
1172
|
+
code_nth(57)
|
|
1173
|
+
end
|
|
1174
|
+
|
|
1175
|
+
def code_fifty_ninth
|
|
1176
|
+
code_nth(58)
|
|
1177
|
+
end
|
|
1178
|
+
|
|
1179
|
+
def code_sixtieth
|
|
1180
|
+
code_nth(59)
|
|
1181
|
+
end
|
|
1182
|
+
|
|
1183
|
+
def code_sixty_first
|
|
1184
|
+
code_nth(60)
|
|
1185
|
+
end
|
|
1186
|
+
|
|
1187
|
+
def code_sixty_second
|
|
1188
|
+
code_nth(61)
|
|
1189
|
+
end
|
|
1190
|
+
|
|
1191
|
+
def code_sixty_third
|
|
1192
|
+
code_nth(62)
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1195
|
+
def code_sixty_fourth
|
|
1196
|
+
code_nth(63)
|
|
1197
|
+
end
|
|
1198
|
+
|
|
1199
|
+
def code_sixty_fifth
|
|
1200
|
+
code_nth(64)
|
|
1201
|
+
end
|
|
1202
|
+
|
|
1203
|
+
def code_sixty_sixth
|
|
1204
|
+
code_nth(65)
|
|
1205
|
+
end
|
|
1206
|
+
|
|
1207
|
+
def code_sixty_seventh
|
|
1208
|
+
code_nth(66)
|
|
1209
|
+
end
|
|
1210
|
+
|
|
1211
|
+
def code_sixty_eighth
|
|
1212
|
+
code_nth(67)
|
|
1213
|
+
end
|
|
1214
|
+
|
|
1215
|
+
def code_sixty_ninth
|
|
1216
|
+
code_nth(68)
|
|
1217
|
+
end
|
|
1218
|
+
|
|
1219
|
+
def code_seventieth
|
|
1220
|
+
code_nth(69)
|
|
1221
|
+
end
|
|
1222
|
+
|
|
1223
|
+
def code_seventy_first
|
|
1224
|
+
code_nth(70)
|
|
1225
|
+
end
|
|
1226
|
+
|
|
1227
|
+
def code_seventy_second
|
|
1228
|
+
code_nth(71)
|
|
1229
|
+
end
|
|
1230
|
+
|
|
1231
|
+
def code_seventy_third
|
|
1232
|
+
code_nth(72)
|
|
1233
|
+
end
|
|
1234
|
+
|
|
1235
|
+
def code_seventy_fourth
|
|
1236
|
+
code_nth(73)
|
|
1237
|
+
end
|
|
1238
|
+
|
|
1239
|
+
def code_seventy_fifth
|
|
1240
|
+
code_nth(74)
|
|
1241
|
+
end
|
|
1242
|
+
|
|
1243
|
+
def code_seventy_sixth
|
|
1244
|
+
code_nth(75)
|
|
1245
|
+
end
|
|
1246
|
+
|
|
1247
|
+
def code_seventy_seventh
|
|
1248
|
+
code_nth(76)
|
|
1249
|
+
end
|
|
1250
|
+
|
|
1251
|
+
def code_seventy_eighth
|
|
1252
|
+
code_nth(77)
|
|
1253
|
+
end
|
|
1254
|
+
|
|
1255
|
+
def code_seventy_ninth
|
|
1256
|
+
code_nth(78)
|
|
1257
|
+
end
|
|
1258
|
+
|
|
1259
|
+
def code_eightieth
|
|
1260
|
+
code_nth(79)
|
|
1261
|
+
end
|
|
1262
|
+
|
|
1263
|
+
def code_eighty_first
|
|
1264
|
+
code_nth(80)
|
|
1265
|
+
end
|
|
1266
|
+
|
|
1267
|
+
def code_eighty_second
|
|
1268
|
+
code_nth(81)
|
|
1269
|
+
end
|
|
1270
|
+
|
|
1271
|
+
def code_eighty_third
|
|
1272
|
+
code_nth(82)
|
|
1273
|
+
end
|
|
1274
|
+
|
|
1275
|
+
def code_eighty_fourth
|
|
1276
|
+
code_nth(83)
|
|
1277
|
+
end
|
|
1278
|
+
|
|
1279
|
+
def code_eighty_fifth
|
|
1280
|
+
code_nth(84)
|
|
1281
|
+
end
|
|
1282
|
+
|
|
1283
|
+
def code_eighty_sixth
|
|
1284
|
+
code_nth(85)
|
|
1285
|
+
end
|
|
1286
|
+
|
|
1287
|
+
def code_eighty_seventh
|
|
1288
|
+
code_nth(86)
|
|
1289
|
+
end
|
|
1290
|
+
|
|
1291
|
+
def code_eighty_eighth
|
|
1292
|
+
code_nth(87)
|
|
1293
|
+
end
|
|
1294
|
+
|
|
1295
|
+
def code_eighty_ninth
|
|
1296
|
+
code_nth(88)
|
|
1297
|
+
end
|
|
1298
|
+
|
|
1299
|
+
def code_ninetieth
|
|
1300
|
+
code_nth(89)
|
|
1301
|
+
end
|
|
1302
|
+
|
|
1303
|
+
def code_ninety_first
|
|
1304
|
+
code_nth(90)
|
|
1305
|
+
end
|
|
1306
|
+
|
|
1307
|
+
def code_ninety_second
|
|
1308
|
+
code_nth(91)
|
|
1309
|
+
end
|
|
1310
|
+
|
|
1311
|
+
def code_ninety_third
|
|
1312
|
+
code_nth(92)
|
|
1313
|
+
end
|
|
1314
|
+
|
|
1315
|
+
def code_ninety_fourth
|
|
1316
|
+
code_nth(93)
|
|
1317
|
+
end
|
|
1318
|
+
|
|
1319
|
+
def code_ninety_fifth
|
|
1320
|
+
code_nth(94)
|
|
1321
|
+
end
|
|
1322
|
+
|
|
1323
|
+
def code_ninety_sixth
|
|
1324
|
+
code_nth(95)
|
|
1325
|
+
end
|
|
1326
|
+
|
|
1327
|
+
def code_ninety_seventh
|
|
1328
|
+
code_nth(96)
|
|
1329
|
+
end
|
|
1330
|
+
|
|
1331
|
+
def code_ninety_eighth
|
|
1332
|
+
code_nth(97)
|
|
1333
|
+
end
|
|
1334
|
+
|
|
1335
|
+
def code_ninety_ninth
|
|
1336
|
+
code_nth(98)
|
|
1337
|
+
end
|
|
1338
|
+
|
|
1339
|
+
def code_one_hundredth
|
|
1340
|
+
code_nth(99)
|
|
1341
|
+
end
|
|
1342
|
+
|
|
646
1343
|
def code_sample(value = nil)
|
|
647
1344
|
code_value = value.to_code
|
|
648
1345
|
|
data/lib/code/object/time.rb
CHANGED
|
@@ -94,6 +94,7 @@ class Code
|
|
|
94
94
|
code_operator = args.fetch(:operator, nil).to_code
|
|
95
95
|
code_arguments = args.fetch(:arguments, []).to_code
|
|
96
96
|
code_value = code_arguments.code_first
|
|
97
|
+
code_second = code_arguments.code_second
|
|
97
98
|
|
|
98
99
|
case code_operator.to_s
|
|
99
100
|
when "after?"
|
|
@@ -187,8 +188,15 @@ class Code
|
|
|
187
188
|
sig(args)
|
|
188
189
|
code_sunday?
|
|
189
190
|
when "format"
|
|
190
|
-
sig(args) { String }
|
|
191
|
-
|
|
191
|
+
sig(args) { [String.maybe, { locale: String.maybe }] }
|
|
192
|
+
|
|
193
|
+
if code_value.is_a?(Dictionary)
|
|
194
|
+
code_format(nil, locale: code_value.code_get(:locale))
|
|
195
|
+
elsif code_second.something?
|
|
196
|
+
code_format(code_value, locale: code_second.code_get(:locale))
|
|
197
|
+
else
|
|
198
|
+
code_format(code_value)
|
|
199
|
+
end
|
|
192
200
|
when "january?"
|
|
193
201
|
sig(args)
|
|
194
202
|
code_january?
|
|
@@ -366,6 +374,7 @@ class Code
|
|
|
366
374
|
code_operator = args.fetch(:operator, nil).to_code
|
|
367
375
|
code_arguments = args.fetch(:arguments, []).to_code
|
|
368
376
|
code_value = code_arguments.code_first
|
|
377
|
+
code_second = code_arguments.code_second
|
|
369
378
|
|
|
370
379
|
case code_operator.to_s
|
|
371
380
|
when "after?"
|
|
@@ -456,8 +465,15 @@ class Code
|
|
|
456
465
|
sig(args)
|
|
457
466
|
code_sunday?
|
|
458
467
|
when "format"
|
|
459
|
-
sig(args) { String }
|
|
460
|
-
|
|
468
|
+
sig(args) { [String.maybe, { locale: String.maybe }] }
|
|
469
|
+
|
|
470
|
+
if code_value.is_a?(Dictionary)
|
|
471
|
+
code_format(nil, locale: code_value.code_get(:locale))
|
|
472
|
+
elsif code_second.something?
|
|
473
|
+
code_format(code_value, locale: code_second.code_get(:locale))
|
|
474
|
+
else
|
|
475
|
+
code_format(code_value)
|
|
476
|
+
end
|
|
461
477
|
when "january?"
|
|
462
478
|
sig(args)
|
|
463
479
|
code_january?
|
|
@@ -793,10 +809,18 @@ class Code
|
|
|
793
809
|
code_month.code_twelve?
|
|
794
810
|
end
|
|
795
811
|
|
|
796
|
-
def code_format(format)
|
|
812
|
+
def code_format(format, locale: nil)
|
|
797
813
|
code_format = format.to_code
|
|
814
|
+
code_locale = locale.to_code
|
|
815
|
+
|
|
816
|
+
requested_locale = code_locale.raw&.to_s
|
|
817
|
+
locale = requested_locale&.presence_in(LOCALES)&.to_sym || I18n.locale
|
|
818
|
+
locale = I18n.locale unless I18n.available_locales.include?(locale.to_sym)
|
|
819
|
+
|
|
820
|
+
format = code_format.raw || :default
|
|
821
|
+
format = format.to_sym if I18n.exists?("time.formats.#{format}", locale)
|
|
798
822
|
|
|
799
|
-
String.new(
|
|
823
|
+
String.new(I18n.l(raw, format: format, locale: locale))
|
|
800
824
|
end
|
|
801
825
|
|
|
802
826
|
def code_today
|
data/lib/code.rb
CHANGED
data/spec/code/format_spec.rb
CHANGED
|
@@ -17,7 +17,7 @@ RSpec.describe Code::Format do
|
|
|
17
17
|
["[1,2,3]", "[1, 2, 3]"],
|
|
18
18
|
[
|
|
19
19
|
"[1, 2, 3].select { |n| n.even? }",
|
|
20
|
-
"[1, 2, 3].select { |n
|
|
20
|
+
"[1, 2, 3].select { |n| n.even? }"
|
|
21
21
|
],
|
|
22
22
|
[
|
|
23
23
|
"if true 1 elsif false 2 else 3 end",
|
|
@@ -29,7 +29,7 @@ RSpec.describe Code::Format do
|
|
|
29
29
|
],
|
|
30
30
|
[
|
|
31
31
|
"Http.post(\"https://api.openai.com/v1/chat/completions\", headers: { authorization: \"Bearer {open_ai_api_key}\", \"content-type\": \"application/json\" }, body: { model: model, messages: [{ role: \"system\", content: \"hello\" }, { role: \"user\", content: \"world\" }] }.to_json)",
|
|
32
|
-
"Http.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers: {\n authorization: \"Bearer {open_ai_api_key}\",\n \"content-type\": \"application/json\"\n },\n body: {\n model: model,\n messages: [\n { role:
|
|
32
|
+
"Http.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers: {\n authorization: \"Bearer {open_ai_api_key}\",\n \"content-type\": \"application/json\"\n },\n body: {\n model: model,\n messages: [\n { role: :system, content: :hello },\n { role: :user, content: :world }\n ]\n }.to_json\n)"
|
|
33
33
|
]
|
|
34
34
|
].each do |input, expected|
|
|
35
35
|
it "formats #{input.inspect}" do
|
|
@@ -8,6 +8,10 @@ RSpec.describe Code::Object::List do
|
|
|
8
8
|
["[1, 2, 3].sum", "6"],
|
|
9
9
|
["[1, 2] + [3, 4]", "[1, 2, 3, 4]"],
|
|
10
10
|
["[] + []", "[]"],
|
|
11
|
+
["[1, 2, 3].second", "2"],
|
|
12
|
+
["[1, 2, 3].third", "3"],
|
|
13
|
+
["(1..100).to_list.one_hundredth", "100"],
|
|
14
|
+
["[1, 2, 3].one_hundredth", "nothing"]
|
|
11
15
|
].each do |input, expected|
|
|
12
16
|
it "#{input} == #{expected}" do
|
|
13
17
|
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
data/spec/code_spec.rb
CHANGED
|
@@ -248,7 +248,9 @@ RSpec.describe Code do
|
|
|
248
248
|
%w[Class.new(nothing) Nothing],
|
|
249
249
|
%w[Class.new(true) Boolean],
|
|
250
250
|
%w[Date Date],
|
|
251
|
+
["Date.format == Date.format(:default)", "true"],
|
|
251
252
|
%w[Date("0001-01-01").to_string :0001-01-01],
|
|
253
|
+
["Date(\"2024-03-02\").format == Date(\"2024-03-02\").format(:default)", "true"],
|
|
252
254
|
%w[Date("2024-03-02").to_string :2024-03-02],
|
|
253
255
|
%w[Decimal(1) 1.0],
|
|
254
256
|
%w[Decimal(1) 1],
|
|
@@ -296,6 +298,10 @@ RSpec.describe Code do
|
|
|
296
298
|
["Class.new(Time, Boolean)", "Time"],
|
|
297
299
|
%w[Date("2024-3-2").to_string :2024-03-02],
|
|
298
300
|
%w[Date("2024-3-2").to_string :2024-03-02],
|
|
301
|
+
["Time.format.present?", "true"],
|
|
302
|
+
["Class(Time.format(locale: :fr))", "String"],
|
|
303
|
+
["Time.new(\"2024-03-05.06:10:59.UTC\").format(locale: :fr) == Time.new(\"2024-03-05.06:10:59.UTC\").format(:default, locale: :fr)", "true"],
|
|
304
|
+
["Time.new(\"2024-03-05.06:10:59.UTC\").format == Time.new(\"2024-03-05.06:10:59.UTC\").format(:default)", "true"],
|
|
299
305
|
["Decimal(1, :2)", "100"],
|
|
300
306
|
["Decimal(:1, 2)", "100.0"],
|
|
301
307
|
["Decimal.new(1, :2)", "100"],
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: code-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.9.
|
|
4
|
+
version: 1.9.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dorian Marié
|
|
@@ -351,7 +351,6 @@ files:
|
|
|
351
351
|
- spec/code/object/nothing_spec.rb
|
|
352
352
|
- spec/code/object/range_spec.rb
|
|
353
353
|
- spec/code/object/string_spec.rb
|
|
354
|
-
- spec/code/object/time_spec.rb
|
|
355
354
|
- spec/code/parser/boolean_spec.rb
|
|
356
355
|
- spec/code/parser/chained_call_spec.rb
|
|
357
356
|
- spec/code/parser/dictionary_spec.rb
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe Code::Object::Time do
|
|
6
|
-
[
|
|
7
|
-
['Time.new(1).format("%s")', ":1"],
|
|
8
|
-
['Time.new(1100042342).format("%s")', ":1100042342"],
|
|
9
|
-
['Time.new(1.2).format("%s.%L")', '"1.200"'],
|
|
10
|
-
['Time.new(11212.1212).format("%s.%L")', '"11212.121"']
|
|
11
|
-
].each do |input, expected|
|
|
12
|
-
it "#{input} == #{expected}" do
|
|
13
|
-
expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|