/
parse_test.rb
1897 lines (1664 loc) · 70 KB
/
parse_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require_relative 'test_helpers/test_helper'
require 'reading'
class ParseTest < Minitest::Test
using Reading::Util::HashDeepMerge
using Reading::Util::HashArrayDeepFetch
self.class.attr_reader :inputs, :outputs
def inputs = self.class.inputs
def outputs = self.class.outputs
# ==== INPUT
@inputs = {}
## INPUT: ENABLING COLUMNS
# In the columns tests, the input in the heredocs below are each parsed with
# only the columns enabled that are listed in the hash key. This tests basic
# functionality of each column, and a few possible combinations of columns.
@inputs[:enabled_columns] = {}
@inputs[:enabled_columns][:"head"] = <<~EOM.freeze
\\Author - Title
Sapiens
Goatsong
How To
EOM
@inputs[:enabled_columns][:"head, end_dates"] = <<~EOM.freeze
\\Author - Title|End dates
Sapiens
Goatsong|2020/5/30
How To
EOM
@inputs[:enabled_columns][:"head, start_dates"] = <<~EOM.freeze
Sapiens|2021/9/1
Goatsong|2020/5/1
How To
EOM
@inputs[:enabled_columns][:"head, start_dates, end_dates"] = <<~EOM.freeze
Sapiens|2021/9/1
Goatsong|2020/5/1|2020/5/30
How To
EOM
@inputs[:enabled_columns][:"rating, head, start_dates, end_dates"] = <<~EOM.freeze
|Sapiens|2021/9/1
5|Goatsong|2020/5/1|2020/5/30
|How To
EOM
# length but no sources
@inputs[:enabled_columns][:"rating, head, start_dates, end_dates, length"] = <<~EOM.freeze
|Sapiens|2021/9/1||15:17
5|Goatsong|2020/5/1|2020/5/30|247
|How To
EOM
# sources but no length
@inputs[:enabled_columns][:"rating, head, sources, start_dates, end_dates"] = <<~EOM.freeze
|Sapiens|Vail Library B00ICN066A|2021/9/1
5|Goatsong|0312038380|2020/5/1|2020/5/30
|How To
EOM
# sources and length
@inputs[:enabled_columns][:"rating, head, sources, start_dates, end_dates, length"] = <<~EOM.freeze
|Sapiens|Vail Library B00ICN066A|2021/9/1||15:17
5|Goatsong|0312038380|2020/5/1|2020/5/30|247
|How To
EOM
## INPUT: FEATURES OF SINGLE COLUMNS
# In each the features tests, a single column is enabled (specified in the
# hash key) and a bunch of possible content for that column is tested. These
# are the columns that are more flexible and can have lots of information
# crammed into them.
@inputs[:features_head] =
{
:"author" =>
"Tom Holt - Goatsong",
:"series" =>
"Tom Holt - Goatsong -- in The Walled Orchard",
:"series with volume" =>
"Tom Holt - Goatsong -- The Walled Orchard, #1",
:"multiple series" =>
"Tom Holt - Goatsong -- in Holt Historical Fiction -- The Walled Orchard, #1",
:"extra info" =>
"Tom Holt - Goatsong -- paperback -- 1990",
:"extra info and series" =>
"Tom Holt - Goatsong -- paperback -- The Walled Orchard, #1 -- 1990",
:"format" =>
"📕Tom Holt - Goatsong",
:"multi items" =>
"📕Tom Holt - Goatsong, 🔊Sapiens",
:"multi items without a comma" =>
"📕Tom Holt - Goatsong 🔊Sapiens",
:"multi items with a long separator" =>
"📕Tom Holt - Goatsong -- 🔊Sapiens",
:"progress" =>
"50% 📕Tom Holt - Goatsong",
:"progress pages" =>
"p220 📕Tom Holt - Goatsong",
:"progress pages without p" =>
"220 📕Tom Holt - Goatsong",
:"progress time" =>
"2:30 📕Tom Holt - Goatsong",
:"dnf in head" =>
"DNF 📕Tom Holt - Goatsong",
:"other string in head is ignored" =>
"maybe will DNF 📕Tom Holt - Goatsong",
:"dnf in head with progress" =>
"DNF 50% 📕Tom Holt - Goatsong",
:"dnf with multi items" =>
"DNF 📕Tom Holt - Goatsong, 🔊Sapiens",
:"all features" =>
"DNF 50% 📕Tom Holt - Goatsong -- paperback -- The Walled Orchard, #1 -- 1990, 🔊Sapiens"
}
# DEFAULT_TITLE (plus a column separator) are added to the beginning of each
# input string in the features included in INPUTS_WITH_DEFAULT_TITLE, except
# in input strings where a custom Head column is provided.
# This is to avoid having to include a Head column in every input string below,
# since the Head column is not optional.
DEFAULT_TITLE = "Default"
INPUTS_WITH_DEFAULT_TITLE = [
:features_sources,
:features_start_dates,
:features_history,
:"features_length, history"
]
@inputs[:features_sources] =
{
:"ISBN-10" =>
"0312038380",
:"ISBN-13" =>
"978-0312038380",
:"ASIN" =>
"B00GVG01HE",
:"source" =>
"Little Library",
:"URL source" =>
"https://www.edlin.org/holt",
:"URL source with a name from config" =>
"https://archive.org/details/walledorchard0000holt",
:"multiple sources must be separated with commas" =>
"Little Library, https://www.edlin.org/holt, https://tomholt.com, Lexpub",
:"source with ISBN" =>
"Little Library 0312038380",
:"source with ISBN-10 ending in X" =>
"Little Library 031203838X",
:"sources with ISBN" =>
"Little Library, https://www.edlin.org/holt, https://tomholt.com, Lexpub 0312038380",
:"comma not required before and after URL source" =>
"Little Library https://www.edlin.org/holt https://tomholt.com Lexpub 0312038380",
:"simple variants" =>
"📕Little Library 📕Lexpub",
:"variant with extra info" =>
"📕Little Library -- paperback -- 1990 🔊Lexpub",
:"optional long separator can be added between variants" =>
"📕Little Library -- paperback -- 1990 🔊Lexpub",
:"variant with extra info and series" =>
"📕Little Library -- paperback -- The Walled Orchard, #1 -- 1990 🔊Lexpub",
:"variant with extra info and series from Head also" =>
"#{DEFAULT_TITLE} -- in Holt's Classical Novels -- unabridged|📕Little Library -- paperback -- The Walled Orchard, #1 -- 1990 🔊Lexpub",
:"length after sources ISBN and before extra info" =>
"📕Little Library 0312038380 247 -- paperback -- 1990 🔊Lexpub 7:03",
:"multiple sources allowed in variant" =>
"📕Little Library, https://www.edlin.org/holt, https://tomholt.com, Lexpub 0312038380 247 -- paperback -- 1990 🔊Lexpub 7:03",
:"optional commas can be added within and between variants" =>
"📕Little Library, https://www.edlin.org/holt, https://tomholt.com, Lexpub, 0312038380, 247 -- paperback -- 1990, 🔊Lexpub 7:03",
}
@inputs[:features_start_dates] =
{
:"start date" =>
"2020/09/01",
:"start dates" =>
"2020/09/01, 2021/07/15",
:"planned after a start date" =>
"2020/09/01, ??",
:"planned only" =>
"??",
:"progress" =>
"50% 2020/09/01",
:"progress pages" =>
"220p 2020/09/01",
:"progress pages without p" =>
"220 2020/09/01",
:"progress time" =>
"2:30 2020/09/01",
:"dnf default zero" =>
"DNF 2020/09/01",
:"dnf with progress" =>
"DNF 50% 2020/09/01",
:"dnf only" =>
"DNF 50%",
:"variant" =>
"2020/09/01 v2",
:"variant only" =>
"v2",
:"group" =>
"2020/09/01 v2 🤝🏼 county book club",
:"group only" =>
"🤝🏼 county book club",
:"all features" =>
"DNF 50% 2020/09/01 v2, 2:30 2021/07/15",
}
# The compact_planned part (unlike in other :features_x) is merely semantic;
# it has no effect in set_config_columns below.
@inputs[:features_compact_planned] =
{
:"title only" =>
"\\⚡A Song for Nero",
:"with author" =>
"\\⚡Tom Holt - A Song for Nero",
:"with sources" =>
"\\⚡Tom Holt - A Song for Nero @Lexpub @Hoopla",
:"with sources in the Sources column" =>
"\\⚡Tom Holt - A Song for Nero|Lexpub, Hoopla",
:"with Sources and Length column" =>
"\\⚡Tom Holt - A Song for Nero|Lexpub, Hoopla|239",
:"with only Length column" =>
"\\⚡Tom Holt - A Song for Nero|239",
:"with fuller Head and Sources columns" =>
"\\⚡Tom Holt - A Song for Nero -- unabridged -- in Holt's Classical Novels|Lexpub, Hoopla B00GW4U2TM",
:"with sources and extra info" =>
"\\⚡Tom Holt - A Song for Nero @Lexpub @Hoopla -- unabridged -- in Holt's Classical Novels",
:"multiple" =>
"\\⚡Tom Holt - A Song for Nero @Lexpub @Hoopla 🔊True Grit @Lexpub",
:"multiple with source" =>
"\\@Lexpub: ⚡Tom Holt - A Song for Nero @Hoopla 🔊True Grit",
:"multiple with genre" =>
"\\HISTORICAL FICTION: ⚡Tom Holt - A Song for Nero @Lexpub @Hoopla 🔊True Grit @Lexpub",
:"multiple with multiple genres" =>
"\\HISTORICAL FICTION, FAVES: ⚡Tom Holt - A Song for Nero @Lexpub @Hoopla 🔊True Grit @Lexpub",
:"multiple with genre plus source" =>
"\\HISTORICAL FICTION @Lexpub: ⚡Tom Holt - A Song for Nero @Hoopla 🔊True Grit",
:"duplicate sources are ignored" =>
"\\HISTORICAL FICTION @Lexpub: ⚡Tom Holt - A Song for Nero @Hoopla @Lexpub @Hoopla 🔊True Grit @Lexpub",
:"multiple sources at the beginning" =>
"\\HISTORICAL FICTION @Lexpub @https://www.lexpublib.org: ⚡Tom Holt - A Song for Nero 🔊True Grit",
:"config-defined emojis are ignored" =>
"\\❓HISTORICAL FICTION @Lexpub:⚡💲Tom Holt - A Song for Nero ✅@Hoopla ✅🔊True Grit",
}
@inputs[:features_history] =
{
:"dates" =>
"2021/12/6 0:30 -- 12/21 -- 3/1",
:"dates can omit unchanged month" =>
"2021/12/6 0:30 -- 21 -- 3/1",
:"date ranges" =>
"2021/12/6..8 0:30 -- 12/21 -- 3/1",
:"adjacent dates of same daily amount are merged into a range" => # of 12/6..10
"2021/12/6..8 1:30 -- 12/9 0:30 -- 12/10",
:"time amounts" =>
"2021/12/6..8 0:35 -- 12/21 0:45 -- 3/1 0:45",
:"implied time amount" => # 3/1 has an implied amount of 0:45
"2021/12/6..8 0:35 -- 12/21 0:45 -- 3/1",
# Here 0:45 has an implied date of 12/9, and 0:30 also has an implied date of
# 12/9 (the implied date doesn't increment except after a range), so the 0:30
# overwrites the 0:45 on 12/9.
:"implied dates" =>
"2021/12/6..8 0:35 -- 0:45 -- 0:30",
:"implied date range starts" => # same as 12/6, 12/7..8, 12/9..10
"2021/12/6 0:35 -- ..12/8 0:45 -- ..12/10 0:25",
:"implied date range end" => # Date.today becomes the end date
"2021/12/6.. 0:35",
:"implied date range start and end" => # same as 12/6, 12/7..
"2021/12/6 0:35 -- .. 0:45",
:"open range" =>
"2021/12/6.. 0:35 -- 0:25 -- ..12/13",
:"open range with repeated name (re-listen)" =>
"2021/12/6.. 0:35 #1 -- 0:25 #2 -- ..12/13 #1",
:"open range with dates in the middle" =>
"2021/12/6.. 0:35 -- 0:25 -- 12/9..10 0:45 -- ..13",
:"open range with implied end" => # implies ..12/8 0:25
"2021/12/6.. 0:35 -- 0:25 -- 12/9..10 0:45",
:"repetition" =>
"2021/12/6 0:30 x4 -- 12/7 x2",
:"frequency" =>
"2021/12/6..6/1 0:30 x1/month",
:"frequency x1 implied" =>
"2021/12/6..6/1 0:30/month",
:"frequency until present" =>
"2021/12/6..6/1 0:30/month -- .. x2/month",
:"frequency implied until present" =>
"2021/12/6..6/1 0:30/month -- x2/month",
:"previous repetition and frequency apply when amount and progress are omitted" =>
"2021/12/6..6/1 0:30 x2/month -- 7/1..12/25",
:"exception list" =>
"2021/12/27..1/8 1:00/day -- not 12/28..29, 1/1, ",
:"exception list can be an open range at the end" =>
"2022/09/24.. 1:00/day -- not 9/25..26 -- 9/28.. 2:00/day -- not 9/30..",
# 13:00 here gives the same result as 1:00/day, though it's unexpected. We
# would expect that over these 10 days (not counting the exception days),
# 10:00 means 1:00/day. However, the amounts are distributed across the days
# *before* the exception days are removed, i.e. 13:00 across 13 days means
# 1:00/day. I don't use exception lists with fixed amounts, so I don't feel it
# would be worth the extra complexity to make exception lists recalculate
# amount-per-day in cases of a fixed amount. So this is a feature, not a bug ;)
:"exception list doesn't work as expected with fixed amount" =>
"2021/12/27..1/8 13:00 -- not 12/28..29, 1/1",
:"overwriting" =>
"2021/12/27..1/8 1:00/day -- not 12/28..29, 1/1 -- (1/4..8 2:00/day)",
:"overwriting can omit parentheses" =>
"2021/12/27..1/8 1:00/day -- not 12/28..29, 1/1 -- 1/4..8 2:00/day",
# "x0" may produce different results than "not" because "x0" is carried over to the omitted days.
:"overwriting to zero does not have the same effect" =>
"2021/12/27..1/8 1:00/day -- (2021/12/28..29 x0) -- (1/1 x0)",
:"names" =>
"2021/12/6..8 0:35 #1 Why Ruby2JS is a Game Changer -- 12/21 0:45 #2 Componentized View Architecture FTW! -- 3/1 #3 String-Based Templates vs. DSLs",
:"repeated name means re-listen" =>
"2021/12/6..8 0:35 #1 Why Ruby2JS is a Game Changer -- 12/21 0:45 #2 Componentized View Architecture FTW! -- 3/1 #3 String-Based Templates vs. DSLs -- 5/1 0:35 #1 Why Ruby2JS is a Game Changer",
:"favorites" =>
"2021/12/6..8 0:35 ⭐#1 Why Ruby2JS is a Game Changer -- 12/21 0:45 ⭐#2 Componentized View Architecture FTW! -- 3/1 #3 String-Based Templates vs. DSLs",
:"multiple experiences" =>
"2021/12/6 0:30 ---- 2022/4/1 0:30",
:"variant" =>
"2021/12/6 0:30 ---- v2 2022/4/1 0:30",
:"group" =>
"2021/12/6 0:30 ---- 🤝🏼with Sam 2022/4/1 0:30",
:"planned" =>
"2021/12/6..8 0:35 #1 Why Ruby2JS is a Game Changer -- 12/21 0:45 #2 Componentized View Architecture FTW! -- ?? #3 String-Based Templates vs. DSLs",
:"planned in middle" =>
"2021/12/6..8 0:35 #1 Why Ruby2JS is a Game Changer -- ?? 0:45 #2 Componentized View Architecture FTW! -- #3 String-Based Templates vs. DSLs -- 4/18 #4 Design Patterns on the Frontend",
:"DNF" =>
"2021/12/6..8 DNF 50% 0:35 #1 Why Ruby2JS is a Game Changer -- 12/21 DNF @0:15 0:45 #2 Componentized View Architecture FTW! -- 3/1 DNF 0:45 #3 String-Based Templates vs. DSLs",
:"progress without DNF" =>
"2021/12/6..8 50% 0:35 #1 Why Ruby2JS is a Game Changer -- 12/21 @0:15 0:45 #2 Componentized View Architecture FTW! -- 3/1 @0 0:45 #3 String-Based Templates vs. DSLs",
:"pages amount" =>
"2021/04/28 10p",
:"pages amount without p" =>
"2021/04/28 10",
:"stopping points in place of amount" =>
"2021/04/28 10p -- 4/30 @20p -- 5/1 @30p",
:"stopping point with p on other side or omitted" =>
"2021/04/28 10p -- 4/30 @p20 -- 5/1 @30",
}
@inputs[:"features_length, history"] =
{
:"length of each" =>
"0:30 each|2021/12/6 -- 12/21 0:45 -- 3/1",
:"repetitions in length" =>
"0:30 x3|2021/12/6 -- 12/21 -- 3/1",
:"repetitions in length with 'each'" =>
"0:30 each x3|2021/12/6 -- 12/21 -- 3/1",
:"done shortcut with length" =>
"144|2021/04/28 10p -- 4/30 @20p -- 5/1 @30p -- ..5/20 done",
}
## INPUT: ALL COLUMNS
# For interactions between columns that are not caught in the single-column
# tests above. Also for realistic examples from the reading.csv template:
# https://github.com/fpsvogel/reading/blob/main/doc/reading.csv
@inputs[:all_columns] =
{
:"empty Sources column doesn't prevent variant from elsewhere" =>
"|📕Sapiens||2020/09/01",
:"default span amount is the correct length via variants" =>
"|Goatsong|📕Little Library 0312038380 247 -- paperback -- 1990 🔊Lexpub 7:03|2020/09/01",
}
@inputs[:all_columns][:"custom config: listening speed"] = <<~EOM.freeze
\\{ speed: { format: { audiobook: 1.5, audio: 2 } } }
|🔊Dracula|||||9:00
|🎤Flightless Bird|||||||2022/8/1 10:00
EOM
@inputs[:all_columns][:"realistic examples: in progress books"] = <<~EOM.freeze
\\Rating|Format, Author, Title|Sources, ISBN/ASIN|Start dates, Progress|End dates|Genres|Length|Notes|History
\\------ IN PROGRESS
|🔊Sapiens: A Brief History of Humankind|Hoopla B00ICN066A|2021/09/20||history|15:17|Easy to criticize, but I like the emphasis on human happiness. -- Ch. 5: "We did not domesticate wheat. It domesticated us." -- Discussion of that point: https://www.reddit.com/r/AskHistorians/comments/2ttpn2
5|📕Tom Holt - Goatsong|Lexpub 0312038380|2019/05/28, 2020/05/01|2019/06/13|history, fiction|247
EOM
@inputs[:all_columns][:"realistic examples: done"] = <<~EOM.freeze
\\------ DONE
4|📕Robert Louis Stevenson - Insula Thesauraria -- in Mount Hope Classics -- trans. Arcadius Avellanus|1533694567|2020/10/20 🤝🏼Latin reading group|2021/08/31|latin, fiction|260
2|DNF 50% 🔊Total Cat Mojo|gift from neighbor Edith B01NCYY3BV|2020/03/21|2020/04/01|cats|10:13|🔒I would've felt bad if I hadn't tried.
1|DNF 🎤FiveThirtyEight Politics 🎤The NPR Politics Podcast 🎤Pod Save America||2021/08/02|2021/08/02|politics, podcast|0:30|Not very deep. Disappointing.
5|Randall Munroe - What If?: Serious Scientific Answers to Absurd Hypothetical Questions|🔊Lexpub B00LV2F1ZA 6:36 -- unabridged -- published 2016 ⚡Amazon B00IYUYF4A 320 -- published 2014|2021/08/01, 2021/08/16 v2 🤝🏼with Sam, 2021/09/01|2021/08/15, 2021/08/28, 2021/09/10|science||Favorites: Global Windstorm, Relativistic Baseball, Laser Pointer, Hair Dryer, Machine-Gun Jetpack, Neutron Bullet. -- 💬It's been a long time since I gave highest marks to a "just for fun" book, but wow, this was fun. So fun that after listening to the audiobook, I immediately proceeded to read the book, for its illustrations. If I'd read this as a kid, I might have been inspired to become a scientist.
EOM
@inputs[:all_columns][:"realistic examples: planned"] = <<~EOM.freeze
\\------ PLANNED
|⚡Tom Holt - Alexander At The World's End|B00GVG00R0|||historical fiction|484
\\
\\⚡How to Think Like a Roman Emperor
\\🔊Trevor Noah - Born a Crime @Lexpub @Jeffco
\\
\\HISTORICAL FICTION: ⚡Tom Holt - A Song for Nero 🔊True Grit @Lexpub 🔊Two Gentlemen of Lebowski @https://www.runleiarun.com/lebowski/
\\SCIENCE, WEIRD @Lexpub: 📕Randall Munroe - How To 🔊Weird Earth @Hoopla
EOM
@inputs[:all_columns][:"realistic examples: History column"] = <<~EOM.freeze
3|🎤Flightless Bird|Spotify, https://armchairexpertpod.com/flightless-bird|||podcast|0:50 each||2021/10/06..11 x23 -- ..12/14 x1/week -- 3/1.. x2/week
4|🎤Pete Enns & Jared Byas - The Bible for Normal People|https://peteenns.com/podcast|||religion,podcast|||2021/12/01 0:50 #2 Richard Rohr - A Contemplative Look at The Bible -- 12/9 1:30 #19 Megan DeFranza - The Bible and Intersex Believers -- 12/21 ⭐#160 The Risk of an "Errant" Bible -- 0:50 ⭐#164 Where Did Our Bible Come From? -- 1/1 #5 Mike McHargue - Science and the Bible -- ?? #105 Wil Gafney - Womanist Midrash
4|🎤Escriba Café|https://www.escribacafe.com|||podcast|0:30 each||2021/04/16.. Amor -- Diabolus -- Máfia -- Piratas -- 2:00 Trilogia História do Brasil -- Rapa-Nui -- Espíritos -- Inferno -- ..4/30 Pompeia
4|🔊Born a Crime|Lexpub B01DHWACVY|||memoir|8:44||2021/5/1 @0:47 -- 5/2 @1:10 -- 5/6..15 0:30/day -- 5/20 @6:50 -- 5/21..23 done
EOM
## INPUT: ERRORS
# Bad input that should raise an error.
@inputs[:errors] = {}
@inputs[:errors][Reading::ParsingError] =
{
:"non-numeric rating" =>
"a|Sapiens",
:"comment containing a format emoji (matched as compact planned)" =>
"\\Testing a row with 📕",
:"ISBN/ASIN before sources" =>
"|Goatsong|0312038380 Little Library",
:"OK: ISBN/ASIN as part of a source name" =>
"|Goatsong|https://archive.org/details/isbn_9780767910422",
:"date not in yyyy/mm/dd format" =>
"|Sapiens||2019-01-01|2020/01/01",
:"start date content without a date" =>
"|Sapiens||no date here|2020/01/01",
:"end date content without a date" =>
"|Sapiens||2019/01/01|no date here",
:"incomplete date is the same as no date" =>
"|Sapiens||2019/01|2020/01/01",
:"conjoined dates" =>
"|Sapiens||2019/01/01 2020/01/01",
}
@inputs[:errors][Reading::InvalidDateError] =
{
:"unparsable date" =>
"|Sapiens||2019/01/32|2020/01/01",
:"end date before start date" =>
"|Sapiens||2020/01/01|2019/01/01",
:"start dates out of order" =>
"|Sapiens||2019/01/01, 2018/01/01",
:"end dates out of order" =>
"|Sapiens||2019/01/01, 2020/01/01|2022/01/01, 2021/01/01",
:"missing end date" =>
"|Sapiens||2019/01/01, 2020/01/01|",
:"missing start date" =>
"|Sapiens||2019/01/01|2019/03/01, 2020/03/01",
:"overlapping experiences (end date after the next start date) for the same variant" =>
"|Sapiens||2019/01/01, 2019/02/01|2019/03/01, ",
:"OK: overlapping experiences for different variants" =>
"|Sapiens||2019/01/01, 2019/02/01 v2|2019/03/01, ",
:"dates out of order in History" =>
"|Flightless Bird|||||||2021/10/06 0:30 -- 2020/1/1 0:30",
:"experiences out of order in History" =>
"|Flightless Bird|||||||2021/10/06 0:30 ---- 2020/1/1 0:30",
:"overlapping experiences in History" =>
"|Flightless Bird|||||||2021/10/06..10 0:30 ---- 2021/10/9..12 0:30",
# Because the second entry overwrites the first one in the overlap.
:"OK: overlapping date ranges in History" =>
"|Flightless Bird|||||||2021/10/06..12 0:30 -- 2021/10/10..16 1:00",
}
@inputs[:errors][Reading::InvalidHistoryError] =
{
:"missing first date" =>
"|Flightless Bird|||||||0:30",
:"incomplete first date" =>
"|Flightless Bird|||||||10/06 0:30",
:"missing length/amount" =>
"|Flightless Bird|||||||2021/10/06",
:"backward date range" =>
"|Flightless Bird|||||||2021/10/06..5 0:30",
:"endless date range starts in the future" => # Date::today is stubbed in test_helper.rb to 2022/10/1
"|Flightless Bird|||||||2022/10/2.. 0:30",
}
@inputs[:errors][Reading::InvalidHeadError] =
{
:"OK: blank row" =>
"\n\n",
:"OK: multiple blank rows" =>
"\n\n\n\n",
:"missing Head column" =>
"2",
:"blank Head column" =>
"2| |Hoopla",
:"missing title" =>
"|📕 ",
:"missing title after author" =>
"|📕Mark Twain - ",
:"missing title in compact planned row" =>
"\\📕",
:"missing title after author in compact planned row" =>
"\\📕Mark Twain - ",
}
@inputs[:errors][Reading::TooManyColumnsError] =
{
:"column beyond the number of enabled columns" =>
"|Sapiens||||||||something",
:"empty column beyond the number of enabled columns" =>
"|Sapiens||||||||| ",
}
# Examples of bad rows, such as missing columns, that do NOT raise an error.
# I *could* add more validations to avoid these, but for me these never happen
# because I view my reading.csv with color-coded columns (Rainbow CSV extension
# for VS Code). Even so, I'm documenting these odd cases here.
@inputs[:errors][Reading::Error] =
{
:"OK: missing Rating column if the title is numeric (no InvalidRatingError is raised)" =>
"1984|https://www.george-orwell.org/1984",
:"OK: missing Head column (the date is parsed as the title)" =>
"|2019/01/01",
:"OK: missing Source column (the date is parsed as a source)" =>
"|Sapiens|2019/01/01",
:"OK: missing Genres column (the length is parsed as a genre)" =>
"|Sapiens||2019/01/01|2020/01/01|15:17",
:"OK: missing Notes column (History is parsed as Notes)" =>
"|Sapiens||||history|15:17|2022/5/1 p31 -- 5/2 p54 -- 5/6-15 10p -- 5/20 p200 -- 5/21-23 done",
# OK because in these cases the row is assumed to be a full row.
:"OK: other columns in a compact planned item when only Sources and Length allowed" =>
"\\⚡Tom Holt - A Song for Nero|Lexpub, Hoopla|2022/12/21||fiction,history",
}
## INPUT: CUSTOM CONFIG
# Custom config that should affect the output.
@inputs[:config] = {
:"comment_character" =>
["#3|Dracula",
{ comment_character: "#" }],
:"column_separator" =>
["$Dracula",
{ column_separator: "$" }],
:"column_separator can be a tab" =>
["\tDracula",
{ column_separator: "\t" }],
:"skip_compact_planned" =>
["\\📕Dracula",
{ skip_compact_planned: true }],
:"ignored_characters" =>
["|✅Dracula",
{ ignored_characters: "Da"}],
:"listening speed affects Length" =>
["|🔊Dracula|||||9:00",
{ speed: { format: { audiobook: 1.5 } } }],
:"listening speed affects History" =>
["|🔊Dracula|||||||2022/8/1 9:00",
{ speed: { format: { audiobook: 1.5 } } }],
}
# ==== EXPECTED TEST OUTPUT
# The results of parsing the above inputs are expected to equal the hashes below.
def self.item_hash(**partial_hash)
# This merge is not the same as Reading::Util::HashDeepMerge. This one uses the
# first (empty) subhashes in the item template, for example in :variants and
# :experiences in the item template.
Reading::Config.hash.deep_fetch(:item, :template).merge(partial_hash) do |key, old_value, new_value|
item_template_merge(key, old_value, new_value)
end
end
def self.item_template_merge(key, old_value, new_value)
if old_value.is_a?(Array) && old_value.first.is_a?(Hash)
template = old_value.first
new_value.map do |v|
template.merge(v) do |k, old_v, new_v|
item_template_merge(k, old_v, new_v)
end
end
else
new_value
end
end
@outputs = {}
@outputs[:enabled_columns] = {}
a = item_hash(title: "Sapiens")
b = item_hash(title: "Goatsong")
c = item_hash(title: "How To")
@outputs[:enabled_columns][:"head"] = [a, b, c]
b_end_only = b.deep_merge(
experiences: [{ spans: [{ dates: ..Date.new(2020, 5, 30),
progress: 1.0}] }],
)
@outputs[:enabled_columns][:"head, end_dates"] = [a, b_end_only, c]
a_start = a.deep_merge(experiences: [{ spans: [{ dates: Date.new(2021, 9, 1).. }] }])
b_start = b.deep_merge(experiences: [{ spans: [{ dates: Date.new(2020, 5, 1).. }] }])
@outputs[:enabled_columns][:"head, start_dates"] = [a_start, b_start, c]
a_start_unfinished = a_start.deep_merge(experiences: [{ spans: [{ progress: 0.0 }] }])
b_end = item_hash(
title: "Goatsong",
experiences: [{ spans: [{ dates: Date.new(2020, 5, 1)..Date.new(2020, 5, 30),
progress: 1.0}] }],
)
@outputs[:enabled_columns][:"head, start_dates, end_dates"] = [a_start_unfinished, b_end, c]
a_rating = a_start_unfinished.merge(rating: nil)
b_rating = b_end.merge(rating: 5)
@outputs[:enabled_columns][:"rating, head, start_dates, end_dates"] = [a_rating, b_rating, c]
a_length_and_amount = { variants: [{ length: Reading.time('15:17') }],
experiences: [{ spans: [{ amount: Reading.time('15:17') }] }] }
b_length_and_amount = { variants: [{ length: 247 }],
experiences: [{ spans: [{ amount: 247 }] }] }
a_length = a_rating.deep_merge(a_length_and_amount)
b_length = b_rating.deep_merge(b_length_and_amount)
@outputs[:enabled_columns][:"rating, head, start_dates, end_dates, length"] = [a_length, b_length, c]
a_sources = a_rating.deep_merge(
variants: [{ isbn: "B00ICN066A",
sources: [{ name: "Vail Library" }] }])
b_sources = b_rating.deep_merge(variants: [{ isbn: "0312038380" }])
@outputs[:enabled_columns][:"rating, head, sources, start_dates, end_dates"] = [a_sources, b_sources, c]
a_many = a_sources.deep_merge(a_length_and_amount)
b_many = b_sources.deep_merge(b_length_and_amount)
@outputs[:enabled_columns][:"rating, head, sources, start_dates, end_dates, length"] = [a_many, b_many, c]
@outputs[:features_head] = {}
a = item_hash(author: "Tom Holt", title: "Goatsong")
@outputs[:features_head][:"author"] = [a]
series_name = "The Walled Orchard"
series = { variants: [{ series: [{ name: series_name }] }] }
a_series = a.deep_merge(series)
@outputs[:features_head][:"series"] = [a_series]
volume = { variants: [{ series: [{ volume: 1 }] }] }
a_series_volume = a_series.deep_merge(volume)
@outputs[:features_head][:"series with volume"] = [a_series_volume]
multi_series = {
variants: [{ series: [{ name: "Holt Historical Fiction", volume: nil },
{ name: series_name, volume: 1 }] }],
}
a_multi_series = a.deep_merge(multi_series)
@outputs[:features_head][:"multiple series"] = [a_multi_series]
extra_info = { variants: [{ extra_info: %w[paperback 1990] }] }
a_extra_info = a.deep_merge(extra_info)
@outputs[:features_head][:"extra info"] = [a_extra_info]
a_extra_info_series = a_extra_info.deep_merge(series).deep_merge(volume)
@outputs[:features_head][:"extra info and series"] = [a_extra_info_series]
format = { variants: [{ format: :print }] }
a_format = a.deep_merge(format)
@outputs[:features_head][:"format"] = [a_format]
b = item_hash(title: "Sapiens", variants: [{ format: :audiobook }])
@outputs[:features_head][:"multi items"] = [a_format, b]
@outputs[:features_head][:"multi items without a comma"] = [a_format, b]
@outputs[:features_head][:"multi items with a long separator"] = [a_format, b]
progress_half = { experiences: [{ spans: [{ progress: 0.5 }] }] }
a_progress_half = a_format.deep_merge(progress_half)
@outputs[:features_head][:"progress"] = [a_progress_half]
progress_pages = { experiences: [{ spans: [{ progress: 220 }] }] }
a_progress_pages = a_format.deep_merge(progress_pages)
@outputs[:features_head][:"progress pages"] = [a_progress_pages]
@outputs[:features_head][:"progress pages without p"] = [a_progress_pages]
progress_time = { experiences: [{ spans: [{ progress: Reading.time('2:30') }] }] }
a_progress_time = a_format.deep_merge(progress_time)
@outputs[:features_head][:"progress time"] = [a_progress_time]
progress_zero = { experiences: [{ spans: [{ progress: 0 }] }] }
a_progress_zero = a_format.deep_merge(progress_zero)
@outputs[:features_head][:"dnf in head"] = [a_progress_zero]
@outputs[:features_head][:"other string in head is ignored"] = [a_format]
@outputs[:features_head][:"dnf in head with progress"] = [a_progress_half]
b_progress_zero = b.deep_merge(experiences: [{ spans: [{ progress: 0 }] }])
@outputs[:features_head][:"dnf with multi items"] = [a_progress_zero, b_progress_zero]
full_variants = extra_info.deep_merge(series).deep_merge(volume)
a_full = a_progress_zero.deep_merge(full_variants).deep_merge(progress_half)
b_full = b_progress_zero.deep_merge(progress_half)
@outputs[:features_head][:"all features"] = [a_full, b_full]
@outputs[:features_sources] = {}
title = DEFAULT_TITLE
a = item_hash(title:)
isbn = "0312038380"
a_isbn = a.deep_merge(variants: [{ isbn: isbn }])
@outputs[:features_sources][:"ISBN-10"] = [a_isbn]
a_isbn_13 = a.deep_merge(variants: [{ isbn: "978-0312038380" }])
@outputs[:features_sources][:"ISBN-13"] = [a_isbn_13]
a_asin = a.deep_merge(variants: [{ isbn: "B00GVG01HE" }])
@outputs[:features_sources][:"ASIN"] = [a_asin]
library = { name: "Little Library", url: nil }
a_source = a.deep_merge(variants: [{ sources: [library] }])
@outputs[:features_sources][:"source"] = [a_source]
site_1 = { name: nil,
url: "https://www.edlin.org/holt" }
a_site_1 = a.deep_merge(variants: [{ sources: [site_1] }])
@outputs[:features_sources][:"URL source"] = [a_site_1]
site_named = { name: "Internet Archive",
url: "https://archive.org/details/walledorchard0000holt" }
a_site_named = a.deep_merge(variants: [{ sources: [site_named] }])
@outputs[:features_sources][:"URL source with a name from config"] = [a_site_named]
site_2 = { name: nil,
url: "https://tomholt.com" }
lexpub = { name: "Lexpub", url: nil }
three_sources = [library, site_1, site_2, lexpub]
a_commas = a.deep_merge(variants: [{ sources: three_sources }])
@outputs[:features_sources][:"multiple sources must be separated with commas"] = [a_commas]
a_source_isbn = a.deep_merge(
variants: [{ sources: [library],
isbn: isbn }],
)
@outputs[:features_sources][:"source with ISBN"] = [a_source_isbn]
a_source_isbn_x = a_source_isbn.deep_merge(
variants: [{ isbn: isbn.chop + "X" }],
)
@outputs[:features_sources][:"source with ISBN-10 ending in X"] = [a_source_isbn_x]
a_multi_sources_isbn = a.deep_merge(
variants: [{ sources: three_sources,
isbn: isbn }],
)
@outputs[:features_sources][:"sources with ISBN"] = [a_multi_sources_isbn]
@outputs[:features_sources][:"comma not required before and after URL source"] = [a_multi_sources_isbn]
a_variants = item_hash(
title:,
variants: [{ format: :print, sources: [library] },
{ format: :print, sources: [lexpub] }],
)
@outputs[:features_sources][:"simple variants"] = [a_variants]
a_variant_extra_info = item_hash(
title:,
variants: [{ format: :print,
sources: [library],
extra_info: %w[paperback 1990] },
{ format: :audiobook,
sources: [lexpub] }],
)
@outputs[:features_sources][:"variant with extra info"] = [a_variant_extra_info]
@outputs[:features_sources][:"optional long separator can be added between variants"] = [a_variant_extra_info]
a_variant_series = a_variant_extra_info.deep_merge(
variants: [{ series: [{ name: "The Walled Orchard", volume: 1 }] }],
)
@outputs[:features_sources][:"variant with extra info and series"] = [a_variant_series]
a_head_extras = a_variant_extra_info.deep_merge(
variants: [{ series: [{ name: "Holt's Classical Novels", volume: nil },
{ name: "The Walled Orchard", volume: 1 }],
extra_info: %w[unabridged paperback 1990] },
{ series: [{ name: "Holt's Classical Novels", volume: nil }],
extra_info: ["unabridged"] }]
)
@outputs[:features_sources][:"variant with extra info and series from Head also"] = [a_head_extras]
a_variant_length = item_hash(
title:,
variants: [a_variant_extra_info[:variants].first.merge(isbn: isbn, length: 247),
a_variant_extra_info[:variants].last.merge(length: Reading.time('7:03'))],
)
@outputs[:features_sources][:"length after sources ISBN and before extra info"] = [a_variant_length]
a_variant_sources = item_hash(
title:,
variants: [a_variant_length[:variants].first.merge(sources: three_sources),
a_variant_length[:variants].last],
)
@outputs[:features_sources][:"multiple sources allowed in variant"] = [a_variant_sources]
@outputs[:features_sources][:"optional commas can be added within and between variants"] = [a_variant_sources]
@outputs[:features_start_dates] = {}
a = item_hash(title: DEFAULT_TITLE)
start = { experiences: [{ spans: [{ dates: Date.new(2020, 9, 1).. }] }] }
a_start = a.deep_merge(start)
@outputs[:features_start_dates][:"start date"] = [a_start]
start_2 = {
experiences: [{},
{ spans: [{ dates: Date.new(2021, 7, 15).. }] }],
}
a_start_2 = item_hash(**a.deep_merge(start).deep_merge(start_2))
@outputs[:features_start_dates][:"start dates"] = [a_start_2]
@outputs[:features_start_dates][:"planned after a start date"] = [a_start]
@outputs[:features_start_dates][:"planned only"] = [a]
start_3 = {
experiences: [{},
{},
{ spans: [{ dates: Date.new(2022, 1, 1).. }] }],
}
a_start_3 = item_hash(**a.deep_merge(start).deep_merge(start_2).deep_merge(start_3))
@outputs[:features_start_dates][:"start dates in any order"] = [a_start_3]
progress = ->(amount) { { experiences: [{ spans: [{ progress: amount }] }] } }
a_progress_half = a_start.deep_merge(progress.call(0.5))
@outputs[:features_start_dates][:"progress"] = [a_progress_half]
a_progress_pages = a_start.deep_merge(progress.call(220))
@outputs[:features_start_dates][:"progress pages"] = [a_progress_pages]
@outputs[:features_start_dates][:"progress pages without p"] = [a_progress_pages]
a_progress_time = a_start.deep_merge(progress.call(Reading.time('2:30')))
@outputs[:features_start_dates][:"progress time"] = [a_progress_time]
a_progress_zero = a_start.deep_merge(progress.call(0))
@outputs[:features_start_dates][:"dnf default zero"] = [a_progress_zero]
@outputs[:features_start_dates][:"dnf with progress"] = [a_progress_half]
a_dnf_only = a.deep_merge(progress.call(0.5))
@outputs[:features_start_dates][:"dnf only"] = [a_dnf_only]
variant_2 = { experiences: [{ variant_index: 1 }] }
a_variant = a_start.deep_merge(variant_2)
@outputs[:features_start_dates][:"variant"] = [a_variant]
a_variant_only = a.deep_merge(variant_2)
@outputs[:features_start_dates][:"variant only"] = [a_variant_only]
group = { experiences: [{ group: "county book club" }] }
a_group = a_variant.deep_merge(group)
@outputs[:features_start_dates][:"group"] = [a_group]
a_group_only = a.deep_merge(group)
@outputs[:features_start_dates][:"group only"] = [a_group_only]
a_start_twice = item_hash(**a.deep_merge(start).deep_merge(start_2))
a_start_twice_progress = a_start_twice.deep_merge(
experiences: [{ spans: [{ progress: 0.5 }],
variant_index: 1 },
{ spans: [{ progress: Reading.time('2:30') }] }],
)
@outputs[:features_start_dates][:"all features"] = [a_start_twice_progress]
@outputs[:features_compact_planned] = {}
a_title = item_hash(title: "A Song for Nero",
variants: [{ format: :ebook }])
@outputs[:features_compact_planned][:"title only"] = [a_title]
a_author = a_title.merge(author: "Tom Holt")
@outputs[:features_compact_planned][:"with author"] = [a_author]
lexpub_and_hoopla = [{ name: "Lexpub", url: nil },
{ name: "Hoopla", url: nil }]
a_sources = a_author.deep_merge(variants: [{ sources: lexpub_and_hoopla }])
@outputs[:features_compact_planned][:"with sources"] = [a_sources]
@outputs[:features_compact_planned][:"with sources in the Sources column"] = [a_sources]
a_sources_and_length = a_sources.deep_merge(variants: [{ length: 239 }])
@outputs[:features_compact_planned][:"with Sources and Length column"] =
[a_sources_and_length]
a_length_only = a_author.deep_merge(variants: [{ length: 239 }])
@outputs[:features_compact_planned][:"with only Length column"] = [a_length_only]
a_full_sources = a_sources.deep_merge(
variants: [{ isbn: "B00GW4U2TM",
extra_info: ["unabridged"],
series: [{ name: "Holt's Classical Novels", volume: nil }] }],
)
@outputs[:features_compact_planned][:"with fuller Head and Sources columns"] = [a_full_sources]
a_full_sources_minus_isbn = a_full_sources.deep_merge(variants: [{ isbn: nil }])
@outputs[:features_compact_planned][:"with sources and extra info"] = [a_full_sources_minus_isbn]
b_sources = item_hash(
title: "True Grit",
variants: [{ format: :audiobook,
sources: [{ name: "Lexpub" }] }],
)
@outputs[:features_compact_planned][:"multiple"] = [a_sources, b_sources]
@outputs[:features_compact_planned][:"multiple with source"] = [a_sources, b_sources]
a_genre = a_sources.merge(genres: ["historical fiction"])
b_genre = b_sources.merge(genres: ["historical fiction"])
@outputs[:features_compact_planned][:"multiple with genre"] = [a_genre, b_genre]
a_multi_genre = a_sources.merge(genres: ["historical fiction", "faves"])
b_multi_genre = b_sources.merge(genres: ["historical fiction", "faves"])
@outputs[:features_compact_planned][:"multiple with multiple genres"] = [a_multi_genre, b_multi_genre]
@outputs[:features_compact_planned][:"multiple with genre plus source"] = [a_genre, b_genre]
@outputs[:features_compact_planned][:"duplicate sources are ignored"] = [a_genre, b_genre]
multi_source = [{ sources: [{ name: "Lexpub" },
{ name: nil, url: "https://www.lexpublib.org" }]}]
a_multi_source = a_genre.deep_merge(variants: multi_source)
b_multi_source = b_genre.deep_merge(variants: multi_source)
@outputs[:features_compact_planned][:"multiple sources at the beginning"] = [a_multi_source, b_multi_source]
@outputs[:features_compact_planned][:"config-defined emojis are ignored"] = [a_genre, b_genre]
@outputs[:features_history] = {}
a_dates = item_hash(
title: DEFAULT_TITLE,
experiences: [{ spans: [
{ dates: Date.new(2021, 12, 6)..Date.new(2021, 12, 6),
amount: Reading.time('0:30') },
{ dates: Date.new(2021, 12, 21)..Date.new(2021, 12, 21),
amount: Reading.time('0:30') },
{ dates: Date.new(2022, 3, 1)..Date.new(2022, 3, 1),
amount: Reading.time('0:30') },
] }],
)
@outputs[:features_history][:"dates"] = [a_dates]
@outputs[:features_history][:"dates can omit unchanged month"] = [a_dates]
a_ranges = a_dates.deep_merge(
experiences: [{ spans: [
{ dates: Date.new(2021, 12, 6)..Date.new(2021, 12, 8),
amount: Reading.time('0:30') },
] }],
)
@outputs[:features_history][:"date ranges"] = [a_ranges]
a_adjacent = item_hash(
title: DEFAULT_TITLE,
experiences: [{ spans: [
{ dates: Date.new(2021, 12, 6)..Date.new(2021, 12, 10),
amount: Reading.time('2:30') },
] }],
)
@outputs[:features_history][:"adjacent dates of same daily amount are merged into a range"] = [a_adjacent]
a_amounts = a_ranges.deep_merge(
experiences: [{ spans: [
{ amount: Reading.time('0:35') },
{ amount: Reading.time('0:45') },
{ amount: Reading.time('0:45') },
] }],
)
@outputs[:features_history][:"time amounts"] = [a_amounts]
@outputs[:features_history][:"implied time amount"] = [a_amounts]
a_implied_dates = item_hash(
title: DEFAULT_TITLE,
experiences: [{ spans: [
{ dates: Date.new(2021, 12, 6)..Date.new(2021, 12, 8),
amount: Reading.time('0:35') },
{ dates: Date.new(2021, 12, 9)..Date.new(2021, 12, 9),
amount: Reading.time('0:30') },
] }],
)
@outputs[:features_history][:"implied dates"] = [a_implied_dates]
a_implied_range_start = item_hash(
title: DEFAULT_TITLE,
experiences: [{ spans: [
{ dates: Date.new(2021, 12, 6)..Date.new(2021, 12, 6),
amount: Reading.time('0:35') },
{ dates: Date.new(2021, 12, 7)..Date.new(2021, 12, 8),
amount: Reading.time('0:45') },