• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / marc_cleanup / 49fd4b81-f6f8-41e4-bacd-2f1251d13cb4

15 Dec 2023 10:21PM UTC coverage: 21.291% (+2.7%) from 18.593%
49fd4b81-f6f8-41e4-bacd-2f1251d13cb4

Pull #84

circleci

Beck-Davis
added test for fix_book_008
Pull Request #84: Draft: Additional spec tests for fix_008

442 of 2076 relevant lines covered (21.29%)

0.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.65
/lib/marc_cleanup/fixed_fields.rb
1
module MarcCleanup
1✔
2
  def no_001?(record)
1✔
3
    record['001'].nil?
2✔
4
  end
5

6
  def fixed_field_char_errors?(record)
1✔
7
    fields = record.fields('001'..'009').map(&:value)
×
8
    bad_fields = fields.reject { |value| value.bytesize == value.chars.size }
×
9
    bad_fields += fields.select { |value| value =~ /[^a-z0-9 |.A-Z\-]/ }
×
10
    !bad_fields.empty?
×
11
  end
12

13
  def bib_form(record)
1✔
14
    %w[a c d i j m p t].include?(record.leader[6]) ? record['008'].value[23] : record['008'].value[29]
×
15
  end
16

17
  def multiple_no_008?(record)
1✔
18
    record.fields('008').size != 1
×
19
  end
20

21
  def place_codes
1✔
22
    [
23
      'aa ',
7✔
24
      'abc',
25
      'ac ',
26
      'aca',
27
      'ae ',
28
      'af ',
29
      'ag ',
30
      'ai ',
31
      'ai ',
32
      'air',
33
      'aj ',
34
      'ajr',
35
      'aku',
36
      'alu',
37
      'am ',
38
      'an ',
39
      'ao ',
40
      'aq ',
41
      'aru',
42
      'as ',
43
      'at ',
44
      'au ',
45
      'aw ',
46
      'ay ',
47
      'azu',
48
      'ba ',
49
      'bb ',
50
      'bcc',
51
      'bd ',
52
      'be ',
53
      'bf ',
54
      'bg ',
55
      'bh ',
56
      'bi ',
57
      'bl ',
58
      'bm ',
59
      'bn ',
60
      'bo ',
61
      'bp ',
62
      'br ',
63
      'bs ',
64
      'bt ',
65
      'bu ',
66
      'bv ',
67
      'bw ',
68
      'bwr',
69
      'bx ',
70
      'ca ',
71
      'cau',
72
      'cb ',
73
      'cc ',
74
      'cd ',
75
      'ce ',
76
      'cf ',
77
      'cg ',
78
      'ch ',
79
      'ci ',
80
      'cj ',
81
      'ck ',
82
      'cl ',
83
      'cm ',
84
      'cn ',
85
      'co ',
86
      'cou',
87
      'cp ',
88
      'cq ',
89
      'cr ',
90
      'cs ',
91
      'ctu',
92
      'cu ',
93
      'cv ',
94
      'cw ',
95
      'cx ',
96
      'cy ',
97
      'cz ',
98
      'dcu',
99
      'deu',
100
      'dk ',
101
      'dm ',
102
      'dq ',
103
      'dr ',
104
      'ea ',
105
      'ec ',
106
      'eg ',
107
      'em ',
108
      'enk',
109
      'er ',
110
      'err',
111
      'es ',
112
      'et ',
113
      'fa ',
114
      'fg ',
115
      'fi ',
116
      'fj ',
117
      'fk ',
118
      'flu',
119
      'fm ',
120
      'fp ',
121
      'fr ',
122
      'fs ',
123
      'ft ',
124
      'gau',
125
      'gb ',
126
      'gd ',
127
      'ge ',
128
      'gg ',
129
      'gh ',
130
      'gi ',
131
      'gl ',
132
      'gm ',
133
      'gn ',
134
      'go ',
135
      'gp ',
136
      'gr ',
137
      'gs ',
138
      'gsr',
139
      'gt ',
140
      'gu ',
141
      'gv ',
142
      'gw ',
143
      'gy ',
144
      'gz ',
145
      'hiu',
146
      'hk ',
147
      'hm ',
148
      'ho ',
149
      'ht ',
150
      'hu ',
151
      'iau',
152
      'ic ',
153
      'idu',
154
      'ie ',
155
      'ii ',
156
      'ilu',
157
      'im ',
158
      'inu',
159
      'io ',
160
      'iq ',
161
      'ir ',
162
      'is ',
163
      'it ',
164
      'iu ',
165
      'iv ',
166
      'iw ',
167
      'iy ',
168
      'ja ',
169
      'je ',
170
      'ji ',
171
      'jm ',
172
      'jn ',
173
      'jo ',
174
      'ke ',
175
      'kg ',
176
      'kgr',
177
      'kn ',
178
      'ko ',
179
      'ksu',
180
      'ku ',
181
      'kv ',
182
      'kyu',
183
      'kz ',
184
      'kzr',
185
      'lau',
186
      'lb ',
187
      'le ',
188
      'lh ',
189
      'li ',
190
      'lir',
191
      'ln ',
192
      'lo ',
193
      'ls ',
194
      'lu ',
195
      'lv ',
196
      'lvr',
197
      'ly ',
198
      'mau',
199
      'mbc',
200
      'mc ',
201
      'mdu',
202
      'meu',
203
      'mf ',
204
      'mg ',
205
      'mh ',
206
      'miu',
207
      'mj ',
208
      'mk ',
209
      'ml ',
210
      'mm ',
211
      'mnu',
212
      'mo ',
213
      'mou',
214
      'mp ',
215
      'mq ',
216
      'mr ',
217
      'msu',
218
      'mtu',
219
      'mu ',
220
      'mv ',
221
      'mvr',
222
      'mw ',
223
      'mx ',
224
      'my ',
225
      'mz ',
226
      'na ',
227
      'nbu',
228
      'ncu',
229
      'ndu',
230
      'ne ',
231
      'nfc',
232
      'ng ',
233
      'nhu',
234
      'nik',
235
      'nju',
236
      'nkc',
237
      'nl ',
238
      'nm ',
239
      'nmu',
240
      'nn ',
241
      'no ',
242
      'np ',
243
      'nq ',
244
      'nr ',
245
      'nsc',
246
      'ntc',
247
      'nu ',
248
      'nuc',
249
      'nvu',
250
      'nw ',
251
      'nx ',
252
      'nyu',
253
      'nz ',
254
      'ohu',
255
      'oku',
256
      'onc',
257
      'oru',
258
      'ot ',
259
      'pau',
260
      'pc ',
261
      'pe ',
262
      'pf ',
263
      'pg ',
264
      'ph ',
265
      'pic',
266
      'pk ',
267
      'pl ',
268
      'pn ',
269
      'po ',
270
      'pp ',
271
      'pr ',
272
      'pt ',
273
      'pw ',
274
      'py ',
275
      'qa ',
276
      'qea',
277
      'quc',
278
      'rb ',
279
      're ',
280
      'rh ',
281
      'riu',
282
      'rm ',
283
      'ru ',
284
      'rur',
285
      'rw ',
286
      'ry ',
287
      'sa ',
288
      'sb ',
289
      'sc ',
290
      'scu',
291
      'sd ',
292
      'sdu',
293
      'se ',
294
      'sf ',
295
      'sg ',
296
      'sh ',
297
      'si ',
298
      'sj ',
299
      'sk ',
300
      'sl ',
301
      'sm ',
302
      'sn ',
303
      'snc',
304
      'so ',
305
      'sp ',
306
      'sq ',
307
      'sr ',
308
      'ss ',
309
      'st ',
310
      'stk',
311
      'su ',
312
      'sv ',
313
      'sw ',
314
      'sx ',
315
      'sy ',
316
      'sz ',
317
      'ta ',
318
      'tar',
319
      'tc ',
320
      'tg ',
321
      'th ',
322
      'ti ',
323
      'tk ',
324
      'tkr',
325
      'tl ',
326
      'tma',
327
      'tnu',
328
      'to ',
329
      'tr ',
330
      'ts ',
331
      'tt ',
332
      'tu ',
333
      'tv ',
334
      'txu',
335
      'tz ',
336
      'ua ',
337
      'uc ',
338
      'ug ',
339
      'ui ',
340
      'uik',
341
      'uk ',
342
      'un ',
343
      'unr',
344
      'up ',
345
      'ur ',
346
      'us ',
347
      'utu',
348
      'uv ',
349
      'uy ',
350
      'uz ',
351
      'uzr',
352
      'vau',
353
      'vb ',
354
      'vc ',
355
      've ',
356
      'vi ',
357
      'vm ',
358
      'vn ',
359
      'vp ',
360
      'vra',
361
      'vs ',
362
      'vtu',
363
      'wau',
364
      'wb ',
365
      'wea',
366
      'wf ',
367
      'wiu',
368
      'wj ',
369
      'wk ',
370
      'wlk',
371
      'ws ',
372
      'wvu',
373
      'wyu',
374
      'xa ',
375
      'xb ',
376
      'xc ',
377
      'xd ',
378
      'xe ',
379
      'xf ',
380
      'xga',
381
      'xh ',
382
      'xi ',
383
      'xj ',
384
      'xk ',
385
      'xl ',
386
      'xm ',
387
      'xn ',
388
      'xna',
389
      'xo ',
390
      'xoa',
391
      'xp ',
392
      'xr ',
393
      'xra',
394
      'xs ',
395
      'xv ',
396
      'xx ',
397
      'xxc',
398
      'xxk',
399
      'xxr',
400
      'xxu',
401
      'ye ',
402
      'ykc',
403
      'ys ',
404
      'yu ',
405
      'za '
406
    ]
407
  end
408

409
  def lang_codes
