code-ruby 1.9.1 → 1.9.2

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: 6fa3d1843b2e8b0c48e77e0ebee8f777b600e3a394a6037abc4efac105fc675b
4
- data.tar.gz: bf34f84603acd5949f0b66cc77ec0a05da8785fb27f98a82dcb9688f31dcd3d0
3
+ metadata.gz: 3f549a94b79e05b4a9bcdaccb20f8aac62c12d0df2126be010cdd8837500b48c
4
+ data.tar.gz: 96d615d2927a7f25c35151ceb3c574bcaad56f47e9e3a127363421840a467cc9
5
5
  SHA512:
6
- metadata.gz: 322e53da06d327556582256fd4337873ab5f1cdeb406abcc03812d7c9f2180edfb266d6114d77e49249055d3a8ff55ce89b30326432c5bc19aa53dbe13609641
7
- data.tar.gz: 89eb23ea7ede87aa9dbb46f8ba758a570cc1ac7a259981c663bc093c860bb78f76c4085c0e25c366604895fda5a039f3c166edbf7a61138b167170f342916f1c
6
+ metadata.gz: ca729f38f8dbed018a444f541fa18630df17fc53c0638041279c308a7a7867fb1f22a1d7dfca279f120868e6fbb12cbf50651c4247e95d2c504ceb70353936d1
7
+ data.tar.gz: 41d3ce239359a6df336152f4a4fada3e5526549abe7a27e2cb929ecb46cb4319f36a248395ccca258aadb3be0d5ff80c86c3f8749ece21cb776b59174870ff43
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.9.1)
4
+ code-ruby (1.9.2)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.1
1
+ 1.9.2
@@ -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,13 @@ class Code
96
97
  sig(args)
97
98
  code_future?
98
99
  when "format"
99
- sig(args) { String }
100
- code_format(code_value)
100
+ sig(args) { [String, { locale: String.maybe }] }
101
+
102
+ if code_second.something?
103
+ code_format(code_value, locale: code_second.code_get(:locale))
104
+ else
105
+ code_format(code_value)
106
+ end
101
107
  when "tomorrow"
102
108
  sig(args)
103
109
  code_tomorrow
@@ -323,6 +329,7 @@ class Code
323
329
  code_operator = args.fetch(:operator, nil).to_code
324
330
  code_arguments = args.fetch(:arguments, []).to_code
325
331
  code_value = code_arguments.code_first
332
+ code_second = code_arguments.code_second
326
333
 
327
334
  case code_operator.to_s
328
335
  when "after?"
@@ -407,8 +414,13 @@ class Code
407
414
  sig(args)
408
415
  code_sunday?
409
416
  when "format"
410
- sig(args) { String }
411
- code_format(code_value)
417
+ sig(args) { [String, { locale: String.maybe }] }
418
+
419
+ if code_second.something?
420
+ code_format(code_value, locale: code_second.code_get(:locale))
421
+ else
422
+ code_format(code_value)
423
+ end
412
424
  when "january?"
413
425
  sig(args)
414
426
  code_january?
@@ -684,10 +696,23 @@ class Code
684
696
  code_month.code_twelve?
685
697
  end
686
698
 
687
- def code_format(format)
699
+ def code_format(format, locale: nil)
688
700
  code_format = format.to_code
701
+ code_locale = locale.to_code
702
+
703
+ locale = code_locale.raw.presence_in(LOCALES) || I18n.locale
704
+
705
+ format = code_format.raw
706
+ format = format.to_sym if I18n.exists?("date.formats.#{format}", locale)
707
+
708
+ String.new(I18n.l(raw, format: format, locale: locale))
709
+ end
710
+
711
+ def code_format_locale_from_arguments(code_arguments)
712
+ code_options = code_arguments.raw[1].to_code
713
+ return Nothing.new unless code_options.is_a?(Dictionary)
689
714
 
690
- String.new(raw.strftime(code_format.raw))
715
+ code_options.code_get(:locale)
691
716
  end
692
717
 
693
718
  def code_hour
@@ -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
 
@@ -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,13 @@ class Code
187
188
  sig(args)
188
189
  code_sunday?
189
190
  when "format"
190
- sig(args) { String }
191
- code_format(code_value)
191
+ sig(args) { [String, { locale: String.maybe }] }
192
+
193
+ if code_second.something?
194
+ code_format(code_value, locale: code_second.code_get(:locale))
195
+ else
196
+ code_format(code_value)
197
+ end
192
198
  when "january?"
193
199
  sig(args)
194
200
  code_january?
@@ -366,6 +372,7 @@ class Code
366
372
  code_operator = args.fetch(:operator, nil).to_code
367
373
  code_arguments = args.fetch(:arguments, []).to_code
368
374
  code_value = code_arguments.code_first
375
+ code_second = code_arguments.code_second
369
376
 
370
377
  case code_operator.to_s
371
378
  when "after?"
@@ -456,8 +463,13 @@ class Code
456
463
  sig(args)
457
464
  code_sunday?
458
465
  when "format"
459
- sig(args) { String }
460
- code_format(code_value)
466
+ sig(args) { [String, { locale: String.maybe }] }
467
+
468
+ if code_second.something?
469
+ code_format(code_value, locale: code_second.code_get(:locale))
470
+ else
471
+ code_format(code_value)
472
+ end
461
473
  when "january?"
462
474
  sig(args)
463
475
  code_january?
@@ -793,10 +805,16 @@ class Code
793
805
  code_month.code_twelve?
794
806
  end
795
807
 
796
- def code_format(format)
808
+ def code_format(format, locale: nil)
797
809
  code_format = format.to_code
810
+ code_locale = locale.to_code
811
+
812
+ locale = code_locale.raw.presence_in(LOCALES) || I18n.locale
813
+
814
+ format = code_format.raw
815
+ format = format.to_sym if I18n.exists?("time.formats.#{format}", locale)
798
816
 
799
- String.new(raw.strftime(code_format.raw))
817
+ String.new(I18n.l(raw, format: format, locale: locale))
800
818
  end
801
819
 
802
820
  def code_today
data/lib/code.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  class Code
4
4
  GLOBALS = %i[context error input object output source].freeze
5
5
  DEFAULT_TIMEOUT = 0
6
+ LOCALES = %w[en fr].freeze
6
7
 
7
8
  def initialize(
8
9
  source,
@@ -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|\n n.even?\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: \"system\", content: \"hello\" },\n { role: \"user\", content: \"world\" }\n ]\n }.to_json\n)"
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))
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.1
4
+ version: 1.9.2
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