berkeley_library-tind 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +15 -3
  3. data/.gitignore +3 -0
  4. data/.idea/inspectionProfiles/Project_Default.xml +10 -0
  5. data/.idea/tind.iml +10 -9
  6. data/.rubocop.yml +1 -1
  7. data/CHANGES.md +15 -1
  8. data/README.md +165 -2
  9. data/berkeley_library-tind.gemspec +2 -2
  10. data/bin/alma-multiple-tind +50 -0
  11. data/bin/alma-single-tind +48 -0
  12. data/bin/save_tind_records +80 -0
  13. data/bin/tind-marc +73 -0
  14. data/lib/berkeley_library/tind/export/ods_exporter.rb +4 -6
  15. data/lib/berkeley_library/tind/mapping/additional_datafield_process.rb +128 -0
  16. data/lib/berkeley_library/tind/mapping/alma.rb +42 -0
  17. data/lib/berkeley_library/tind/mapping/alma_base.rb +108 -0
  18. data/lib/berkeley_library/tind/mapping/alma_multiple_tind.rb +31 -0
  19. data/lib/berkeley_library/tind/mapping/alma_single_tind.rb +28 -0
  20. data/lib/berkeley_library/tind/mapping/config.rb +44 -0
  21. data/lib/berkeley_library/tind/mapping/csv_mapper.rb +35 -0
  22. data/lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb +41 -0
  23. data/lib/berkeley_library/tind/mapping/data/one_to_multiple_mapping.csv +4 -0
  24. data/lib/berkeley_library/tind/mapping/data/one_to_one_mapping.csv +39 -0
  25. data/lib/berkeley_library/tind/mapping/external_tind_field.rb +103 -0
  26. data/lib/berkeley_library/tind/mapping/field_catalog.rb +137 -0
  27. data/lib/berkeley_library/tind/mapping/field_catalog_util.rb +105 -0
  28. data/lib/berkeley_library/tind/mapping/match_tind_field.rb +77 -0
  29. data/lib/berkeley_library/tind/mapping/misc.rb +69 -0
  30. data/lib/berkeley_library/tind/mapping/multiple_rule.rb +36 -0
  31. data/lib/berkeley_library/tind/mapping/single_rule.rb +149 -0
  32. data/lib/berkeley_library/tind/mapping/tind_control_subfield.rb +59 -0
  33. data/lib/berkeley_library/tind/mapping/tind_field.rb +49 -0
  34. data/lib/berkeley_library/tind/mapping/tind_field_from_leader.rb +27 -0
  35. data/lib/berkeley_library/tind/mapping/tind_field_from_multiple_map.rb +59 -0
  36. data/lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb +182 -0
  37. data/lib/berkeley_library/tind/mapping/tind_field_util.rb +112 -0
  38. data/lib/berkeley_library/tind/mapping/tind_marc.rb +134 -0
  39. data/lib/berkeley_library/tind/mapping/tind_record_util.rb +135 -0
  40. data/lib/berkeley_library/tind/mapping/tind_subfield_util.rb +154 -0
  41. data/lib/berkeley_library/tind/mapping/util.rb +136 -0
  42. data/lib/berkeley_library/tind/mapping.rb +1 -0
  43. data/lib/berkeley_library/tind/module_info.rb +1 -1
  44. data/spec/berkeley_library/tind/mapping/additional_datafield_process_spec.rb +35 -0
  45. data/spec/berkeley_library/tind/mapping/alma_base_spec.rb +115 -0
  46. data/spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb +20 -0
  47. data/spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb +87 -0
  48. data/spec/berkeley_library/tind/mapping/alma_spec.rb +28 -0
  49. data/spec/berkeley_library/tind/mapping/config_spec.rb +19 -0
  50. data/spec/berkeley_library/tind/mapping/csv_mapper_spec.rb +27 -0
  51. data/spec/berkeley_library/tind/mapping/csv_multiple_mapper_spec.rb +27 -0
  52. data/spec/berkeley_library/tind/mapping/external_tind_field_spec.rb +45 -0
  53. data/spec/berkeley_library/tind/mapping/field_catalog_spec.rb +78 -0
  54. data/spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb +105 -0
  55. data/spec/berkeley_library/tind/mapping/match_tind_field_spec.rb +24 -0
  56. data/spec/berkeley_library/tind/mapping/misc_spec.rb +51 -0
  57. data/spec/berkeley_library/tind/mapping/multiple_rule_spec.rb +44 -0
  58. data/spec/berkeley_library/tind/mapping/single_rule_spec.rb +52 -0
  59. data/spec/berkeley_library/tind/mapping/tind_control_subfield_spec.rb +96 -0
  60. data/spec/berkeley_library/tind/mapping/tind_field_from_leader_spec.rb +21 -0
  61. data/spec/berkeley_library/tind/mapping/tind_field_from_multiple_map_spec.rb +31 -0
  62. data/spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb +167 -0
  63. data/spec/berkeley_library/tind/mapping/tind_field_spec.rb +60 -0
  64. data/spec/berkeley_library/tind/mapping/tind_field_util_spec.rb +68 -0
  65. data/spec/berkeley_library/tind/mapping/tind_marc_spec.rb +88 -0
  66. data/spec/berkeley_library/tind/mapping/tind_record_util_spec.rb +30 -0
  67. data/spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb +48 -0
  68. data/spec/berkeley_library/tind/mapping/util_spec.rb +56 -0
  69. data/spec/berkeley_library/tind/marc/xml_writer_spec.rb +24 -0
  70. data/spec/data/api/pre_assigned_response.json +15 -0
  71. data/spec/data/api/result_file.csv +3 -0
  72. data/spec/data/api/upload_file.json +1 -0
  73. data/spec/data/api/upload_response.json +13 -0
  74. data/spec/data/mapping/991032333019706532-sru.xml +216 -0
  75. data/spec/data/mapping/one_to_multiple_mapping.csv +4 -0
  76. data/spec/data/mapping/one_to_one_mapping.csv +39 -0
  77. data/spec/data/mapping/record.xml +266 -0
  78. data/spec/data/mapping/record_not_qualified.xml +36 -0
  79. metadata +89 -54
  80. data/lib/berkeley_library/util/files.rb +0 -39
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe ExternalTindField do
8
+ describe '# tind_fields_from_collection_information' do
9
+ let(:good_hash) do
10
+ { '336' => ['Image'],
11
+ '852' => ['East Asian Library'],
12
+ '980' => ['pre_1912'],
13
+ '982' => ['Pre 1912 Chinese Materials', 'Pre 1912 Chinese Materials'],
14
+ '991' => [] }
15
+ end
16
+ let(:bad_hash) { {} }
17
+ let(:output_collection_tags) { %w[336 852 980 982] }
18
+
19
+ it 'get tind datafields derived from collection information' do
20
+ expect(ExternalTindField.tind_fields_from_collection_information(good_hash).map(&:tag)).to eq output_collection_tags
21
+ end
22
+
23
+ it 'get [] derived from empty collection information' do
24
+ expect { ExternalTindField.tind_fields_from_collection_information(bad_hash).map(&:tag) }.to raise_error(ArgumentError)
25
+ end
26
+ end
27
+
28
+ describe '# tind_fields_from_alma_id' do
29
+ let(:output_alma_tags) { %w[901 856] }
30
+
31
+ it 'get derived tind fields from alma id' do
32
+ alma_id = '991085821143406532'
33
+ expect(ExternalTindField.tind_mms_id_fields(alma_id).map(&:tag)).to eq output_alma_tags
34
+ end
35
+
36
+ it 'get empty tind fields from a nil alma id' do
37
+ alma_id = nil
38
+ expect { ExternalTindField.tind_mms_id_fields(alma_id).map(&:tag) }.to raise_error(ArgumentError)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ # 14 tags match origin tags defined in csv file
8
+ # ["245", "246", "260", "300", "300", "490", "630", "650", "650", "700", "710", '264', '264','507']
9
+ describe DataFieldsCatalog do
10
+
11
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
12
+ let(:qualified_alm_record) { qualified_alma_obj.record }
13
+ let(:datafields_catalog) { DataFieldsCatalog.new(qualified_alm_record) }
14
+ let(:mms_id) { '991046494559706532' }
15
+
16
+ let(:alma_tags) { %w[255 245 246 260 300 300 490 630 650 700 710] }
17
+ let(:alma_tags_with_pre_existed_tag) { ['264'] }
18
+ let(:alma_tags_with_pre_existed_tag_subfield) { ['507'] }
19
+
20
+ let(:f880_subfield6) { %w[880-245-01 880-246-02 880-260-03 880-490-04 880-650-05 880-700-06 880-710-07] }
21
+ let(:f880_subfield6_with_pre_existed_tag) { [] }
22
+ let(:f880_subfield6_with_pre_existed_tag_subfield) { ['880-507-09'] }
23
+
24
+ # 880 datafield with "880-510-00" should not be includede
25
+ let(:f880_sbufield6_with_00) { %w[880-500-00 880-500-00 880-500-00 880-500-00] }
26
+ let(:not_f880_sbufield6_with_00) { '880-510-00' }
27
+
28
+ it 'get control_fields' do
29
+ expect(datafields_catalog.control_fields.count).to eq 3
30
+ end
31
+
32
+ it 'get mms_id' do
33
+ expect(datafields_catalog.mms_id).to eq mms_id
34
+ end
35
+
36
+ context '# From regular fields' do
37
+
38
+ # One-occurence mapping: there are two 264 datafields in record, only the first one is added
39
+ it 'get regular datafield tags' do
40
+ expect(datafields_catalog.data_fields_group[:normal].map(&:tag)).to eq alma_tags
41
+ end
42
+
43
+ it 'get datafield tags with pre_existed datafield defined in csv' do
44
+ expect(datafields_catalog.data_fields_group[:pre_tag].map(&:tag)).to eq alma_tags_with_pre_existed_tag
45
+ end
46
+
47
+ it 'get datafield tags with pre_existed datafield and subfield defined in csv' do
48
+ expect(datafields_catalog.data_fields_group[:pre_tag_subfield].map(&:tag)).to eq alma_tags_with_pre_existed_tag_subfield
49
+ end
50
+
51
+ end
52
+
53
+ context '# From 880 fields' do
54
+ it 'get 880 datafields - subfield 6 number is 00 ' do
55
+ expect(datafields_catalog.fields_880_subfield6(datafields_catalog.data_fields_880_00)).to eq f880_sbufield6_with_00
56
+ end
57
+
58
+ it 'get 880 datafields - subfield 6 number is not 00 ' do
59
+ expect(datafields_catalog.fields_880_subfield6(datafields_catalog.data_fields_880_00)).not_to include not_f880_sbufield6_with_00
60
+ end
61
+
62
+ it 'get regular subfield 6' do
63
+ expect(datafields_catalog.fields_880_subfield6(datafields_catalog.data_fields_880_group[:normal])).to eq f880_subfield6
64
+ end
65
+
66
+ it 'get regular subfield 6: pre_exsisted datafield' do
67
+ expect(datafields_catalog.data_fields_880_group[:pre_tag]).to eq f880_subfield6_with_pre_existed_tag
68
+ end
69
+
70
+ it 'get regular subfield 6: pre_exsisted datafield and subfield from' do
71
+ expect(datafields_catalog.fields_880_subfield6(datafields_catalog.data_fields_880_group[:pre_tag_subfield])).to eq f880_subfield6_with_pre_existed_tag_subfield
72
+ end
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ module BerkeleyLibrary
4
+ module TIND
5
+ module Mapping
6
+ describe FieldCatalogUtil do
7
+ include Util
8
+ include Misc
9
+ include FieldCatalogUtil
10
+ include TindSubfieldUtil
11
+ include CsvMapper
12
+
13
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
14
+ let(:qualified_alm_record) { qualified_alma_obj.record }
15
+ let(:regular_field_tags) do
16
+ %w[255
17
+ 507
18
+ 245
19
+ 246
20
+ 260
21
+ 300
22
+ 490
23
+ 630
24
+ 650
25
+ 700
26
+ 710
27
+ 264]
28
+ end
29
+
30
+ let(:normal) { %w[255 245 246 260 300 300 490 630 650 650 700 710] }
31
+ let(:pre_tag) { ['264', '264'] }
32
+ let(:pre_tag_subfield) { ['507'] }
33
+
34
+ after do
35
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = []
36
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = []
37
+ end
38
+
39
+ it 'excluding fast subject field' do
40
+ fields = qualified_alm_record.fields.select { |f| ['650', '245'].include? f.tag }
41
+ expect(fields.length).to eq 3
42
+
43
+ final_fields = exluding_fields_with_fast_subject(fields)
44
+ expect(final_fields.length).to eq 2
45
+ expect(final_fields[0].tag).to eq '245'
46
+
47
+ end
48
+
49
+ it 'preparing field group' do
50
+ fields = qualified_alm_record.fields.select { |f| regular_field_tags.include? f.tag }
51
+ expect(fields.length).to eq 15
52
+
53
+ group = prepare_group(fields)
54
+ expect(group[:normal].map(&:tag)).to eq normal
55
+ expect(group[:pre_tag].map(&:tag)).to eq pre_tag
56
+ expect(group[:pre_tag_subfield].map(&:tag)).to eq pre_tag_subfield
57
+ end
58
+
59
+ context 'Defining list of fields mapping from Alma to TIND' do
60
+ it 'no including, excluding defined from config, return all Alma fields for mapping' do
61
+ selected_field_tags = %w[255 507 245 246 260 300]
62
+ fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
63
+ expect(fields_to_map(fields).map(&:tag)).to eq %w[255 507 245 246 260 300 300]
64
+ end
65
+
66
+ it 'both including and excluding have tags, return empty: not allow to define both including and excluding at the same time' do
67
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[254 650]
68
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650 880]
69
+
70
+ selected_field_tags = %w[255 507 245 246 260 300]
71
+ fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
72
+ expect(fields_to_map(fields).map(&:tag)).to eq []
73
+ end
74
+
75
+ it 'only including is defined: keeping fields defined in BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags' do
76
+ selected_field_tags = regular_field_tags
77
+ selected_field_tags << '880'
78
+ selected_field_tags << '001'
79
+ fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
80
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[255 650]
81
+ expect(fields_to_map(fields).map(&:tag)).to eq %w[001 255 650 650 880] # return: Two 650 fields, one 880 field with subfield6 = '650'
82
+ end
83
+
84
+ context 'only excluding origin tags are defined ' do
85
+ it 'excluding has 880, all 880 fields will be excluded.' do
86
+ selected_field_tags = %w[001 880 245 507 255 650 630 700 264]
87
+ fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
88
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650 880]
89
+ final_field_tags = %w[001 245 630 700 264 264] # no 880 fields kept
90
+ expect(fields_to_map(fields).map(&:tag)).to eq final_field_tags
91
+ end
92
+
93
+ it 'excluding has no 880, only 880 whose refered tag located in excluding list will be skipped ' do
94
+ selected_field_tags = %w[001 880 245 507 255 650 630 700 264]
95
+ fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
96
+ BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650]
97
+ final_field_tags = %w[001 245 880 880 880 880 630 880 700 880 880 880 880 880 880 880 264 264]
98
+ expect(fields_to_map(fields).map(&:tag)).to eq final_field_tags
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe MatchTindField do
8
+
9
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
10
+ let(:qualified_alm_record) { qualified_alma_obj.record }
11
+
12
+ let(:tind_marc) { TindMarc.new(qualified_alm_record) }
13
+
14
+ let(:data_fields) { tind_marc.field_catalog.data_fields_880_group[:normal].concat tind_marc.field_catalog.data_fields_group[:normal] }
15
+ let(:no_880_matching_count) { 5 }
16
+
17
+ it 'get 880 un-matched fields' do
18
+ expect(tind_marc.send(:un_matched_fields_880, data_fields, '991032577079706532').length).to eq no_880_matching_count
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe Misc do
8
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
9
+ let(:qualified_alm_record) { qualified_alma_obj.record }
10
+
11
+ let(:tind_marc) { TindMarc.new(qualified_alm_record) }
12
+ let(:regular_field_with_subfield6) { qualified_alma_obj.field('246') }
13
+ let(:field_880_with_subfield6) { qualified_alma_obj.field_880('490-04/$1') }
14
+ let(:field_880_without_subfield6) { qualified_alma_obj.field_880(nil) }
15
+
16
+ it 'get field tag' do
17
+ expect(tind_marc.origin_mapping_tag(regular_field_with_subfield6)).to eq '246'
18
+ end
19
+
20
+ it 'get tag from subfield 6' do
21
+ expect(tind_marc.origin_mapping_tag(field_880_with_subfield6)).to eq '490'
22
+ end
23
+
24
+ it 'get nil when no fubfiel6' do
25
+ expect(tind_marc.referred_tag(field_880_without_subfield6)).to eq nil
26
+ end
27
+
28
+ it '880 field has a refered tag' do
29
+ expect(tind_marc.field_880_has_referred_tag?('490', field_880_with_subfield6)).to eq true
30
+ end
31
+
32
+ it '880 field has no refered tag' do
33
+ expect(tind_marc.field_880_has_referred_tag?('490', field_880_without_subfield6)).to eq false
34
+ end
35
+
36
+ it 'remove defined punctuations' do
37
+ expect(tind_marc.send(:clr_value, ' [1785] Qing Qianlong 50 nian :,')).to eq '1785 Qing Qianlong 50 nian'
38
+ end
39
+
40
+ it 'get seq number' do
41
+ expect(tind_marc.send(:seq_no, '245-01/$1')).to eq 1
42
+ end
43
+
44
+ it 'get seq number - 0' do
45
+ expect(tind_marc.send(:seq_no, '550')).to eq 0
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'csv'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+
8
+ describe MultipleRule do
9
+
10
+ attr_reader :multiple_rule
11
+
12
+ before(:each) do
13
+ rows = Util.csv_rows('spec/data/mapping/one_to_multiple_mapping.csv')
14
+ @multiple_rule = MultipleRule.new(rows[0])
15
+ end
16
+
17
+ it 'get origin tag' do
18
+ expect(multiple_rule.tag_origin).to eq '008'
19
+ end
20
+
21
+ it 'get destination tag' do
22
+ expect(multiple_rule.tag_destination).to eq '041'
23
+ end
24
+
25
+ it 'get indicator' do
26
+ expect(multiple_rule.indicator).to eq [' ', ' ']
27
+ end
28
+
29
+ it 'get pre_existed tag' do
30
+ expect(multiple_rule.pre_existed_tag).to eq '041'
31
+ end
32
+
33
+ it 'get subfield key' do
34
+ expect(multiple_rule.subfield_key).to eq 'a'
35
+ end
36
+
37
+ it 'get position from and to' do
38
+ expect(multiple_rule.position_from_to).to eq [35, 37]
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'csv'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+
8
+ describe SingleRule do
9
+
10
+ attr_reader :single_rule
11
+
12
+ before(:each) do
13
+ rows = Util.csv_rows('spec/data/mapping/one_to_one_mapping.csv')
14
+ @single_rule = SingleRule.new(rows[4])
15
+ end
16
+
17
+ it 'get origin tag' do
18
+ expect(single_rule.tag_origin).to eq '245'
19
+ end
20
+
21
+ it 'get destination tag' do
22
+ expect(single_rule.tag_destination).to eq '245'
23
+ end
24
+
25
+ it 'get indicator' do
26
+ expect(single_rule.indicator).to eq [' ', ' ']
27
+ end
28
+
29
+ it 'get combined rules' do
30
+ expect(single_rule.combined_rules).to eq [[['n,p', 'p', nil]], [['b,f,k', 'b', nil]]] # combination rules mapped to p and b
31
+ end
32
+
33
+ it 'get pre_existed_tag' do
34
+ expect(single_rule.pre_existed_tag).to eq nil
35
+ end
36
+
37
+ it 'get pre_existed_tag_subfield ' do
38
+ expect(single_rule.pre_existed_tag_subfield).to eq nil
39
+ end
40
+
41
+ it 'get single rule exluding pre_existed_subfield hash' do
42
+ expect(single_rule.single_rule_subfield_excluded_hash).to eq({ '6' => '6', 'a' => 'a' })
43
+ end
44
+
45
+ it 'get single rule' do
46
+ expect(single_rule.single_rule_hash).to eq({ '6' => '6', 'a' => 'a' })
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ module BerkeleyLibrary
4
+ module TIND
5
+ module Mapping
6
+ describe TindControlSubfield do
7
+ let(:dummy_obj) { Class.new { extend TindControlSubfield } }
8
+ let(:dumy_obj_multiple_mapper) { Class.new { extend CsvMultipleMapper } }
9
+ let(:leader_rules) { dumy_obj_multiple_mapper.rules[:tag_008] }
10
+ let(:rule) { leader_rules[1] }
11
+ # When 001 value is copied from xml file, it missed 13 spaces, added manually
12
+ let(:leader_val_normal) { '970502i19101920vp nnn kneng d' }
13
+ let(:leader_val_uu) { '970423q19uu19uuxxunnn kneng d' }
14
+ let(:leader_val_u) { '970501q195u195ule nnn kneng d' }
15
+ let(:leader_val_not_good) { '970501i caunnn kneng d' }
16
+
17
+ context '#Normal year - 269 field' do
18
+ let(:sub_val) { dummy_obj.extract_value(rule, leader_val_normal) }
19
+
20
+ it '#extract_value year in dddd' do
21
+ expect(sub_val).to eq '1910'
22
+ end
23
+
24
+ it '#extracted_field - 269__$a: dddd' do
25
+ field = dummy_obj.extracted_field(rule, sub_val)
26
+ expect(field.tag).to eq '269'
27
+ expect(field['a']).to eq '1910'
28
+ end
29
+
30
+ it '#extracted_fields_from_leader: get two fields' do
31
+ fields = dummy_obj.extracted_fields_from_leader(leader_rules, leader_val_normal)
32
+ expect(fields.map(&:tag)).to eq ['041', '269']
33
+ end
34
+ end
35
+
36
+ context '#Year with "uu" - 269 field' do
37
+ let(:sub_val) { dummy_obj.extract_value(rule, leader_val_uu) }
38
+
39
+ it '#extract_value year in dduu' do
40
+ expect(sub_val).to eq '19uu'
41
+ end
42
+
43
+ it '#extracted_field - 269 = nil' do
44
+ field = dummy_obj.extracted_field(rule, sub_val)
45
+ expect(field).to eq nil
46
+ end
47
+
48
+ it '#extracted_fields_from_leader: get one field ' do
49
+ fields = dummy_obj.extracted_fields_from_leader(leader_rules, leader_val_uu)
50
+ expect(fields.map(&:tag)).to eq ['041']
51
+ end
52
+
53
+ end
54
+
55
+ context '#Year with "u" - 269 field' do
56
+ let(:sub_val) { dummy_obj.extract_value(rule, leader_val_u) }
57
+
58
+ it '#extract_value year in dddu' do
59
+ expect(sub_val).to eq '195u'
60
+ end
61
+
62
+ it '#extracted_field - 269__$a: ddd0' do
63
+ field = dummy_obj.extracted_field(rule, sub_val)
64
+ expect(field.tag).to eq '269'
65
+ expect(field['a']).to eq '1950'
66
+ end
67
+
68
+ it '#extracted_fields_from_leader: get two fields ' do
69
+ fields = dummy_obj.extracted_fields_from_leader(leader_rules, leader_val_u)
70
+ expect(fields.map(&:tag)).to eq ['041', '269']
71
+ end
72
+
73
+ end
74
+
75
+ context '#None year - 269 field' do
76
+ let(:sub_val) { dummy_obj.extract_value(rule, leader_val_not_good) }
77
+
78
+ it '#extract_value year - not integer string' do
79
+ expect(sub_val).to eq ' cau'
80
+ end
81
+
82
+ it '#extracted_field - 269 = nil' do
83
+ field = dummy_obj.extracted_field(rule, sub_val)
84
+ expect(field).to eq nil
85
+ end
86
+
87
+ it '#extracted_fields_from_leader: get one field ' do
88
+ fields = dummy_obj.extracted_fields_from_leader(leader_rules, leader_val_uu)
89
+ expect(fields.map(&:tag)).to eq ['041']
90
+ end
91
+
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindFieldFromLeader do
8
+
9
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
10
+ let(:qualified_alm_record) { qualified_alma_obj.record }
11
+ let(:datafields_catalog) { DataFieldsCatalog.new(qualified_alm_record) }
12
+ let(:tindfield_from_leader) { TindFieldFromLeader.new(qualified_alm_record) }
13
+
14
+ it 'get_tindfields' do
15
+ expect(tindfield_from_leader.to_datafields[0].tag).to eq '903'
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ # using 008 field: csv file, one_to_multiple csv file should have 008 field
8
+ # tag_origin tag_destination map_if_no_this_tag_existed subfield_key new_indecator value_from value_to
9
+ # 008 41 41 a _,_ 35 37
10
+ # 008 269 a _,_ 7 10
11
+
12
+ describe TindFieldFromMultipleMap do
13
+
14
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
15
+ let(:qualified_alm_record) { qualified_alma_obj.record }
16
+ let(:tindfield_from_multiple_map) { TindFieldFromMultipleMap.new(qualified_alma_obj.control_field, []) }
17
+
18
+ it 'get tindfields without pre_existing tindfields' do
19
+ expect(tindfield_from_multiple_map.to_datafields.count).to eq 2
20
+ end
21
+
22
+ it 'get tindfields with pre_existing tindfields' do
23
+ current_fields = [] << ::MARC::DataField.new('041', ' ', ' ', ::MARC::Subfield.new('a', 'chi'))
24
+ multiple_map = TindFieldFromMultipleMap.new(qualified_alma_obj.control_field, current_fields)
25
+ expect(multiple_map.to_datafields.count).to eq 1
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end