1✔
410
    %w[
411
      aar
7✔
412
      abk
413
      ace
414
      ach
415
      ada
416
      ady
417
      afa
418
      afh
419
      afr
420
      ain
421
      ajm
422
      aka
423
      akk
424
      alb
425
      ale
426
      alg
427
      alt
428
      amh
429
      ang
430
      anp
431
      apa
432
      ara
433
      arc
434
      arg
435
      arm
436
      arn
437
      arp
438
      art
439
      arw
440
      asm
441
      ast
442
      ath
443
      aus
444
      ava
445
      ave
446
      awa
447
      aym
448
      aze
449
      bad
450
      bai
451
      bak
452
      bal
453
      bam
454
      ban
455
      baq
456
      bas
457
      bat
458
      bej
459
      bel
460
      bem
461
      ben
462
      ber
463
      bho
464
      bih
465
      bik
466
      bin
467
      bis
468
      bla
469
      bnt
470
      bos
471
      bra
472
      bre
473
      btk
474
      bua
475
      bug
476
      bul
477
      bur
478
      byn
479
      cad
480
      cai
481
      cam
482
      car
483
      cat
484
      cau
485
      ceb
486
      cel
487
      cha
488
      chb
489
      che
490
      chg
491
      chi
492
      chk
493
      chm
494
      chn
495
      cho
496
      chp
497
      chr
498
      chu
499
      chv
500
      chy
501
      cmc
502
      cnr
503
      cop
504
      cor
505
      cos
506
      cpe
507
      cpf
508
      cpp
509
      cre
510
      crh
511
      crp
512
      csb
513
      cus
514
      cze
515
      dak
516
      dan
517
      dar
518
      day
519
      del
520
      den
521
      dgr
522
      din
523
      div
524
      doi
525
      dra
526
      dsb
527
      dua
528
      dum
529
      dut
530
      dyu
531
      dzo
532
      efi
533
      egy
534
      eka
535
      elx
536
      eng
537
      enm
538
      epo
539
      esk
540
      esp
541
      est
542
      eth
543
      ewe
544
      ewo
545
      fan
546
      fao
547
      far
548
      fat
549
      fij
550
      fil
551
      fin
552
      fiu
553
      fon
554
      fre
555
      fri
556
      frm
557
      fro
558
      frr
559
      frs
560
      fry
561
      ful
562
      fur
563
      gaa
564
      gae
565
      gag
566
      gal
567
      gay
568
      gba
569
      gem
570
      geo
571
      ger
572
      gez
573
      gil
574
      gla
575
      gle
576
      glg
577
      glv
578
      gmh
579
      goh
580
      gon
581
      gor
582
      got
583
      grb
584
      grc
585
      gre
586
      grn
587
      gsw
588
      gua
589
      guj
590
      gwi
591
      hai
592
      hat
593
      hau
594
      haw
595
      heb
596
      her
597
      hil
598
      him
599
      hin
600
      hit
601
      hmn
602
      hmo
603
      hrv
604
      hsb
605
      hun
606
      hup
607
      iba
608
      ibo
609
      ice
610
      ido
611
      iii
612
      ijo
613
      iku
614
      ile
615
      ilo
616
      ina
617
      inc
618
      ind
619
      ine
620
      inh
621
      int
622
      ipk
623
      ira
624
      iri
625
      iro
626
      ita
627
      jav
628
      jbo
629
      jpn
630
      jpr
631
      jrb
632
      kaa
633
      kab
634
      kac
635
      kal
636
      kam
637
      kan
638
      kar
639
      kas
640
      kau
641
      kaw
642
      kaz
643
      kbd
644
      kha
645
      khi
646
      khm
647
      kho
648
      kik
649
      kin
650
      kir
651
      kmb
652
      kok
653
      kom
654
      kon
655
      kor
656
      kos
657
      kpe
658
      krc
659
      krl
660
      kro
661
      kru
662
      kua
663
      kum
664
      kur
665
      kus
666
      kut
667
      lad
668
      lah
669
      lam
670
      lan
671
      lao
672
      lap
673
      lat
674
      lav
675
      lez
676
      lim
677
      lin
678
      lit
679
      lol
680
      loz
681
      ltz
682
      lua
683
      lub
684
      lug
685
      lui
686
      lun
687
      luo
688
      lus
689
      mac
690
      mad
691
      mag
692
      mah
693
      mai
694
      mak
695
      mal
696
      man
697
      mao
698
      map
699
      mar
700
      mas
701
      max
702
      may
703
      mdf
704
      mdr
705
      men
706
      mga
707
      mic
708
      min
709
      mis
710
      mkh
711
      mla
712
      mlg
713
      mlt
714
      mnc
715
      mni
716
      mno
717
      moh
718
      mol
719
      mon
720
      mos
721
      mul
722
      mun
723
      mus
724
      mwl
725
      mwr
726
      myn
727
      myv
728
      nah
729
      nai
730
      nap
731
      nau
732
      nav
733
      nbl
734
      nde
735
      ndo
736
      nds
737
      nep
738
      new
739
      nia
740
      nic
741
      niu
742
      nno
743
      nob
744
      nog
745
      non
746
      nor
747
      nqo
748
      nso
749
      nub
750
      nwc
751
      nya
752
      nym
753
      nyn
754
      nyo
755
      nzi
756
      oci
757
      oji
758
      ori
759
      orm
760
      osa
761
      oss
762
      ota
763
      oto
764
      paa
765
      pag
766
      pal
767
      pam
768
      pan
769
      pap
770
      pau
771
      peo
772
      per
773
      phi
774
      phn
775
      pli
776
      pol
777
      pon
778
      por
779
      pra
780
      pro
781
      pus
782
      que
783
      raj
784
      rap
785
      rar
786
      roa
787
      roh
788
      rom
789
      rum
790
      run
791
      rup
792
      rus
793
      sad
794
      sag
795
      sah
796
      sai
797
      sal
798
      sam
799
      san
800
      sao
801
      sas
802
      sat
803
      scc
804
      scn
805
      sco
806
      scr
807
      sel
808
      sem
809
      sga
810
      sgn
811
      shn
812
      sho
813
      sid
814
      sin
815
      sio
816
      sit
817
      sla
818
      slo
819
      slv
820
      sma
821
      sme
822
      smi
823
      smj
824
      smn
825
      smo
826
      sms
827
      sna
828
      snd
829
      snh
830
      snk
831
      sog
832
      som
833
      son
834
      sot
835
      spa
836
      srd
837
      srn
838
      srp
839
      srr
840
      ssa
841
      sso
842
      ssw
843
      suk
844
      sun
845
      sus
846
      sux
847
      swa
848
      swe
849
      swz
850
      syc
851
      syr
852
      tag
853
      tah
854
      tai
855
      taj
856
      tam
857
      tar
858
      tat
859
      tel
860
      tem
861
      ter
862
      tet
863
      tgk
864
      tgl
865
      tha
866
      tib
867
      tig
868
      tir
869
      tiv
870
      tkl
871
      tlh
872
      tli
873
      tmh
874
      tog
875
      ton
876
      tpi
877
      tru
878
      tsi
879
      tsn
880
      tso
881
      tsw
882
      tuk
883
      tum
884
      tup
885
      tur
886
      tut
887
      tvl
888
      twi
889
      tyv
890
      udm
891
      uga
892
      uig
893
      ukr
894
      umb
895
      und
896
      urd
897
      uzb
898
      vai
899
      ven
900
      vie
901
      vol
902
      vot
903
      wak
904
      wal
905
      war
906
      was
907
      wel
908
      wen
909
      wln
910
      wol
911
      xal
912
      xho
913
      yao
914
      yap
915
      yid
916
      yor
917
      ypk
918
      zap
919
      zbl
920
      zen
921
      zha
922
      znd
923
      zul
924
      zun
925
      zxx
926
      zza
927
    ]
928
  end
929

930
  def illus_codes
1✔
931
    /^[ a-mop]+$/
1✔
932
  end
933

934
  def audience_codes
1✔
935
    /[ a-gj|]/
×
936
  end
937

938
  def item_form_codes
1✔
939
    /[ a-dfoq-s|]/
×
940
  end
941

942
  def item_orig_form_codes
1✔
943
    /[ a-foqs|]/
×
944
  end
945

946
  def contents_codes
1✔
947
    /^[ a-gi-wyz256]+$/
×
948
  end
949

950
  def gov_pub_codes
1✔
951
    /[ acfilmosuz|]/
×
952
  end
953

954
  def lit_form_codes
1✔
955
    /[01c-fhijmpsu|]/
×
956
  end
957

958
  def biog_codes
1✔
959
    /[ abcd|]/
×
960
  end
961

962
  def comp_type_codes
1✔
963
    /[a-jmuz|]/
×
964
  end
965

966
  def relief_codes
1✔
967
    /^[ a-gi-kmz]+$/
1✔
968
  end
969

970
  def proj_codes
1✔
971
    [
972
      '  ',
1✔
973
      'aa',
974
      'ab',
975
      'ac',
976
      'ad',
977
      'ae',
978
      'af',
979
      'ag',
980
      'am',
981
      'an',
982
      'ap',
983
      'au',
984
      'az',
985
      'ba',
986
      'bb',
987
      'bc',
988
      'bd',
989
      'be',
990
      'bf',
991
      'bg',
992
      'bh',
993
      'bi',
994
      'bj',
995
      'bk',
996
      'bl',
997
      'bo',
998
      'br',
999
      'bs',
1000
      'bu',
1001
      'bz',
1002
      'ca',
1003
      'cb',
1004
      'cc',
1005
      'ce',
1006
      'cp',
1007
      'cu',
1008
      'cz',
1009
      'da',
1010
      'db',
1011
      'dc',
1012
      'dd',
1013
      'de',
1014
      'df',
1015
      'dg',
1016
      'dh',
1017
      'dl',
1018
      'zz',
1019
      '||'
1020
    ]
1021
  end
1022

1023
  def map_type_codes
1✔
1024
    /[a-guz|]/
×
1025
  end
1026

1027
  def map_special_format_codes
1✔
1028
    /[ ejklnoprz]+/
×
1029
  end
1030

1031
  def comp_codes_uris
1✔
1032
    {
1033
      'an' => 'gf2014026635',
×
1034
      'bd' => 'gf2014026648',
1035
      'bg' => 'gf2014026664',
1036
      'bl' => 'gf2014026665',
1037
      'bt' => 'gf2014026650',
1038
      'ca' => 'gf2014026701',
1039
      'cb' => 'gf2014026707',
1040
      'cc' => 'gf2014026707',
1041
      'cg' => 'gf2014026724',
1042
      'ch' => 'gf2014026713',
1043
      'cl' => 'gf2014026712',
1044
      'cn' => 'gf2014026687',
1045
      'co' => 'gf2014026725',
1046
      'cp' => 'gf2014027007',
1047
      'cr' => 'gf2014026695',
1048
      'cs' => 'gf2014026624',
1049
      'ct' => 'gf2014026688',
1050
      'cy' => 'gf2014026739',
1051
      'dv' => 'gf2014027116',
1052
      'fg' => 'gf2014026818',
1053
      'fl' => 'gf2014026806',
1054
      'fm' => 'gf2014026809',
1055
      'ft' => 'gf2018026018',
1056
      'gm' => 'gf2014026839',
1057
      'hy' => 'gf2014026872',
1058
      'jz' => 'gf2014026879',
1059
      'mc' => 'gf2014027050',
1060
      'md' => 'gf2014026915',
1061
      'mi' => 'gf2014026940',
1062
      'mo' => 'gf2014026949',
1063
      'mp' => 'gf2014026950',
1064
      'mr' => 'gf2014026922',
1065
      'ms' => 'gf2014026926',
1066
      'mz' => 'gf2014026928',
1067
      'nc' => 'gf2017026144',
1068
      'op' => 'gf2014026976',
1069
      'or' => 'gf2014026977',
1070
      'ov' => 'gf2014026980',
1071
      'pg' => 'gf2014027017',
1072
      'pm' => 'gf2014026861',
1073
      'po' => 'gf2014027005',
1074
      'pp' => 'gf2014027009',
1075
      'pr' => 'gf2014027013',
1076
      'ps' => 'gf2014026989',
1077
      'pt' => 'gf2014026984',
1078
      'pv' => 'gf2014026994',
1079
      'rc' => 'gf2014027054',
1080
      'rd' => 'gf2014027057',
1081
      'rg' => 'gf2014027034',
1082
      'ri' => 'gf2017026128',
1083
      'rp' => 'gf2014027051',
1084
      'rq' => 'gf2014027048',
1085
      'sd' => 'gf2014027111',
1086
      'sg' => 'gf2014027103',
1087
      'sn' => 'gf2014027099',
1088
      'sp' => 'gf2014027120',
1089
      'st' => 'gf2014027115',
1090
      'su' => 'gf2014027116',
1091
      'sy' => 'gf2014027121',
1092
      'tc' => 'gf2014027140',
1093
      'vi' => 'gf2017026025',
1094
      'vr' => 'gf2014027156',
1095
      'wz' => 'gf2014027167',
1096
      'za' => 'gf2016026059'
1097
    }
