berkeley_library-tind 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +15 -3
- data/.gitignore +3 -0
- data/.idea/inspectionProfiles/Project_Default.xml +10 -0
- data/.idea/tind.iml +4 -3
- data/CHANGES.md +6 -0
- data/README.md +121 -2
- data/berkeley_library-tind.gemspec +1 -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/module_info.rb +1 -1
- data/lib/berkeley_library/util/files.rb +1 -2
- 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_writer_spec.rb +24 -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
- metadata +105 -2
@@ -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
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindFieldFromSingleMap do
|
8
|
+
let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
|
9
|
+
let(:qualified_alm_record) { qualified_alma_obj.record }
|
10
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('245'), false) }
|
11
|
+
|
12
|
+
# 1. Subfield one to one mapping
|
13
|
+
# 2. Subfield not listed in csv file is not mapped
|
14
|
+
describe '1. subfield one to one mapping' do
|
15
|
+
it 'get tindfield tag: 245 => 245 ' do
|
16
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '245'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'get 245$a' do
|
20
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq 'Cang jie pian :'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'get 245$b' do
|
24
|
+
expect(tindfield_from_single_map.to_datafield['b']).to eq '[san juan] /'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'get 245$6' do
|
28
|
+
expect(tindfield_from_single_map.to_datafield['6']).to eq '880-99'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'shoud not get 245$c' do
|
32
|
+
expect(tindfield_from_single_map.to_datafield['c']).to eq nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
describe '2. mapping indicators' do
|
36
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('710'), false) }
|
37
|
+
|
38
|
+
it 'get indicator1' do
|
39
|
+
expect(tindfield_from_single_map.to_datafield.indicator1).to eq '2'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'get indicator2' do
|
43
|
+
expect(tindfield_from_single_map.to_datafield.indicator2).to eq ' '
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# 264 datafield mapping defined in csv has only one mapping occurrence
|
49
|
+
# To test only the first occurrence is mapped
|
50
|
+
describe '3. multiple origin 264 fields => only mapping the first occurrence' do
|
51
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('264'), false) }
|
52
|
+
|
53
|
+
it 'get tindfield tag: 264 => 260' do
|
54
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '260'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'get the first 264$a' do
|
58
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq '264 fake a 1'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'get the first 264$b' do
|
62
|
+
expect(tindfield_from_single_map.to_datafield['b']).to eq '264 fake b 1'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'get the first 264$c' do
|
66
|
+
expect(tindfield_from_single_map.to_datafield['c']).to eq '264 fake c 1'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 1. 507 datafield has pre-existed subfield a defined in csv file
|
71
|
+
# 2. To test excluding subfield a mapping from 507
|
72
|
+
# 3. TindFieldFromSingleMap.new(): input excluding_subfield = true
|
73
|
+
describe '4. pre_existed subfield = true' do
|
74
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('507'), true) }
|
75
|
+
|
76
|
+
it 'get tindfield tag: 507 => 255 ' do
|
77
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '255'
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'pre_existed 507$a is not mapped' do
|
81
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# To test rule: subfield value combined without concatenation symbol defined in csv
|
86
|
+
describe '5. subfields are combined' do
|
87
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('246'), false) }
|
88
|
+
|
89
|
+
it 'get tindfield tag: 246 => 246' do
|
90
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '246'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'get combined subfield a, b, p, n' do
|
94
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq 'Sun shi Cang jie pian ^^ b fake ^^ p fake ^^ n fake'
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
# To test multiple rules mapped to the same tinddatafield
|
100
|
+
describe '6. subfields are combined with multiple rules' do
|
101
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('630'), false) }
|
102
|
+
let(:combined_value) { 'fake a * fake b * fake c * fake d * fake f * fake j * fake k * fake l * fake m * fake n * fake o * fake p * fake q * fake r * fake s * fake t * fake x1 -- fake x2 ' }
|
103
|
+
|
104
|
+
it 'get tindfield tag: 630 => 630' do
|
105
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '630'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'get combined subfield a, b, p, n' do
|
109
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq combined_value
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
# 1. To test 880 datafield
|
115
|
+
# 2. 880 tag reversed
|
116
|
+
# 3. subfields z,y, z combined with concatenation symbol defined in csv file
|
117
|
+
describe '7. 880 datafield mapping' do
|
118
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field_880('650-05/$1'), false) }
|
119
|
+
|
120
|
+
it 'get tindfield tag: 880 => 880' do
|
121
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '880'
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'get 880$a: subfield a x,y,z combined to subfield a with symbol " -- " ' do
|
125
|
+
expect(tindfield_from_single_map.to_datafield['a']).to eq '經部 小學類 -- 字書. '
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
# 1. To test 880 datafield
|
131
|
+
# 2. Tag in 880 subfield 6 is mapped based on a regular datafield mapping rule
|
132
|
+
# 3. 880 datafield with 507 tag in subfield 6
|
133
|
+
# mapped from 507-09/$1 to 255-09/$1
|
134
|
+
describe '8. 880 subfield 6 value mapped to new destination tag' do
|
135
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field_880('507-09/$1'), false) }
|
136
|
+
|
137
|
+
it 'get tindfield tag: 880 => 880' do
|
138
|
+
expect(tindfield_from_single_map.to_datafield.tag).to eq '880'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'get subfield 6: "507-09/$1" => "255-09/$1" ' do
|
142
|
+
expect(tindfield_from_single_map.to_datafield['6']).to eq '255-09/$1'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindField do
|
8
|
+
it 'Field 035' do
|
9
|
+
f = TindField.f_035('Alibaba123')
|
10
|
+
expect(f.tag).to eq '035'
|
11
|
+
expect(f['a']).to eq 'Alibaba123'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'Field 035 derived from mms_id' do
|
15
|
+
f = TindField.f_035_from_alma_id('991085821143406532', 'cu_news')
|
16
|
+
expect(f.tag).to eq '035'
|
17
|
+
expect(f['a']).to eq '(cu_news)991085821143406532'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'Field 245$p' do
|
21
|
+
f = TindField.f_245_p('fake_title_version')
|
22
|
+
expect(f.tag).to eq '245'
|
23
|
+
expect(f['p']).to eq 'fake_title_version'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'Field FFT' do
|
27
|
+
f = TindField.f_fft('http://host/image.tif', 'news')
|
28
|
+
expect(f.tag).to eq 'FFT'
|
29
|
+
expect(f['a']).to eq 'http://host/image.tif'
|
30
|
+
expect(f['d']).to eq 'news'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'Field 902$d' do
|
34
|
+
f = TindField.f_902_d
|
35
|
+
puts f['d']
|
36
|
+
expect(f.tag).to eq '902'
|
37
|
+
expect(f['d']).to match(/^\d{4}-\d{2}-\d{2}$/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'Field 902$n' do
|
41
|
+
f = TindField.f_902_n('YZ')
|
42
|
+
expect(f.tag).to eq '902'
|
43
|
+
expect(f['n']).to eq 'YZ'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'Field 982$p' do
|
47
|
+
f = TindField.f_982_p('project name')
|
48
|
+
expect(f.tag).to eq '982'
|
49
|
+
expect(f['p']).to eq 'project name'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'Marc field' do
|
53
|
+
f = TindField.f('998', 'g', 'file name')
|
54
|
+
expect(f.tag).to eq '998'
|
55
|
+
expect(f['g']).to eq 'file name'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindFieldUtil 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
|
+
|
13
|
+
let(:normal_fields_group) { tind_marc.field_catalog.data_fields_group[:normal] }
|
14
|
+
let(:field_normal) { qualified_alma_obj.field('245') }
|
15
|
+
let(:field_pre_existed_field) { qualified_alma_obj.field('264') } # 264 has pre_existed field defined in csv file
|
16
|
+
let(:field_pre_existed_field_and_subfield) { qualified_alma_obj.field('507') } # 507 has pre_existed_field_subfield defined in csv file
|
17
|
+
let(:fields_880_group) { tind_marc.field_catalog.data_fields_880_group[:normal] }
|
18
|
+
let(:field_880_245) { qualified_alma_obj.field_880('245-01/$1') }
|
19
|
+
|
20
|
+
it 'get a rule on datafield' do
|
21
|
+
expect(tind_marc.rule(field_normal)).to be_an_instance_of BerkeleyLibrary::TIND::Mapping::SingleRule
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'tindfield found existing list of tindfields' do
|
25
|
+
expect(tind_marc.tindfield_existed?(field_pre_existed_field, normal_fields_group)).to eq true
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'tindfield not found existing list of tindfields' do
|
29
|
+
expect(tind_marc.tindfield_existed?(field_normal, normal_fields_group)).to eq false
|
30
|
+
end
|
31
|
+
|
32
|
+
# fake 255$a existing in the record.xml
|
33
|
+
it 'tindfield subfield found in existing list of tindfields' do
|
34
|
+
expect(tind_marc.tindfield_subfield_existed?(field_pre_existed_field_and_subfield, normal_fields_group)).to eq true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'tindfield subfield not found existing list of tindfields' do
|
38
|
+
expect(tind_marc.tindfield_subfield_existed?(field_normal, normal_fields_group)).to eq false
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'find an 880 field, subfield6 including tag 245' do
|
42
|
+
expect(tind_marc.field_880_on_subfield6_tag('245', fields_880_group)['6']).to eq '245-01/$1'
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '# field_pre_existed' do
|
46
|
+
it 'find pre_existed 880 field' do
|
47
|
+
expect(tind_marc.send(:field_pre_existed, '245', field_880_245, fields_880_group)['6']).to eq '245-01/$1'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'find no pre_existed 880 field' do
|
51
|
+
expect(tind_marc.send(:field_pre_existed, '247', field_880_245, fields_880_group)).to eq nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'find pre_existed regular field' do
|
55
|
+
expect(tind_marc.send(:field_pre_existed, '245', field_normal, normal_fields_group).tag).to eq '245'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'find no pre_existed regular field' do
|
59
|
+
expect(tind_marc.send(:field_pre_existed, '299', field_normal, normal_fields_group)).to eq nil
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindMarc 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(:normal_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('507')] }
|
15
|
+
let(:normal_tindfield_tags) { ['245', '255'] }
|
16
|
+
|
17
|
+
let(:with_pre_existed_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('264')] }
|
18
|
+
let(:current_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('260')] }
|
19
|
+
let(:with_pre_existed_tind_fields_tags) { ['245'] }
|
20
|
+
|
21
|
+
let(:with_pre_existed_subfield_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('507')] }
|
22
|
+
let(:current_with_pre_existed_subfield_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('255')] }
|
23
|
+
let(:with_pre_existed_tind_subfield_fields_tags) { ['245'] }
|
24
|
+
|
25
|
+
# mapped on pre_existed_field rule: "260"
|
26
|
+
# mapped on pre_existed_subfield rule: "255"
|
27
|
+
let(:tindfield_tags) do
|
28
|
+
%w[255 245 246 260 300 300 490 630 650
|
29
|
+
700 710 903 041 269 255]
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:tind_880_subfield6_tags) { ['245', '246', '260', '490', '650', '700', '710', '255', nil, '500', '500', '500', '500'] }
|
33
|
+
|
34
|
+
# mapped on pre_existed_field rule => ''
|
35
|
+
# mapped on pre_existed_subfield rule: "880-255-09"
|
36
|
+
# 880 datafields with '00' in subfield 6 come from field_catalog - 4 tindfields
|
37
|
+
let(:tindfield_880_normal_tags) do
|
38
|
+
%w[880-245-01 880-246-02 880-260-03 880-490-04 880-650-05
|
39
|
+
880-700-06 880-710-07 880-255-09
|
40
|
+
880-500-00 880-500-00 880-500-00 880-500-00]
|
41
|
+
end
|
42
|
+
|
43
|
+
context '# From public methods: ' do
|
44
|
+
it 'get a TIND record' do
|
45
|
+
expect(tind_marc.tind_record).to be_a ::MARC::Record
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'get all tindfields' do
|
49
|
+
expect(tind_marc.tindfields.count).to eq 28 # 7 (normal tindfields) + 21 (880 tindfields)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '# From private methods: ' do
|
54
|
+
|
55
|
+
it 'get normal tindfield tags' do
|
56
|
+
expect(tind_marc.send(:tindfields_group).map(&:tag)).to eq tindfield_tags
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'get 880 tindfield tags' do
|
60
|
+
expect(tind_marc.send(:tindfields_group_880).map { |f| tind_marc.origin_mapping_tag(f) }).to eq tind_880_subfield6_tags
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'get 880 tindfield subfield6 values' do
|
64
|
+
expect(tind_marc.fields_880_subfield6(tind_marc.send(:tindfields_group_880))).to eq tindfield_880_normal_tags
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'get normal tindfields' do
|
68
|
+
expect(tind_marc.send(:tindfields_from_normal, normal_fields).map(&:tag)).to eq normal_tindfield_tags
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'get control tindfields' do
|
72
|
+
expect(tind_marc.send(:tindfields_from_control, []).map(&:tag)).to eq ['041', '269']
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'get tindfields with pre_existed field' do
|
76
|
+
expect(tind_marc.send(:tindfields_with_pre_existed_field, with_pre_existed_fields, current_fields).map(&:tag)).to eq with_pre_existed_tind_fields_tags
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'get tindfields with pre_existed_subfield' do
|
80
|
+
expect(tind_marc.send(:tindfields_with_pre_existed_subfield, with_pre_existed_subfield_fields, current_with_pre_existed_subfield_fields).map(&:tag)).to eq normal_tindfield_tags
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindSubfieldUtil 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(:regular_field_with_subfield6) { qualified_alma_obj.field('246') }
|
16
|
+
let(:regular_field_without_subfield6) { qualified_alma_obj.field('300') }
|
17
|
+
let(:field_880_with_subfield6) { qualified_alma_obj.field_880('490-04/$1') }
|
18
|
+
let(:field_880_without_subfield6) { qualified_alma_obj.field_880(nil) }
|
19
|
+
let(:no_880_matching_list) { ['No matching: 880 $ 245-01/$1 ', 'No matching: 245 $ 880-99 ', 'No matching: 630 $ 880-16 '] }
|
20
|
+
let(:subfield6_values) { ['245-01/$1', '880-16', '246-02/$04', '880-02'] }
|
21
|
+
|
22
|
+
it 'get origin tag from regular field' do
|
23
|
+
expect(tind_marc.origin_mapping_tag(regular_field_with_subfield6)).to eq '246'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'get clean value' do
|
27
|
+
str = 'to [test] removing : special characters :;/'
|
28
|
+
expect(tind_marc.send(:clr_value, str)).to eq 'to test removing : special characters'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'get the lowest seq no' do
|
32
|
+
expect(tind_marc.send(:subfield6_value_with_lowest_seq_no, subfield6_values)).to eq '245-01/$1'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'get origin tag from a 880 field' do
|
36
|
+
it 'with subfield6' do
|
37
|
+
expect(tind_marc.origin_mapping_tag(field_880_with_subfield6)).to eq '490'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'without subfield6' do
|
41
|
+
expect(tind_marc.origin_mapping_tag(field_880_without_subfield6)).to eq nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe Util 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(:un_qualified_alma_obj) { Alma.new('spec/data/mapping/record_not_qualified.xml') }
|
13
|
+
let(:un_qualified_alm_record) { un_qualified_alma_obj.record }
|
14
|
+
|
15
|
+
let(:field) { qualified_alma_obj.field('260') }
|
16
|
+
let(:subfield_hash) do
|
17
|
+
{ '6' => '880-03',
|
18
|
+
'a' => '[Daliang] :',
|
19
|
+
'b' => 'Daliang fu shu,',
|
20
|
+
'c' => 'Qing Qianlong 50 nian [1785]' }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'get three digits' do
|
24
|
+
tag = '1'
|
25
|
+
expect(Util.send(:format_tag, tag)).to eq '001'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'get letters' do
|
29
|
+
tag = 'LDR'
|
30
|
+
expect(Util.send(:format_tag, tag)).to eq 'LDR'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'get subfield hash from a field' do
|
34
|
+
expect(Util.subfield_hash(field)).to eq subfield_hash
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'get qualified alma record' do
|
38
|
+
expect(Util.qualified_alma_record?(qualified_alm_record)).to eq true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'get unqualified alma record' do
|
42
|
+
expect(Util.qualified_alma_record?(un_qualified_alm_record)).to eq false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'get symbol from string "a--a"' do
|
46
|
+
expect(Util.concatenation_symbol('a--a')).to eq ' -- '
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'get symbol from nil' do
|
50
|
+
expect(Util.concatenation_symbol(nil)).to eq ' '
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -187,6 +187,30 @@ module BerkeleyLibrary
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
190
|
+
|
191
|
+
it 'writes to a Tempfile object' do
|
192
|
+
Dir.mktmpdir(File.basename(__FILE__, '.rb')) do |dir|
|
193
|
+
out = Tempfile.new(File.join(dir, 'marc.xml'))
|
194
|
+
begin
|
195
|
+
# noinspection RubyMismatchedArgumentType
|
196
|
+
w = XMLWriter.new(out)
|
197
|
+
w.write(record)
|
198
|
+
w.close
|
199
|
+
|
200
|
+
expected = File.open(input_path) { |f| Nokogiri::XML(f) }
|
201
|
+
actual = File.open(out.path) { |f| Nokogiri::XML(f) }
|
202
|
+
ensure
|
203
|
+
out.close
|
204
|
+
out.unlink
|
205
|
+
end
|
206
|
+
|
207
|
+
aggregate_failures do
|
208
|
+
EquivalentXml.equivalent?(expected, actual) do |n1, n2, result|
|
209
|
+
expect(n2.to_s).to eq(n1.to_s) unless result
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
190
214
|
end
|
191
215
|
end
|
192
216
|
end
|