berkeley_library-tind 0.4.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +16 -4
- data/.gitignore +3 -0
- data/.idea/inspectionProfiles/Project_Default.xml +10 -0
- data/.idea/tind.iml +24 -22
- data/CHANGES.md +24 -0
- data/README.md +136 -3
- data/berkeley_library-tind.gemspec +2 -0
- data/bin/alma-multiple-tind +50 -0
- data/bin/alma-single-tind +48 -0
- data/bin/save_tind_records +80 -0
- data/bin/tind-marc +73 -0
- data/lib/berkeley_library/tind/mapping/additional_datafield_process.rb +128 -0
- data/lib/berkeley_library/tind/mapping/alma.rb +42 -0
- data/lib/berkeley_library/tind/mapping/alma_base.rb +101 -0
- data/lib/berkeley_library/tind/mapping/alma_multiple_tind.rb +31 -0
- data/lib/berkeley_library/tind/mapping/alma_single_tind.rb +28 -0
- data/lib/berkeley_library/tind/mapping/config.rb +44 -0
- data/lib/berkeley_library/tind/mapping/csv_mapper.rb +35 -0
- data/lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb +41 -0
- data/lib/berkeley_library/tind/mapping/data/one_to_multiple_mapping.csv +4 -0
- data/lib/berkeley_library/tind/mapping/data/one_to_one_mapping.csv +39 -0
- data/lib/berkeley_library/tind/mapping/external_tind_field.rb +103 -0
- data/lib/berkeley_library/tind/mapping/field_catalog.rb +146 -0
- data/lib/berkeley_library/tind/mapping/field_catalog_util.rb +59 -0
- data/lib/berkeley_library/tind/mapping/match_tind_field.rb +77 -0
- data/lib/berkeley_library/tind/mapping/misc.rb +69 -0
- data/lib/berkeley_library/tind/mapping/multiple_rule.rb +36 -0
- data/lib/berkeley_library/tind/mapping/single_rule.rb +143 -0
- data/lib/berkeley_library/tind/mapping/tind_control_subfield.rb +59 -0
- data/lib/berkeley_library/tind/mapping/tind_field.rb +49 -0
- data/lib/berkeley_library/tind/mapping/tind_field_from_leader.rb +27 -0
- data/lib/berkeley_library/tind/mapping/tind_field_from_multiple_map.rb +59 -0
- data/lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb +170 -0
- data/lib/berkeley_library/tind/mapping/tind_field_util.rb +112 -0
- data/lib/berkeley_library/tind/mapping/tind_marc.rb +134 -0
- data/lib/berkeley_library/tind/mapping/tind_subfield_util.rb +154 -0
- data/lib/berkeley_library/tind/mapping/util.rb +117 -0
- data/lib/berkeley_library/tind/mapping.rb +1 -0
- data/lib/berkeley_library/tind/marc/xml_builder.rb +70 -0
- data/lib/berkeley_library/tind/marc/xml_reader.rb +22 -16
- data/lib/berkeley_library/tind/marc/xml_writer.rb +152 -0
- data/lib/berkeley_library/tind/module_info.rb +1 -1
- data/lib/berkeley_library/util/files.rb +38 -0
- data/spec/berkeley_library/tind/mapping/additional_datafield_process_spec.rb +35 -0
- data/spec/berkeley_library/tind/mapping/alma_base_spec.rb +115 -0
- data/spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb +20 -0
- data/spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb +87 -0
- data/spec/berkeley_library/tind/mapping/alma_spec.rb +28 -0
- data/spec/berkeley_library/tind/mapping/config_spec.rb +19 -0
- data/spec/berkeley_library/tind/mapping/csv_mapper_spec.rb +27 -0
- data/spec/berkeley_library/tind/mapping/csv_multiple_mapper_spec.rb +27 -0
- data/spec/berkeley_library/tind/mapping/external_tind_field_spec.rb +45 -0
- data/spec/berkeley_library/tind/mapping/field_catalog_spec.rb +78 -0
- data/spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb +57 -0
- data/spec/berkeley_library/tind/mapping/match_tind_field_spec.rb +25 -0
- data/spec/berkeley_library/tind/mapping/misc_spec.rb +51 -0
- data/spec/berkeley_library/tind/mapping/multiple_rule_spec.rb +44 -0
- data/spec/berkeley_library/tind/mapping/single_rule_spec.rb +52 -0
- data/spec/berkeley_library/tind/mapping/tind_control_subfield_spec.rb +96 -0
- data/spec/berkeley_library/tind/mapping/tind_field_from_leader_spec.rb +21 -0
- data/spec/berkeley_library/tind/mapping/tind_field_from_multiple_map_spec.rb +31 -0
- data/spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb +150 -0
- data/spec/berkeley_library/tind/mapping/tind_field_spec.rb +60 -0
- data/spec/berkeley_library/tind/mapping/tind_field_util_spec.rb +68 -0
- data/spec/berkeley_library/tind/mapping/tind_marc_spec.rb +88 -0
- data/spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb +48 -0
- data/spec/berkeley_library/tind/mapping/util_spec.rb +56 -0
- data/spec/berkeley_library/tind/marc/xml_reader_spec.rb +22 -0
- data/spec/berkeley_library/tind/marc/xml_writer_spec.rb +218 -0
- data/spec/data/issue-4.xml +157 -0
- data/spec/data/mapping/991032333019706532-sru.xml +216 -0
- data/spec/data/mapping/one_to_multiple_mapping.csv +4 -0
- data/spec/data/mapping/one_to_one_mapping.csv +39 -0
- data/spec/data/mapping/record.xml +263 -0
- data/spec/data/mapping/record_not_qualified.xml +36 -0
- data/spec/data/new-records.xml +46 -0
- metadata +128 -2
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module TIND
|
5
|
+
module Mapping
|
6
|
+
describe AlmaSingleTIND do
|
7
|
+
let(:additona_245_field) { [Util.datafield('245', [' ', ' '], [Util.subfield('a', 'fake 245 a')])] }
|
8
|
+
let(:marc_obj) { (::MARC::Record.new).append(additona_245_field) }
|
9
|
+
|
10
|
+
before { BerkeleyLibrary::Alma::Config.default! }
|
11
|
+
after { BerkeleyLibrary::Alma::Config.send(:clear!) }
|
12
|
+
|
13
|
+
it ' get tind record' do
|
14
|
+
alma_single_tind = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
|
15
|
+
|
16
|
+
allow(alma_single_tind).to receive(:base_tind_record).with('991085821143406532', additona_245_field).and_return(marc_obj)
|
17
|
+
expect(alma_single_tind.record('991085821143406532', additona_245_field)).to be marc_obj
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'TIND record mapping' do
|
21
|
+
let(:coll_param_hash) do
|
22
|
+
{
|
23
|
+
'336' => ['Image'],
|
24
|
+
'852' => ['East Asian Library'],
|
25
|
+
'980' => ['pre_1912'],
|
26
|
+
'982' => ['Pre 1912 Chinese Materials - short name', 'Pre 1912 Chinese Materials - long name'],
|
27
|
+
'991' => []
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:id) { '991032333019706532' }
|
32
|
+
let(:marc_url) { BerkeleyLibrary::Alma::RecordId.parse(id).marc_uri.to_s }
|
33
|
+
let(:logger) { BerkeleyLibrary::Logging.logger }
|
34
|
+
|
35
|
+
before do
|
36
|
+
AlmaBase.collection_parameter_hash = coll_param_hash
|
37
|
+
AlmaBase.is_035_from_mms_id = true
|
38
|
+
end
|
39
|
+
|
40
|
+
after do
|
41
|
+
AlmaBase.collection_parameter_hash = nil
|
42
|
+
AlmaBase.is_035_from_mms_id = false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'transforms a record' do
|
46
|
+
marc_xml = File.read('spec/data/mapping/991032333019706532-sru.xml')
|
47
|
+
stub_request(:get, marc_url).to_return(body: marc_xml)
|
48
|
+
|
49
|
+
expect(logger).not_to receive(:warn)
|
50
|
+
|
51
|
+
mapper = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
|
52
|
+
url = "https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/#{id}/#{id}_v001_0064.jpg"
|
53
|
+
fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, 'v001_0064')
|
54
|
+
tind_record = mapper.record(id, [fft])
|
55
|
+
|
56
|
+
expect(tind_record).to be_a(::MARC::Record)
|
57
|
+
expect(tind_record['FFT']).to eq(fft)
|
58
|
+
|
59
|
+
expect(tind_record['901']['m']).to eq(id)
|
60
|
+
expect(tind_record['035']['a']).to eq("(pre_1912)#{id}")
|
61
|
+
|
62
|
+
alma_record = ::MARC::XMLReader.read(StringIO.new(marc_xml)).first
|
63
|
+
sf_245a_expected = alma_record.spec('245$a{$6=\880-02}').first
|
64
|
+
sf_245_value_expected = sf_245a_expected.value.sub(/[^[:alnum:]]+$/, '')
|
65
|
+
|
66
|
+
sf_245a_actual = tind_record.spec('245$a{$6=\880-02}').first
|
67
|
+
sf_245a_value_actual = sf_245a_actual.value
|
68
|
+
expect(sf_245a_value_actual).to eq(sf_245_value_expected)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'handles pathological records without an 001 control field' do
|
72
|
+
marc_xml = File.read('spec/data/mapping/991032333019706532-sru.xml')
|
73
|
+
.sub('<controlfield tag="001">991032333019706532</controlfield>', '')
|
74
|
+
stub_request(:get, marc_url).to_return(body: marc_xml)
|
75
|
+
|
76
|
+
expect(logger).to receive(:warn).with("#{id} has no Control Field 001")
|
77
|
+
|
78
|
+
mapper = BerkeleyLibrary::TIND::Mapping::AlmaSingleTIND.new
|
79
|
+
url = "https://digitalassets.lib.berkeley.edu/pre1912ChineseMaterials/ucb/ready/#{id}/#{id}_v001_0064.jpg"
|
80
|
+
fft = BerkeleyLibrary::TIND::Mapping::TindField.f_fft(url, 'v001_0064')
|
81
|
+
expect { mapper.record(id, [fft]) }.to raise_error(ArgumentError)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module TIND
|
5
|
+
module Mapping
|
6
|
+
describe Alma do
|
7
|
+
let(:alma_obj) { Alma.new('spec/data/mapping/record.xml') }
|
8
|
+
|
9
|
+
it 'control field value' do
|
10
|
+
expect(alma_obj.control_field.tag).to eq '008'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'control field value' do
|
14
|
+
expect(alma_obj.control_field.tag).to eq '008'
|
15
|
+
end
|
16
|
+
|
17
|
+
it '880 field' do
|
18
|
+
expect(alma_obj.field_880('245-01/$1')['6']).to eq '245-01/$1'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'regular field' do
|
22
|
+
expect(alma_obj.field('245').tag).to eq '245'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module TIND
|
5
|
+
module Mapping
|
6
|
+
describe Config do
|
7
|
+
|
8
|
+
it 'get the one to one mapping file' do
|
9
|
+
expect(Config.one_to_one_map_file).to end_with('one_to_one_mapping.csv')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'get the one to multiple mapping file' do
|
13
|
+
expect(Config.one_to_multiple_map_file).to end_with('one_to_multiple_mapping.csv')
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe CsvMapper do
|
8
|
+
let(:dummy_class) { Class.new { extend CsvMapper } }
|
9
|
+
let(:from_tag) { %w[100 110 111 242 245 246 250 255 260 264 300 351 490 500 502 505 507 520 522 524 536 541 545 546 600 610 611 630 650 651 655 700 710 711 720 752 773 907] }
|
10
|
+
let(:rules_keys) { %i[tag_100 tag_110 tag_111 tag_242 tag_245 tag_246 tag_250 tag_255 tag_260 tag_264 tag_300 tag_351 tag_490 tag_500 tag_502 tag_505 tag_507 tag_520 tag_522 tag_524 tag_536 tag_541 tag_545 tag_546 tag_600 tag_610 tag_611 tag_630 tag_650 tag_651 tag_655 tag_700 tag_710 tag_711 tag_720 tag_752 tag_773 tag_907] }
|
11
|
+
|
12
|
+
it 'get origin tags' do
|
13
|
+
expect(dummy_class.from_tags).to eq from_tag
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'get keys of rules' do
|
17
|
+
expect(dummy_class.rules.keys).to eq rules_keys
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'get tag required one occurrence in csv ' do
|
21
|
+
expect(dummy_class.one_occurrence_tags).to eq ['264']
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe CsvMultipleMapper do
|
8
|
+
let(:dummy_class) { Class.new { extend CsvMultipleMapper } }
|
9
|
+
let(:from_tag) { ['008', 'LDR'] }
|
10
|
+
let(:rules_keys) { %i[tag_008 tag_LDR] }
|
11
|
+
|
12
|
+
it 'get origin tags' do
|
13
|
+
expect(dummy_class.from_tags).to eq from_tag
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'get keys of rules' do
|
17
|
+
expect(dummy_class.rules.keys).to eq rules_keys
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'get 2 rules on tag "008" ' do
|
21
|
+
expect(dummy_class.send(:rules_on_tag, '008').count).to eq 2
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -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,57 @@
|
|
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
|
+
it 'excluding fast subject field' do
|
35
|
+
fields = qualified_alm_record.fields.select { |f| ['650', '245'].include? f.tag }
|
36
|
+
expect(fields.length).to eq 3
|
37
|
+
|
38
|
+
final_fields = exluding_fields_with_fast_subject(fields)
|
39
|
+
expect(final_fields.length).to eq 2
|
40
|
+
expect(final_fields[0].tag).to eq '245'
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'preparing field group' do
|
45
|
+
fields = qualified_alm_record.fields.select { |f| regular_field_tags.include? f.tag }
|
46
|
+
expect(fields.length).to eq 15
|
47
|
+
|
48
|
+
group = prepare_group(fields)
|
49
|
+
expect(group[:normal].map(&:tag)).to eq normal
|
50
|
+
expect(group[:pre_tag].map(&:tag)).to eq pre_tag
|
51
|
+
expect(group[:pre_tag_subfield].map(&:tag)).to eq pre_tag_subfield
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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) { 4 }
|
16
|
+
|
17
|
+
it 'get 880 un-matched fields' do
|
18
|
+
# puts tind_marc.send(:un_matched_fields_880, data_fields, '991032577079706532').inspect
|
19
|
+
expect(tind_marc.send(:un_matched_fields_880, data_fields, '991032577079706532').length).to eq no_880_matching_count
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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
|