1098
  end
1099

1100
  def composition_codes
1✔
1101
    %w[
1102
      an
1✔
1103
      bd
1104
      bg
1105
      bl
1106
      bt
1107
      ca
1108
      cb
1109
      cc
1110
      cg
1111
      ch
1112
      cl
1113
      cn
1114
      co
1115
      cp
1116
      cr
1117
      cs
1118
      ct
1119
      cy
1120
      cz
1121
      df
1122
      dv
1123
      fg
1124
      fl
1125
      fm
1126
      ft
1127
      gm
1128
      hy
1129
      jz
1130
      mc
1131
      md
1132
      mi
1133
      mo
1134
      mp
1135
      mr
1136
      ms
1137
      mu
1138
      mz
1139
      nc
1140
      nn
1141
      op
1142
      or
1143
      ov
1144
      pg
1145
      pm
1146
      po
1147
      pp
1148
      pr
1149
      ps
1150
      pt
1151
      pv
1152
      rc
1153
      rd
1154
      rg
1155
      ri
1156
      rp
1157
      rq
1158
      sd
1159
      sg
1160
      sn
1161
      sp
1162
      st
1163
      su
1164
      sy
1165
      tc
1166
      tl
1167
      ts
1168
      uu
1169
      vi
1170
      vr
1171
      wz
1172
      za
1173
      zz
1174
      ||
1175
    ]
1176
  end
1177

1178
  def music_format_codes
1✔
1179
    /[a-eg-npuz|]/
×
1180
  end
1181

1182
  def music_part_codes
1✔
1183
    /[ defnu|]/
×
1184
  end
1185

1186
  def accompany_codes
1✔
1187
    /^[ a-ikrsz]+$/
×
1188
  end
1189

1190
  def lit_text_codes
1✔
1191
    /^[ a-prstz]+$/
×
1192
  end
1193

1194
  def transpose_codes
1✔
1195
    /[ abcnu|]/
×
1196
  end
1197

1198
  def freq_codes
1✔
1199
    /[ a-kmqstuwz|]/
1✔
1200
  end
1201

1202
  def cr_type_codes
1✔
1203
    /[ dlmnpw|]/
×
1204
  end
1205

1206
  def cr_contents_codes
1✔
1207
    /^[ a-ik-wyz56]+/
×
1208
  end
1209

1210
  def orig_script_codes
1✔
1211
    /[ a-luz|]/
×
1212
  end
1213

1214
  def visual_type_codes
1✔
1215
    /^[a-dfgik-tvwz|]$/
×
1216
  end
1217

1218
  def all_008(field)
1✔
1219
    date_entered = field[0..5]
7✔
1220
    date_type = field[6]
7✔
1221
    date1 = field[7..10]
7✔
1222
    date2 = field[11..14]
7✔
1223
    place = field[15..17]
7✔
1224
    lang = field[35..37]
7✔
1225
    modified = field[38]
7✔
1226
    cat_source = field[39]
7✔
1227
    return true unless date_entered =~ /^[0-9]{6}$/
7✔
1228
    return true unless %w[b c d e i k m n p q r s t u |].include?(date_type)
7✔
1229
    return true unless date1 == '||||' || date1 == '    ' || date1 =~ /^[0-9u]{4}$/
7✔
1230

1231
    case date_type
7✔
1232
    when 'e'
1233
      return true unless date2 =~ /^[0-9]+[ ]*$/
×
1234
    else
1235
      return true unless date2 == '||||' || date2 == '    ' || date2 =~ /^[0-9u]{4}$/
7✔
1236
    end
1237
    return true unless place == '|||' || place_codes.include?(place)
7✔
1238
    return true unless lang == '|||'  || lang_codes.include?(lang)
7✔
1239
    return true unless %w[\  d o r s x |].include?(modified)
7✔
1240
    return true unless %w[\  c d u |].include?(cat_source)
7✔
1241

1242
    false
7✔
1243
  end
1244

1245
  def book_008(field)
1✔
1246
    illus = field[0..3]
1✔
1247
    audience = field[4]
1✔
1248
    item_form = field[5]
1✔
1249
    contents = field[6..9]
1✔
1250
    gov_pub = field[10]
1✔
1251
    conf_pub = field[11]
1✔
1252
    festschrift = field[12]
1✔
1253
    index = field[13]
1✔
1254
    undefined = field[14]
1✔
1255
    lit_form = field[15]
1✔
1256
    biog = field[16]
1✔
1257
    return true unless illus == '||||' || illus =~ illus_codes
1✔
1258
    return true unless audience =~ audience_codes
×
1259
    return true unless item_form =~ item_form_codes
×
1260
    return true unless contents == '||||' || contents =~ contents_codes
×
1261
    return true unless gov_pub =~ gov_pub_codes
×
1262
    return true unless %w[0 1 |].include?(conf_pub)
×
1263
    return true unless %w[0 1 |].include?(festschrift)
×
1264
    return true unless %w[0 1 |].include?(index)
×
1265
    return true unless undefined == ' '
×
1266
    return true unless lit_form =~ lit_form_codes
×
1267
    return true unless biog =~ biog_codes
×
1268

1269
    false
×
1270
  end
1271

1272
  def comp_008(field)
1✔
1273
    undef1 = field[0..3]
1✔
1274
    audience = field[4]
1✔
1275
    item_form = field[5]
1✔
1276
    undef2 = field[6..7]
1✔
1277
    type = field[8]
1✔
1278
    undef3 = field[9]
1✔
1279
    gov_pub = field[10]
1✔
1280
    undef4 = field[11..16]
1✔
1281
    return true unless ['||||', '    '].include?(undef1)
1✔
1282
    return true unless audience =~ audience_codes
×
1283
    return true unless item_form =~ /[ oq|]/
×
1284
    return true unless ['  ', '||'].include?(undef2)
×
1285
    return true unless type =~ comp_type_codes
×
1286
    return true unless [' ', '|'].include?(undef3)
×
1287
    return true unless gov_pub =~ gov_pub_codes
×
1288
    return true unless ['||||||', '      '].include?(undef4)
×
1289

1290
    false
×
1291
  end
1292

1293
  def map_008(field)
1✔
1294
    relief = field[0..3]
1✔
1295
    proj = field[4..5]
1✔
1296
    undef1 = field[6]
1✔
1297
    type = field[7]
1✔
1298
    undef2 = field[8..9]
1✔
1299
    gov_pub = field[10]
1✔
1300
    item_form = field[11]
1✔
1301
    undef3 = field[12]
1✔
1302
    index = field[13]
1✔
1303
    undef4 = field[14]
1✔
1304
    format = field[15..16]
1✔
1305
    return true unless relief == '||||' || relief =~ relief_codes
1✔
1306
    return true unless proj_codes.include?(proj)
1✔
1307
    return true unless [' ', '|'].include?(undef1)
×
1308
    return true unless type =~ map_type_codes
×
1309
    return true unless ['||', '  '].include?(undef2)
×
1310
    return true unless gov_pub =~ gov_pub_codes
×
1311
    return true unless item_form =~ item_form_codes
×
1312
    return true unless [' ', '|'].include?(undef3)
×
1313
    return true unless %w[0 1 |].include?(index)
×
1314
    return true unless [' ', '|'].include?(undef4)
×
1315
    return true unless format == '||' || format =~ map_special_format_codes
×
1316

1317
    false
×
1318
  end
1319

1320
  def music_008(field)
1✔
1321
    comp_form = field[0..1]
1✔
1322
    music_format = field[2]
1✔
1323
    parts = field[3]
1✔
1324
    audience = field[4]
1✔
1325
    item_form = field[5]
1✔
1326
    accompanying = field[6..11]
1✔
1327
    lit_text = field[12..13]
1✔
1328
    undef1 = field[14]
1✔
1329
    transpose = field[15]
1✔
1330
    undef2 = field[16]
1✔
1331
    return true unless composition_codes.include?(comp_form)
1✔
1332
    return true unless music_format =~ music_format_codes
×
1333
    return true unless parts =~ music_part_codes
×
1334
    return true unless audience =~ audience_codes
×
1335
    return true unless item_form =~ item_form_codes
×
1336
    return true unless accompanying == '||||||' || accompanying =~ accompany_codes
×
1337
    return true unless lit_text == '||' || lit_text =~ lit_text_codes
×
1338
    return true unless [' ', '|'].include?(undef1)
×
1339
    return true unless transpose =~ transpose_codes
×
1340
    return true unless [' ', '|'].include?(undef2)
×
1341

1342
    false
×
1343
  end
1344

1345
  def continuing_resource_008(field)
1✔
1346
    freq = field[0]
1✔
1347
    reg = field[1]
1✔
1348
    undef1 = field[2]
1✔
1349
    cr_type = field[3]
1✔
1350
    item_orig_form = field[4]
1✔
1351
    item_form = field[5]
1✔
1352
    work_nature = field[6]
1✔
1353
    contents = field[7..9]
1✔
1354
    gov_pub = field[10]
1✔
1355
    conf_pub = field[11]
1✔
1356
    undef2 = field[12..14]
1✔
1357
    orig_script = field[15]
1✔
1358
    entry = field[16]
1✔
1359
    return true unless freq =~ freq_codes
1✔
1360
    return true unless %w[n r u x |].include?(reg)
1✔
1361
    return true unless [' ', '|'].include?(undef1)
×
1362
    return true unless cr_type =~ cr_type_codes
×
1363
    return true unless item_orig_form =~ item_orig_form_codes
×
1364
    return true unless item_form =~ item_form_codes
×
1365
    return true unless work_nature == '|' || work_nature =~ cr_contents_codes
×
1366
    return true unless contents == '|||' || contents =~ cr_contents_codes
×
1367
    return true unless gov_pub =~ gov_pub_codes
×
1368
    return true unless ['0', '1', '|'].include?(conf_pub)
×
1369
    return true unless ['   ', '|||'].include?(undef2)
×
1370
    return true unless orig_script =~ orig_script_codes
×
1371
    return true unless %w[0 1 2 |].include?(entry)
×
1372

1373
    false
×
1374
  end
1375

1376
  def visual_008(field)
1✔
1377
    runtime = field[0..2]
1✔
1378
    undef1 = field[3]
1✔
1379
    audience = field[4]
1✔
1380
    undef2 = field[5..9]
1✔
1381
    gov_pub = field[10]
1✔
1382
    item_form = field[11]
1✔
1383
    undef3 = field[12..14]
1✔
1384
    visual_type = field[15]
1✔
1385
    technique = field[16]
1✔
1386
    return true unless %w[nnn --- |||].include?(runtime) || runtime =~ /^[0-9]{3}$/
1✔
1387
    return true unless [' ', '|'].include?(undef1)
×
1388
    return true unless audience =~ audience_codes
×
1389
    return true unless ['     ', '|||||'].include?(undef2)
×
1390
    return true unless gov_pub =~ gov_pub_codes
×
1391
    return true unless item_form =~ item_form_codes
×
1392
    return true unless ['   ', '|||'].include?(undef3)
×
1393
    return true unless visual_type =~ visual_type_codes
×
1394
    return true unless %w[a c l n u z |].include?(technique)
×
1395

1396
    false
×
1397
  end
1398

1399
  def mix_mat_008(field)
1✔
1400
    undef1 = field[0..4]
1✔
1401
    item_form = field[5]
1✔
1402
    undef2 = field[6..16]
1✔
1403
    return true unless ['     ', '|||||'].include?(undef1)
1✔
1404
    return true unless item_form =~ item_form_codes
×
1405
    return true unless ['           ', '|||||||||||'].include?(undef2)
×
1406

1407
    false
×
1408
  end
1409

1410
  def book
1✔
1411
    %w[
1412
      aa
8✔
1413
      ac
1414
      ad
1415
      am
1416
      ta
1417
      tc
1418
      td
1419
      tm
1420
    ]
1421
  end
1422

1423
  def comp_file
1✔
1424
    %w[
1425
      ma
6✔
1426
      mb
1427
      mc
1428
      md
1429
      mi
1430
      mm
1431
      ms
1432
    ]
1433
  end
1434

1435
  def map
1✔
1436
    %w[
1437
      ea
5✔
1438
      eb
1439
      ec
1440
      ed
1441
      ei
1442
      em
1443
      es
1444
      fa
1445
      fb
1446
      fc
1447
      fd
1448
      fi
1449
      fm
1450
      fs
1451
    ]
1452
  end
1453

1454
  def music
1✔
1455
    %w[
1456
      ca
4✔
1457
      cb
1458
      cc
1459
      cd
1460
      ci
1461
      cm
1462
      cs
1463
      da
1464
      db
1465
      dc
1466
      dd
1467
      di
1468
      dm
1469
      ds
1470
      ia
1471
      ib
1472
      ic
1473
      id
1474
      ii
1475
      im
1476
      is
1477
      ja
1478
      jb
1479
      jc
1480
      jd
1481
      ji
1482
      jm
1483
      js
1484
    ]
1485
  end
1486

1487
  def continuing_resource
1✔
1488
    %w[
1489
      ab
3✔
1490
      ai
1491
      as
1492
      tb
1493
      ti
1494
      ts
1495
    ]
1496
  end
1497

1498
  def visual
1✔
1499
    %w[
1500
      ga
2✔
1501
      gb
1502
      gc
1503
      gd
1504
      gi
1505
      gm
1506
      gs
1507
      ka
1508
      kb
1509
      kc
1510
      kd
1511
      ki
1512
      km
1513
      ks
1514
      oa
1515
      ob
1516
      oc
1517
      od
1518
      oi
1519
      om
1520
      os
1521
      ra
1522
      rb
1523
      rc
1524
      rd
1525
      ri
1526
      rm
1527
      rs
1528
    ]
1529
  end
1530

1531
  def mixed
1✔
1532
    %w[
1533
      pa
1✔
1534
      pb
1535
      pc
1536
      pd
1537
      pi
1538
      pm
1539
      ps
1540
    ]
1541
  end
1542

1543
  def bad_005?(record)
1✔
1544
    field = record['005']
×
1545
    return false unless field
×
1546

1547
    field.value =~ /^[0-9]{14}\.[0-9]$/ ? false : true
×
1548
  end
1549

1550
  # Uses same methods as the specific 008 methods
1551
  def bad_006?(record)
1✔
1552
    fields = record.fields('006')
×
1553
    return false if fields.empty?
×
1554

1555
    fields.each do |field|
×
1556
      return true if field.value.length != 18
×
1557

1558
      rec_type = field.value[0]
×
1559
      specific_006 = field.value[1..-1]
×
1560
      case rec_type
×
1561
      when 'a', 't'
1562
        return true if book_008(specific_006)
×
1563
      when 'm'
1564
        return true if comp_008(specific_006)
×
1565
      when 'e', 'f'
1566
        return true if map_008(specific_006)
×
1567
      when 'c', 'd', 'i', 'j'
1568
        return true if music_008(specific_006)
×
1569
      when 's'
1570
        return true if continuing_resource_008(specific_006)
×
1571
      when 'g', 'k', 'o', 'r'
1572
        return true if visual_008(specific_006)
×
1573
      when 'p'
1574
        return true if mix_mat_008(specific_006)
×
1575
      end
1576
    end
1577
    false
×
1578
  end
1579

1580
  def map_007(field)
1✔
1581
    return true unless field.length == 7
×
1582
    return true unless %w[d g j k q r s u y z |].include?(field[0])
×
1583
    return true unless field[1] == ' '
×
1584
    return true unless %w[a c |].include?(field[2])
×
1585
    return true unless %w[a b c d e f g i j l n p q r s t u v w x y z |].include?(field[3])
×
1586
    return true unless %w[f n u z |].include?(field[4])
×
1587
    return true unless %w[a b c d u z |].include?(field[5])
×
1588
    return true unless %w[a b m n |].include?(field[6])
×
1589

1590
    false
×
1591
  end
1592

1593
  def elec_007(field)
1✔
1594
    return true unless field.length == 13
×
1595
    return true unless %w[a b c d e f h j k m o r s u z |].include?(field[0])
×
1596
    return true unless field[1] == ' '
×
1597
    return true unless %w[a b c g m n u z |].include?(field[2])
×
1598
    return true unless %w[a e g i j n o u v z |].include?(field[3])
×
1599
    return true unless %w[\  a u |].include?(field[4])
×
1600
    return true unless %w[mmm nnn --- |||].include?(field[5..7]) || field[5..7] =~ /^[0-9]{3}$/
×
1601
    return true unless %w[a m u |].include?(field[8])
×
1602
    return true unless %w[a n p u |].include?(field[9])
×
1603
    return true unless %w[a b c d m n u |].include?(field[10])
×
1604
    return true unless %w[a b d m u |].include?(field[11])
×
1605
    return true unless %w[a n p r u |].include?(field[12])
×
1606

1607
    false
×
1608
  end
1609

1610
  def globe_007(field)
1✔
1611
    return true unless field.length == 5
×
1612
    return true unless %w[a b c e u z |].include?(field[0])
×
1613
    return true unless field[1] == ' '
×
1614
    return true unless %w[a c |].include?(field[2])
×
1615
    return true unless %w[a b c d e f g i l n p u v w z |].include?(field[3])
×
1616
    return true unless %w[f n u z |].include?(field[4])
×
1617

1618
    false
×
1619
  end
1620

1621
  def tactile_007(field)
1✔
1622
    return true unless field.length == 9
×
1623
    return true unless %w[a b c d u z |].include?(field[0])
×
1624
    return true unless field[1] == ' '
×
1625
    return true unless field[2..3] == '||' || field[2..3] =~ /^[abcdemnuz ]{2}$/
×
1626
    return true unless %w[a b m n u z |].include?(field[4])
×
1627
    return true unless field[5..7] == '||' || field[5..7] =~ /^[abcdefghijklnuz ]{3}$/
×
1628
    return true unless %w[a b n u z |].include?(field[8])
×
1629

1630
    false
×
1631
  end
1632

1633
  def proj_graphic_007(field)
1✔
1634
    return true unless field.length == 8
×
1635
    return true unless %w[c d f o s t u z |].include?(field[0])
×
1636
    return true unless field[1] == ' '
×
1637
    return true unless %w[a b c h m n u z |].include?(field[2])
×
1638
    return true unless %w[d e j k m o u z |].include?(field[3])
×
1639
    return true unless %w[\  a b u |].include?(field[4])
×
1640
    return true unless %w[\  a b c d e f g h i u z |].include?(field[5])
×
1641
    return true unless %w[a b c d e f g j k s t v w x y u z |].include?(field[6])
×
1642
    return true unless %w[\  c d e h j k m u z |].include?(field[7])
×
1643

1644
    false
×
1645
  end
1646

1647
  def microform_007(field)
1✔
1648
    return true unless field.length == 12
×
1649
    return true unless %w[a b c d e f g h j u z |].include?(field[0])
×
1650
    return true unless field[1] == ' '
×
1651
    return true unless %w[a b m u |].include?(field[2])
×
1652
    return true unless %w[a d f g h l m o p u z |].include?(field[3])
×
1653
    return true unless %w[a b c d e u v |].include?(field[4])
×
1654
    return true unless field[5..7] == '|||' || field[5..7] =~ /^[0-9]+[\-]*$/
×
1655
    return true unless %w[a m u |].include?(field[8])
×
1656
    return true unless %w[a n p u |].include?(field[9])
×
1657
    return true unless %w[a b c d m n u |].include?(field[10])
×
1658
    return true unless %w[a b d m u |].include?(field[11])
×
1659
    return true unless %w[a n p r u |].include?(field[12])
×
1660

1661
    false
×
1662
  end
1663

1664
  def nonproj_graphic_007(field)
1✔
1665
    return true unless field.length == 5
×
1666
    return true unless %w[a c d e f g h i j k l n o p q r s u v z |].include?(field[0])
×
1667
    return true unless field[1] == ' '
×
1668
    return true unless %w[a b c h m u z |].include?(field[2])
×
1669
    return true unless %w[a b c d e f g h i l m n o p q r s t u v w z |].include?(field[3])
×
1670
    return true unless %w[\  a b c d e f g h i l m n o p q r s t u v w z |].include?(field[4])
×
1671

1672
    false
×
1673
  end
1674

1675
  def motion_pict_007(field)
1✔
1676
    return true unless field.length > 6
×
1677
    return true unless %w[c f o r u z |].include?(field[0])
×
1678
    return true unless field[1] == ' '
×
1679
    return true unless %w[b c h m n u z |].include?(field[2])
×
1680
    return true unless %w[a b c d e f u z |].include?(field[3])
×
1681
    return true unless %w[\  a b u |].include?(field[4])
×
1682
    return true unless %w[\  a b c d e f g h i u z |].include?(field[5])
×
1683
    return true unless %w[a b c d e f g u z |].include?(field[6])
×
1684
    return true unless field[7].nil? || field[7] =~ /[kmnqsuz|]/
×
1685
    return true unless field[8].nil? || field[8] =~ /[a-gnz|]/
×
1686
    return true unless field[9].nil? || field[9] =~ /[abnuz|]/
×
1687
    return true unless field[10].nil? || field[10] =~ /[deoruz|]/
×
1688
    return true unless field[11].nil? || field[11] =~ /[acdimnprtuz|]/
×
1689
    return true unless field[12].nil? || field[12] =~ /[a-np-vz|]/
×
1690
    return true unless field[13].nil? || field[13] =~ /[abcdnuz|]/
×
1691
    return true unless field[14].nil? || field[14] =~ /[a-hklm|]/
×
1692
    return true unless field[15].nil? || field[15] =~ /[cinu|]/
×
1693

1694
    inspect_date = field[16..21]
×
1695
    case inspect_date
×
1696
    when '||||||', '------'
1697
      false
×
1698
    when /^[0-9]+[\-]*$/
1699
      false
×
1700
    else
1701
      true
×
1702
    end
1703
  end
1704

1705
  def kit_mus_007(field)
1✔
1706
    return true unless field.length == 1
×
1707

1708
    %w[u |].include?(field[0]) ? false : true
×
1709
  end
1710

1711
  def remote_data_types
1✔
1712
    %w[
1713
      aa
×
1714
      da
1715
      db
1716
      dc
1717
      dd
1718
      de
1719
      df
1720
      dv
1721
      dz
1722
      ga
1723
      gb
1724
      gc
1725
      gd
1726
      ge
1727
      gf
1728
      gg
1729
      gu
1730
      gz
1731
      ja
1732
      jb
1733
      jc
1734
      jv
1735
      jz
1736
      ma
1737
      mb
1738
      mm
1739
      nn
1740
      pa
1741
      pb
1742
      pc
1743
      pd
1744
      pe
1745
      pz
1746
      ra
1747
      rb
1748
      rc
1749
      rd
1750
      sa
1751
      ta
1752
      uu
1753
      zz
1754
      ||
1755
    ]
1756
  end
1757

1758
  def remote_007(field)
1✔
1759
    return true unless field.length == 10
×
1760
    return true unless field[0] =~ /[u|]/
×
1761
    return true unless field[1] == ' '
×
1762
    return true unless field[2] =~ /[abcnuz|]/
×
1763
    return true unless field[3] =~ /[abcnu|]/
×
1764
    return true unless field[4] =~ /[0-9nu|]/
×
1765
    return true unless field[5] =~ /[a-inuz|]/
×
1766
    return true unless field[6] =~ /[abcmnuz|]/
×
1767
    return true unless field[7] =~ /[abuz|]/
×
1768
    return true unless remote_data_types.include? field[8..9]
×
1769

1770
    false
×
1771
  end
1772

1773
  def recording_007(field)
1✔
1774
    return true unless field.length == 13
×
1775
    return true unless %w[d e g i q r s t u w z |].include?(field[0])
×
1776
    return true unless field[1] == ' '
×
1777
    return true unless field[2] =~ /[a-fhik-pruz|]/
×
1778
    return true unless field[3] =~ /[mqsuz|]/
×
1779
    return true unless field[4] =~ /[mnsuz|]/
×
1780
    return true unless field[5] =~ /[a-gjnosuz|]/
×
1781
    return true unless field[6] =~ /[l-puz|]/
×
1782
    return true unless field[7] =~ /[a-fnuz|]/
×
1783
    return true unless field[8] =~ /[abdimnrstuz|]/
×
1784
    return true unless field[9] =~ /[abcgilmnprswuz|]/
×
1785
    return true unless field[10] =~ /[hlnu|]/
×
1786
    return true unless field[11] =~ /[a-hnuz|]/
×
1787
    return true unless field[12] =~ /[abdeuz|]/
×
1788

1789
    false
×
1790
  end
1791

1792
  def text_007(field)
1✔
1793
    return true unless field.length == 1
×
1794

1795
    %w[a b c d u z |].include?(field[0]) ? false : true
×
1796
  end
1797

1798
  def video_007(field)
1✔
1799
    return true unless field.length == 8
×
1800
    return true unless %w[c d f r u z |].include?(field[0])
×
1801
    return true unless field[1] == ' '
×
1802
    return true unless %w[a b c m n u z |].include?(field[2])
×
1803
    return true unless field[3] =~ /[a-kmopqsuvz|]/
×
1804
    return true unless %w[\  a b u |].include?(field[4])
×
1805
    return true unless %w[\  a b c d e f g h i u z |].include?(field[5])
×
1806
    return true unless %w[a m o p q r u z |].include?(field[6])
×
1807
    return true unless %w[k m n q s u z |].include?(field[7])
×
1808

1809
    false
×
1810
  end
1811

1812
  def unspec_007(field)
1✔
1813
    return true unless field.length == 1
×
1814

1815
    %w[m u z |].include?(field[0]) ? false : true
×
1816
  end
1817

1818
  def bad_007?(record)
1✔
1819
    fields = record.fields('007')
×
1820
    return false if fields.empty?
×
1821

1822
    fields.each do |field|
×
1823
      rec_type = field.value[0]
×
1824
      specific_f007 = field.value[1..-1]
×
1825
      return true unless specific_f007
×
1826

1827
      case rec_type
×
1828
      when 'a'
1829
        return true if map_007(specific_f007)
×
1830
      when 'c'
1831
        return true if elec_007(specific_f007)
×
1832
      when 'd'
1833
        return true if globe_007(specific_f007)
×
1834
      when 'f'
1835
        return true if tactile_007(specific_f007)
×
1836
      when 'g'
1837
        return true if proj_graphic_007(specific_f007)
×
1838
      when 'h'
1839
        return true if microform_007(specific_f007)
×
1840
      when 'k'
1841
        return true if nonproj_graphic_007(specific_f007)
×
1842
      when 'm'
1843
        return true if motion_pict_007(specific_f007)
×
1844
      when 'o' || 'q'
1845
        return true if kit_mus_007(specific_f007)
×
1846
      when 'r'
1847
        return true if remote_007(specific_f007)
×
1848
      when 's'
1849
        return true if recording_007(specific_f007)
×
1850
      when 't'
1851
        return true if text_007(specific_f007)
×
1852
      when 'v'
1853
        return true if video_007(specific_f007)
×
1854
      when 'z'
1855
        return true if unspec_007(specific_f007)
×
1856
      else
1857
        return true
×
1858
      end
1859
    end
1860
    false
×
1861
  end
1862

1863
  def bad_008_length?(record)
1✔
1864
    field = record['008'].value
×
1865
    field.length != 40
×
1866
  end
1867

1868
  def bad_008?(record)
1✔
1869
    field = record['008'].value
7✔
1870
    return true if field.length != 40
7✔
1871
    return true if all_008(field)
7✔
1872

1873
    rec_type = record.leader[6..7]
7✔
1874
    specific_f008 = field[18..34]
7✔
1875
    if book.include?(rec_type)
7✔
1876
      return true if book_008(specific_f008)
1✔
1877
    elsif comp_file.include?(rec_type)
6✔
1878
      return true if comp_008(specific_f008)
1✔
1879
    elsif map.include?(rec_type)
5✔
1880
      return true if map_008(specific_f008)
1✔
1881
    elsif music.include?(rec_type)
4✔
1882
      return true if music_008(specific_f008)
1✔
1883
    elsif continuing_resource.include?(rec_type)
3✔
1884
      return true if continuing_resource_008(specific_f008)
1✔
1885
    elsif visual.include?(rec_type)
2✔
1886
      return true if visual_008(specific_f008)
1✔
1887
    elsif mixed.include?(rec_type)
1✔
1888
      return true if mix_mat_008(specific_f008)
1✔
1889
    end
1890
    false
×
1891
  end
1892

1893
  ### Replace obsolete values with current values when possible
1894
  def fix_007(record)
1✔
1895
    target_fields = record.fields('007')
×
1896
    return record if target_fields.empty?
×
1897

1898
    target_fields.each do |field|
×
1899
      field_index = record.fields.index(field)
×
1900
      field_value = field.value
×
1901
      rec_type = field_value[0]
×
1902
      next unless %w[a c d f g h k m o q r s t v z].include? rec_type
×
1903

1904
      fixed_007 = rec_type
×
1905
      specific_007 = field_value[1..-1]
×
1906
      next unless specific_007
×
1907

1908
      case rec_type
×
1909
      when 'a'
1910
        fixed_007 << fix_map_007(specific_007)
×
1911
      when 'c'
1912
        fixed_007 << fix_electronic_007(specific_007)
×
1913
      when 'd'
1914
        fixed_007 << fix_globe_007(specific_007)
×
1915
      when 'f'
1916
        fixed_007 << fix_tactile_007(specific_007)
×
1917
      when 'g'
1918
        fixed_007 << fix_proj_007(specific_007)
×
1919
      when 'h'
1920
        fixed_007 << fix_microform_007(specific_007)
×
1921
      when 'k'
1922
        fixed_007 << fix_nonproj_007(specific_007)
×
1923
      when 'm'
1924
        fixed_007 << fix_motion_pic_007(specific_007)
×
1925
      when 'o'
1926
        fixed_007 << fix_kit_007(specific_007)
×
1927
      when 'q'
1928
        fixed_007 << fix_notated_mus_007(specific_007)
×
1929
      when 'r'
1930
        fixed_007 << fix_remote_007(specific_007)
×
1931
      when 's'
1932
        fixed_007 << fix_sound_rec_007(specific_007)
×
1933
      when 't'
1934
        fixed_007 << fix_text_007(specific_007)
×
1935
      when 'v'
1936
        fixed_007 << fix_video_007(specific_007)
×
1937
      when 'z'
1938
        fixed_007 << fix_unspec_007(specific_007)
×
1939
      end
1940
      record.fields[field_index].value = fixed_007
×
1941
    end
1942
    record
×
1943
  end
1944

1945
  def fix_map_007(specific_007)
1✔
1946
    return specific_007 unless specific_007.length == 7
×
1947

1948
    fixed_field = ''
×
1949
    mat_designation = specific_007[0]
×
1950
    color = specific_007[2]
×
1951
    color.gsub!('b', 'c')
×
1952
    medium = specific_007[3]
×
1953
    medium.gsub!(/[^a-gijlnp-z|]/, 'u')
×
1954
    repro_type = specific_007[4]
×
1955
    repro_type.gsub!(/[^fnuz|]/, 'u')
×
1956
    prod_details = specific_007[5]
×
1957
    prod_details.gsub!(/[^abcduz|]/, 'u')
×
1958
    aspect = specific_007[6]
×
1959
    aspect.gsub!('u', '|')
×
1960
    fixed_field << mat_designation
×
1961
    fixed_field << ' '
×
1962
    fixed_field << color
×
1963
    fixed_field << medium
×
1964
    fixed_field << repro_type
×
1965
    fixed_field << prod_details
×
1966
    fixed_field << aspect
×
1967
    fixed_field
×
1968
  end
1969

1970
  def fix_electronic_007(specific_007)
1✔
1971
    return specific_007 unless specific_007.length > 4
×
1972

1973
    fixed_field = ''
×
1974
    mat_designation = specific_007[0]
×
1975
    mat_designation.gsub!(/[^a-fhjkmorsuz|]/, 'u')
×
1976
    color = specific_007[2]
×
1977
    color.gsub!(/[^abcghmnuz|]/, 'u')
×
1978
    dimensions = specific_007[3]
×
1979
    dimensions.gsub!(/[^aegijnouvz|]/, 'u')
×
1980
    sound = specific_007[4]
×
1981
    sound.gsub!(/[^ au|]/, 'u')
×
1982
    fixed_field << mat_designation
×
1983
    fixed_field << ' '
×
1984
    fixed_field << color
×
1985
    fixed_field << dimensions
×
1986
    fixed_field << sound
×
1987
    return fixed_field if specific_007.length == 5
×
1988

1989
    bit_depth = specific_007[5..7]
×
1990
    unless %w[mmm nnn --- |||].include? bit_depth
×
1991
      bit_depth =~ /^[0-9]{3}$/ ? bit_depth : '---'
×
1992
    end
1993
    fixed_field << bit_depth
×
1994
    formats = specific_007[8]
×
1995
    return fixed_field unless formats
×
1996

1997
    formats.gsub!(/[^amu|]/, 'u')
×
1998
    fixed_field << formats
×
1999
    quality = specific_007[9]
×
2000
    return fixed_field unless quality
×
2001

2002
    quality.gsub!(/[^anpu|]/, 'u')
×
2003
    fixed_field << quality
×
2004
    source = specific_007[10]
×
2005
    return fixed_field unless source
×
2006

2007
    source.gsub!(/[^abcdmnu|]/, 'u')
×
2008
    fixed_field << source
×
2009
    compression = specific_007[11]
×
2010
    return fixed_field unless compression
×
2011

2012
    compression.gsub!(/[^abdmu|]/, 'u')
×
2013
    fixed_field << compression
×
2014
    reformatting = specific_007[12]
×
2015
    return fixed_field unless reformatting
×
2016

2017
    reformatting.gsub!(/[^anpru|]/, 'u')
×
2018
    fixed_field << reformatting
×
2019
    fixed_field
×
2020
  end
2021

2022
  def fix_globe_007(specific_007)
1✔
2023
    return specific_007 unless specific_007.length == 7
×
2024

2025
    fixed_field = ''
×
2026
    mat_designation = specific_007[0]
×
2027
    mat_designation.gsub!(/[^abcdeuz|]/, 'u')
×
2028
    color = specific_007[2]
×
2029
    color.gsub!('b', 'c')
×
2030
    medium = specific_007[3]
×
2031
    medium.gsub!(/[^a-gilnpuvwz|]/, 'u')
×
2032
    repro_type = specific_007[4]
×
2033
    repro_type.gsub!(/[^fnuz|]/, 'u')
×
2034
    fixed_field << mat_designation
×
2035
    fixed_field << ' '
×
2036
    fixed_field << color
×
2037
    fixed_field << medium
×
2038
    fixed_field << repro_type
×
2039
    fixed_field
×
2040
  end
2041

2042
  def fix_tactile_007(specific_007)
1✔
2043
    return specific_007 unless specific_007.length == 9
×
2044

2045
    fixed_field = ''
×
2046
    mat_designation = specific_007[0]
×
2047
    mat_designation.gsub!(/[^abcduz|]/, 'u')
×
2048
    writing = specific_007[2..3]
×
2049
    unless writing == '||'
×
2050
      writing_chars = writing.chars.select { |c| c =~ /[a-emnuz]/ }.sort.join('')
×
2051
      writing = writing_chars.ljust(2)
×
2052
    end
2053
    contraction = specific_007[4]
×
2054
    contraction.gsub!(/[^abmnuz|]/, 'u')
×
2055
    music = specific_007[5..7]
×
2056
    unless music == '|||'
×
2057
      music_chars = music.chars.select { |c| c =~ /[a-lnuz]/ }.sort.join('')
×
2058
      music = music_chars.ljust(3)
×
2059
    end
2060
    special = specific_007[8]
×
2061
    special.gsub!(/[^abnuz|]/, 'u')
×
2062
    fixed_field << mat_designation
×
2063
    fixed_field << ' '
×
2064
    fixed_field << writing
×
2065
    fixed_field << contraction
×
2066
    fixed_field << music
×
2067
    fixed_field << special
×
2068
    fixed_field
×
2069
  end
2070

2071
  def fix_proj_007(specific_007)
1✔
2072
    return specific_007 unless specific_007.length == 8
×
2073

2074
    fixed_field = ''
×
2075
    mat_designation = specific_007[0]
×
2076
    mat_designation.gsub!(/[^cdfostuz|]/, 'u')
×
2077
    color = specific_007[2]
×
2078
    color.gsub!(/[^abchmnuz|]/, 'u')
×
2079
    base = specific_007[3]
×
2080
    base.gsub!(/[^dejkmouz|]/, 'u')
×
2081
    sound_on_medium = specific_007[4]
×
2082
    sound_on_medium.gsub!(/[^ abu|]/, 'u')
×
2083
    sound_medium = specific_007[5]
×
2084
    sound_medium.gsub!(/[^ a-iuz|]/, 'u')
×
2085
    dimensions = specific_007[6]
×
2086
    dimensions.gsub!(/[^a-gjkst-z|]/, 'u')
×
2087
    support = specific_007[7]
×
2088
    support.gsub!(/[^ cdehjkmuz|]/, 'u')
×
2089
    fixed_field << mat_designation
×
2090
    fixed_field << ' '
×
2091
    fixed_field << color
×
2092
    fixed_field << base
×
2093
    fixed_field << sound_on_medium
×
2094
    fixed_field << sound_medium
×
2095
    fixed_field << dimensions
×
2096
    fixed_field << support
×
2097
    fixed_field
×
2098
  end
2099

2100
  def fix_microform_007(specific_007)
1✔
2101
    return specific_007 unless specific_007.length == 12
×
2102

2103
    fixed_field = ''
×
2104
    mat_designation = specific_007[0]
×
2105
    mat_designation.gsub!(/[^a-hjuz|]/, 'u')
×
2106
    aspect = specific_007[2]
×
2107
    aspect.gsub!(/[^abmu|]/, 'u')
×
2108
    dimensions = specific_007[3]
×
2109
    dimensions.gsub!(/[^adfghlmopuz|]/, 'u')
×
2110
    reduction_range = specific_007[4]
×
2111
    reduction_range.gsub!(/[^a-euv|]/, 'u')
×
2112
    reduction_ratio = specific_007[5..7]
×
2113
    unless %w[--- |||].include? reduction_ratio
×
2114
      reduction_ratio =~ /^[0-9]/ ? reduction_ratio : '---'
×
2115
      reduction_nums = reduction_ratio.chars.select { |c| c =~ /[0-9]/ }.join('')
×
2116
      reduction_ratio = reduction_nums.ljust(3, '-')
×
2117
    end
2118
    color = specific_007[8]
×
2119
    color.gsub!(/[^bcmuz|]/, 'u')
×
2120
    emulsion = specific_007[9]
×
2121
    emulsion.gsub!(/[^abcmnuz|]/, 'u')
×
2122
    generation = specific_007[10]
×
2123
    generation.gsub!(/[^abcmu|]/, 'u')
×
2124
    base = specific_007[11]
×
2125
    base.gsub!(/[^abcdimnprtuz|]/, 'u')
×
2126
    fixed_field << mat_designation
×
2127
    fixed_field << ' '
×
2128
    fixed_field << aspect
×
2129
    fixed_field << dimensions
×
2130
    fixed_field << reduction_range
×
2131
    fixed_field << reduction_ratio
×
2132
    fixed_field << color
×
2133
    fixed_field << emulsion
×
2134
    fixed_field << generation
×
2135
    fixed_field << base
×
2136
    fixed_field
×
2137
  end
2138

2139
  def fix_nonproj_007(specific_007)
1✔
2140
    return specific_007 unless specific_007.length == 5
×
2141

2142
    fixed_field = ''
×
2143
    mat_designation = specific_007[0]
×
2144
    mat_designation.gsub!(/[^ac-ln-suvz|]/, 'u')
×
2145
    color = specific_007[2]
×
2146
    color.gsub!(/[^abchmuz|]/, 'u')
×
2147
    primary_support = specific_007[3]
×
2148
    primary_support.gsub!(/[^a-il-wz|]/, 'u')
×
2149
    secondary_support = specific_007[4]
×
2150
    secondary_support.gsub!(/[^ a-il-wz|]/, 'u')
×
2151
    fixed_field << mat_designation
×
2152
    fixed_field << ' '
×
2153
    fixed_field << color
×
2154
    fixed_field << primary_support
×
2155
    fixed_field << secondary_support
×
2156
    fixed_field
×
2157
  end
2158

2159
  def fix_motion_pic_007(specific_007)
1✔
2160
    return specific_007 unless specific_007.length > 6
×
2161

2162
    fixed_field = ''
×
2163
    mat_designation = specific_007[0]
×
2164
    mat_designation.gsub!(/[^cdforuz|]/, 'u')
×
2165
    color = specific_007[2]
×
2166
    color.gsub!(/[^bchmnuz|]/, 'u')
×
2167
    presentation = specific_007[3]
×
2168
    presentation.gsub!(/[^a-fuz|]/, 'u')
×
2169
    sound_on_medium = specific_007[4]
×
2170
    sound_on_medium.gsub!(/[^ abu|]/, 'u')
×
2171
    sound_medium = specific_007[5]
×
2172
    sound_medium.gsub!(/[^ a-iuz|]/, 'u')
×
2173
    dimensions = specific_007[6]
×
2174
    dimensions.gsub!(/[^a-guz|]/, 'u')
×
2175
    fixed_field << mat_designation
×
2176
    fixed_field << ' '
×
2177
    fixed_field << color
×
2178
    fixed_field << presentation
×
2179
    fixed_field << sound_on_medium
×
2180
    fixed_field << sound_medium
×
2181
    fixed_field << dimensions
×
2182
    return fixed_field if specific_007.length == 7
×
2183

2184
    channels = specific_007[7]
×
2185
    channels.gsub!(/[^kmnqsuz|]/, 'u')
×
2186
    fixed_field << channels
×
2187
    elements = specific_007[8]
×
2188
    return fixed_field unless elements
×
2189

2190
    elements.gsub!('h', 'z')
×
2191
    elements.gsub!(/[^abcdefgnz|]/, '|')
×
2192
    fixed_field << elements
×
2193
    aspect = specific_007[9]
×
2194
    return fixed_field unless aspect
×
2195

2196
    aspect.gsub!(/[^abnuz|]/, 'u')
×
2197
    fixed_field << aspect
×
2198
    generation = specific_007[10]
×
2199
    return fixed_field unless generation
×
2200

2201
    generation.gsub!(/[^deoruz|]/, 'u')
×
2202
    fixed_field << generation
×
2203
    base = specific_007[11]
×
2204
    return fixed_field unless base
×
2205

2206
    base.gsub!(/[^acdimnprtuz|]/, 'u')
×
2207
    fixed_field << base
×
2208
    refined = specific_007[12]
×
2209
    return fixed_field unless refined
×
2210

2211
    refined.gsub!(/[^a-np-vz|]/, 'u')
×
2212
    fixed_field << refined
×
2213
    stock = specific_007[13]
×
2214
    return fixed_field unless stock
×
2215

2216
    stock.gsub!(/[^abcdnuz|]/, 'u')
×
2217
    fixed_field << stock
×
2218
    deterioration = specific_007[14]
×
2219
    return fixed_field unless deterioration
×
2220

2221
    deterioration.gsub!(/[^abcdefghklm|]/, '|')
×
2222
    fixed_field << deterioration
×
2223
    completeness = specific_007[15]
×
2224
    return fixed_field unless completeness
×
2225

2226
    completeness.gsub!(/[^cinu|]/, 'u')
×
2227
    fixed_field << completeness
×
2228
    return fixed_field if specific_007.length == 16
×
2229

2230
    inspect_date = specific_007[16..21]
×
2231
    inspect_date.gsub!(/[^0-9\-]/, '-')
×
2232
    fixed_field << inspect_date
×
2233
    fixed_field
×
2234
  end
2235

2236
  def fix_kit_007(specific_007)
1✔
2237
    mat_designation = specific_007[0]
×
2238
    mat_designation.gsub(/[^u|]/, 'u')
×
2239
  end
2240

2241
  def fix_notated_mus_007(specific_007)
1✔
2242
    mat_designation = specific_007[0]
×
2243
    mat_designation.gsub(/[^u|]/, 'u')
×
2244
  end
2245

2246
  def fix_remote_007(specific_007)
1✔
2247
    return specific_007 unless specific_007.length == 10
×
2248

2249
    fixed_field = ''
×
2250
    mat_designation = specific_007[0]
×
2251
    mat_designation.gsub!(/[^u|]/, 'u')
×
2252
    altitude = specific_007[2]
×
2253
    altitude.gsub!(/[^abcnuz|]/, 'u')
×
2254
    attitude = specific_007[3]
×
2255
    attitude.gsub!(/[^abcnuz|]/, 'u')
×
2256
    clouds = specific_007[4]
×
2257
    clouds.gsub!(/[^0-9nu|]/, 'u')
×
2258
    construction = specific_007[5]
×
2259
    construction.gsub!(/[^a-inuz|]/, 'u')
×
2260
    use = specific_007[6]
×
2261
    use.gsub!(/[^abcmnuz|]/, 'u')
×
2262
    sensor = specific_007[7]
×
2263
    sensor.gsub!(/[^abuz|]/, 'u')
×
2264
    data_type = specific_007[8..9]
×
2265
    data_type = 'uu' unless remote_data_types.include? data_type
×
2266
    fixed_field << mat_designation
×
2267
    fixed_field << ' '
×
2268
    fixed_field << altitude
×
2269
    fixed_field << attitude
×
2270
    fixed_field << clouds
×
2271
    fixed_field << construction
×
2272
    fixed_field << use
×
2273
    fixed_field << sensor
×
2274
    fixed_field << data_type
×
2275
    fixed_field
×
2276
  end
2277

2278
  def fix_sound_rec_007(specific_007)
1✔
2279
    return specific_007 unless specific_007.length == 13
×
2280

2281
    fixed_field = ''
×
2282
    mat_designation = specific_007[0]
×
2283
    mat_designation = case mat_designation
×
2284
                      when 'c'
2285
                        'e'
×
2286
                      when 'f'
2287
                        'i'
×
2288
                      else
2289
                        mat_designation
×
2290
                      end
2291
    mat_designation.gsub!(/[^degiq-uwz|]/, 'u')
×
2292
    speed = specific_007[2]
×
2293
    speed.gsub!(/[^a-fhik-pruz|]/, 'u')
×
2294
    channels = specific_007[3]
×
2295
    channels.gsub!(/[^mqsuz|]/, 'u')
×
2296
    groove = specific_007[4]
×
2297
    groove.gsub!(/[^mnsuz|]/, 'u')
×
2298
    dimensions = specific_007[5]
×
2299
    dimensions.gsub!(/[^abcdefgjnosuz|]/, 'u')
×
2300
    width = specific_007[6]
×
2301
    width = case width
×
2302
            when 'a'
2303
              'm'
×
2304
            when 'b'
2305
              'o'
×
2306
            when 'c'
2307
              'p'
×
2308
            else
2309
              width
×
2310
            end
2311
    width.gsub!(/[^l-puz|]/, 'u')
×
2312
    configuration = specific_007[7]
×
2313
    configuration.gsub!(/[^abcdefnuz|]/, 'u')
×
2314
    disc_kind = specific_007[8]
×
2315
    disc_kind.gsub!(/[^abdimnrstuz|]/, 'u')
×
2316
    material = specific_007[9]
×
2317
    material.gsub!(/[^abcgilmnprswuz|]/, 'u')
×
2318
    cutting = specific_007[10]
×
2319
    cutting.gsub!(/[^hlnu|]/, 'u')
×
2320
    playback = specific_007[11]
×
2321
    playback.gsub!(/[^abcdefghnuz|]/, 'u')
×
2322
    storage = specific_007[12]
×
2323
    storage.gsub!(/[^abdeuz|]/, 'u')
×
2324
    fixed_field << mat_designation
×
2325
    fixed_field << ' '
×
2326
    fixed_field << speed
×
2327
    fixed_field << channels
×
2328
    fixed_field << groove
×
2329
    fixed_field << dimensions
×
2330
    fixed_field << width
×
2331
    fixed_field << configuration
×
2332
    fixed_field << disc_kind
×
2333
    fixed_field << material
×
2334
    fixed_field << cutting
×
2335
    fixed_field << playback
×
2336
    fixed_field << storage
×
2337
    fixed_field
×
2338
  end
2339

2340
  def fix_text_007(specific_007)
1✔
2341
    mat_designation = specific_007[0]
×
2342
    mat_designation.gsub(/[^abcduz|]/, 'u')
×
2343
  end
2344

2345
  def fix_video_007(specific_007)
1✔
2346
    return specific_007 unless specific_007.length == 8
×
2347

2348
    fixed_field = ''
×
2349
    mat_designation = specific_007[0]
×
2350
    mat_designation.gsub!(/[^cdfruz|]/, 'u')
×
2351
    color = specific_007[2]
×
2352
    color.gsub!(/[^abcmnuz|]/, 'u')
×
2353
    format = specific_007[3]
×
2354
    format.gsub!(/[^a-kmopqsuvz|]/, 'u')
×
2355
    sound_on_medium = specific_007[4]
×
2356
    sound_on_medium.gsub!(/[^ abu|]/, 'u')
×
2357
    sound_medium = specific_007[5]
×
2358
    sound_medium.gsub!(/[^ abcdefghiuz|]/, 'u')
×
2359
    dimensions = specific_007[6]
×
2360
    dimensions.gsub!(/[^amopqruz|]/, 'u')
×
2361
    channels = specific_007[7]
×
2362
    channels.gsub!(/[^kmnqsuz|]/, 'u')
×
2363
    fixed_field << mat_designation
×
2364
    fixed_field << ' '
×
2365
    fixed_field << color
×
2366
    fixed_field << format
×
2367
    fixed_field << sound_on_medium
×
2368
    fixed_field << sound_medium
×
2369
    fixed_field << dimensions
×
2370
    fixed_field << channels
×
2371
    fixed_field
×
2372
  end
2373

2374
  def fix_unspec_007(specific_007)
1✔
2375
    mat_designation = specific_007[0]
×
2376
    mat_designation.gsub(/[^muz|]/, 'u')
×
2377
  end
2378

2379
  def contents_chars
1✔
2380
    %w[a b c d e f g h i k l m n o p q r s t u v w y z 5 6]
4✔
2381
  end
2382

2383
  def fix_contents_chars(contents)
1✔
2384
    return contents if contents =~ /\|+$/
1✔
2385

2386
    contents.chars.each_with_index do |char, index|
1✔
2387
      case char
4✔
2388
      when 'h'
2389
        contents[index] = 'f'
×
2390
      when '3'
2391
        contents[index] = 'k'
×
2392
      when 'x'
2393
        contents[index] = 't'
×
2394
      when '4'
2395
        contents[index] = 'q'
×
2396
      end
2397
    end
2398
    contents_values = contents.chars.select { |c| contents_chars.include? c }.sort.join('')
5✔
2399
    contents_values.ljust(contents.size)
1✔
2400
  end
2401

2402
  ### Replace obsolete values with current values when possible
2403
  def fix_006(record)
1✔
2404
    target_fields = record.fields('006')
×
2405
    return record if target_fields.empty?
×
2406

2407
    target_fields.each do |field|
×
2408
      next if field.value.size != 18
×
2409

2410
      rec_type = field.value[0]
×
2411
      next unless rec_type =~ /[ac-gijkmoprst]/
×
2412

2413
      specific_006 = field.value[1..-1]
×
2414
      field.value[1..-1] = case rec_type
×
2415
                           when 'a', 't'
2416
                             fix_book_008(specific_006)
×
2417
                           when 'c', 'd', 'i', 'j'
2418
                             fix_music_008(specific_006)
×
2419
                           when 'e', 'f'
2420
                             fix_map_008(specific_006)
×
2421
                           when 'g', 'k', 'o', 'r'
2422
                             fix_visual_008(specific_006)
×
2423
                           when 'm'
2424
                             fix_comp_008(specific_006)
×
2425
                           when 'p'
2426
                             fix_mix_mat_008(specific_006)
×
2427
                           when 's'
2428
                             fix_continuing_resource_008(specific_006)
×
2429
                           end
2430
    end
2431
    record
×
2432
  end
2433

2434
  ### Replace obsolete values with current values when possible
2435
  def fix_008(record)
1✔
2436
    target_fields = record.fields('008')
1✔
2437
    return record if target_fields.size != 1
1✔
2438

2439
    rec_type = record.leader[6..7]
1✔
2440
    return record unless rec_type =~ /^[ac-gijkmoprt][abcdims]$/
1✔
2441

2442
    fixed_record = record
1✔
2443
    field = target_fields.first
1✔
2444
    return record if field.value.size != 40
1✔
2445

2446
    field_index = fixed_record.fields.index(field)
1✔
2447
    field_value = field.value
1✔
2448
    specific_008 = field_value[18..34]
1✔
2449
    modified = field_value[38]
1✔
2450
    cat_source = field_value[39]
1✔
2451
    fixed_008 = field_value
1✔
2452
    fixed_008[38] = '|' if modified == 'u'
1✔
2453
    if cat_source =~ /[abl]/
1✔
2454
      fixed_008[39] = ' '
×
2455
    elsif [' ', 'c', 'd', 'u', '|'].include? cat_source
1✔
2456
      fixed_008[39] = cat_source
1✔
2457
    elsif cat_source == 'o'
×
2458
      fixed_008[39] = 'd'
×
2459
    end
2460
    fixed_008[18..34] =
1✔
2461
      if book.include? rec_type
1✔
2462
        fix_book_008(specific_008)
1✔
2463
      elsif comp_file.include? rec_type
×
2464
        fix_comp_008(specific_008)
×
2465
      elsif map.include? rec_type
×
2466
        fix_map_008(specific_008)
×
2467
      elsif music.include? rec_type
×
2468
        fix_music_008(specific_008)
×
2469
      elsif continuing_resource.include? rec_type
×
2470
        fix_continuing_resource_008(specific_008)
×
2471
      elsif visual.include? rec_type
×
2472
        fix_visual_008(specific_008)
×
2473
      elsif mixed.include? rec_type
×
2474
        fix_mix_mat_008(specific_008)
×
2475
      else
2476
        specific_008
×
2477
      end
2478
    fixed_record.fields[field_index].value = fixed_008
1✔
2479
    fixed_record
1✔
2480
  end
2481

2482
  def fix_book_008(field)
1✔
2483
    fixed_field = ''
1✔
2484
    illus = field[0..3]
1✔
2485
    audience = field[4]
1✔
2486
    item_form = field[5]
1✔
2487
    contents = field[6..9]
1✔
2488
    gov_pub = field[10]
1✔
2489
    conf_pub = field[11]
1✔
2490
    festschrift = field[12]
1✔
2491
    index_code = field[13]
1✔
2492
    lit_form = field[15]
1✔
2493
    biog = field[16]
1✔
2494
    unless illus == '||||'
1✔
2495
      illus_chars = illus.chars.select { |c| %w[a b c d e f g h i j k l m o p].include? c }.sort.join('')
5✔
2496
      illus = illus_chars.ljust(4)
1✔
2497
    end
2498
    fixed_field << illus
1✔
2499
    audience.gsub!(/[uv]/, 'j')
1✔
2500
    fixed_field << audience
1✔
2501
    fixed_field << item_form
1✔
2502
    contents = fix_contents_chars(contents)
1✔
2503
    fixed_field << contents
1✔
2504
    gov_pub.gsub!('n', 'o')
1✔
2505
    fixed_field << gov_pub
1✔
2506
    fixed_field << conf_pub
1✔
2507
    fixed_field << festschrift
1✔
2508
    fixed_field << index_code
1✔
2509
    fixed_field << ' '
1✔
2510
    lit_form.gsub!(' ', '0')
1✔
2511
    fixed_field << lit_form
1✔
2512
    fixed_field << biog
1✔
2513
    fixed_field.gsub('-', '|')
1✔
2514
  end
2515

2516
  def fix_comp_008(field)
1✔
2517
    fixed_field = ''
×
2518
    audience = field[4]
×
2519
    item_form = field[5]
×
2520
    type = field[8]
×
2521
    gov_pub = field[10]
×
2522
    fixed_field << '    '
×
2523
    audience.gsub!(/[uv]/, 'j')
×
2524
    fixed_field << audience
×
2525
    fixed_field << item_form
×
2526
    fixed_field << '  '
×
2527
    fixed_field << type
×
2528
    fixed_field << ' '
×
2529
    gov_pub.gsub!('n', 'o')
×
2530
    fixed_field << gov_pub
×
2531
    fixed_field << '      '
×
2532
    fixed_field.gsub('-', '|')
×
2533
  end
2534

2535
  def fix_map_008(field)
1✔
2536
    fixed_field = ''
×
2537
    relief = field[0..3]
×
2538
    proj = field[4..5]
×
2539
    type = field[7]
×
2540
    gov_pub = field[10]
×
2541
    item_form = field[11]
×
2542
    index_code = field[13]
×
2543
    format = field[15..16]
×
2544
    unless relief == '||||'
×
2545
      relief.gsub!('h', 'c')
×
2546
      relief_chars = relief.chars.select { |c| %w[a b c d e f g i j k m z].include? c }.sort.join('')
×
2547
      relief = relief_chars.ljust(4)
×
2548
    end
2549
    fixed_field << relief
×
2550
    fixed_field << proj
×
2551
    fixed_field << ' '
×
2552
    fixed_field << type
×
2553
    fixed_field << '  '
×
2554
    gov_pub.gsub!('n', 'o')
×
2555
    fixed_field << gov_pub
×
2556
    fixed_field << item_form
×
2557
    fixed_field << ' '
×
2558
    fixed_field << index_code
×
2559
    fixed_field << ' '
×
2560
    unless format == '||'
×
2561
      format_chars = format.chars.select { |c| %w[e j k l n o p r z].include? c }.sort.join('')
×
2562
      format = format_chars.ljust(2)
×
2563
    end
2564
    fixed_field << format
×
2565
    fixed_field.gsub('-', '|')
×
2566
  end
2567

2568
  def fix_music_008(field)
1✔
2569
    fixed_field = ''
×
2570
    comp_form = field[0..1]
×
2571
    music_format = field[2]
×
2572
    parts = field[3]
×
2573
    audience = field[4]
×
2574
    item_form = field[5]
×
2575
    accompanying = field[6..11]
×
2576
    lit_text = field[12..13]
×
2577
    transpose = field[15]
×
2578
    fixed_field << comp_form
×
2579
    fixed_field << music_format
×
2580
    fixed_field << parts
×
2581
    audience.gsub!(/[uv]/, 'j')
×
2582
    fixed_field << audience
×
2583
    fixed_field << item_form
×
2584
    unless accompanying == '||||||'
×
2585
      accompanying.gsub!('j', 'i')
×
2586
      accompanying_chars = accompanying.chars.select { |c| %w[a b c d e f g h i k r s z].include? c }.sort.join('')
×
2587
      accompanying = accompanying_chars.ljust(6)
×
2588
    end
2589
    fixed_field << accompanying
×
2590
    unless ['||', '  '].include? lit_text
×
2591
      lit_text_chars = lit_text.chars.select { |c| %w[a b c d e f g h i j k l m n o p r s t z].include? c }.sort.join('')
×
2592
      lit_text = lit_text_chars.ljust(2)
×
2593
    end
2594
    fixed_field << lit_text
×
2595
    fixed_field << ' '
×
2596
    fixed_field << transpose
×
2597
    fixed_field << ' '
×
2598
    fixed_field.gsub('-', '|')
×
2599
  end
2600

2601
  def fix_continuing_resource_008(field)
1✔
2602
    fixed_field = ''
×
2603
    freq = field[0]
×
2604
    reg = field[1]
×
2605
    cr_type = field[3]
×
2606
    item_orig_form = field[4]
×
2607
    item_form = field[5]
×
2608
    work_nature = field[6]
×
2609
    contents = field[7..9]
×
2610
    gov_pub = field[10]
×
2611
    conf_pub = field[11]
×
2612
    orig_script = field[15]
×
2613
    entry = field[16]
×
2614
    fixed_field << freq
×
2615
    fixed_field << reg
×
2616
    fixed_field << ' '
×
2617
    fixed_field << cr_type
×
2618
    fixed_field << item_orig_form
×
2619
    fixed_field << item_form
×
2620
    fixed_field << work_nature
×
2621
    contents = fix_contents_chars(contents)
×
2622
    fixed_field << contents
×
2623
    gov_pub.gsub!('n', 'o')
×
2624
    fixed_field << gov_pub
×
2625
    fixed_field << conf_pub
×
2626
    fixed_field << '   '
×
2627
    fixed_field << orig_script
×
2628
    fixed_field << entry
×
2629
    fixed_field.gsub('-', '|')
×
2630
  end
2631

2632
  def fix_visual_008(field)
1✔
2633
    fixed_field = ''
×
2634
    runtime = field[0..2]
×
2635
    audience = field[4]
×
2636
    gov_pub = field[10]
×
2637
    item_form = field[11]
×
2638
    visual_type = field[15]
×
2639
    technique = field[16]
×
2640
    fixed_field << runtime
×
2641
    fixed_field << ' '
×
2642
    audience.gsub!(/[uv]/, 'j')
×
2643
    fixed_field << audience
×
2644
    fixed_field << '     '
×
2645
    gov_pub.gsub!('n', 'o')
×
2646
    fixed_field << gov_pub
×
2647
    fixed_field << item_form
×
2648
    fixed_field << '   '
×
2649
    visual_type.gsub!('e', 'v')
×
2650
    fixed_field << visual_type
×
2651
    technique.gsub!(' ', 'n')
×
2652
    fixed_field << technique
×
2653
    fixed_field
×
2654
  end
2655

2656
  def fix_mix_mat_008(field)
1✔
2657
    fixed_field = ''
×
2658
    item_form = field[5]
×
2659
    fixed_field << '     '
×
2660
    fixed_field << item_form
×
2661
    fixed_field << '           '
×
2662
    fixed_field.gsub('-', '|')
×
2663
  end
2664
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc