mods_display 0.3.3 → 0.3.4
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/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +60 -0
- data/.travis.yml +2 -2
- data/Rakefile +10 -2
- data/lib/mods_display.rb +42 -42
- data/lib/mods_display/configuration.rb +69 -67
- data/lib/mods_display/configuration/access_condition.rb +17 -13
- data/lib/mods_display/configuration/base.rb +27 -24
- data/lib/mods_display/configuration/format.rb +8 -4
- data/lib/mods_display/configuration/genre.rb +8 -4
- data/lib/mods_display/configuration/imprint.rb +12 -7
- data/lib/mods_display/configuration/name.rb +8 -4
- data/lib/mods_display/configuration/note.rb +8 -4
- data/lib/mods_display/configuration/related_item.rb +8 -4
- data/lib/mods_display/configuration/subject.rb +11 -9
- data/lib/mods_display/configuration/title.rb +8 -4
- data/lib/mods_display/controller_extension.rb +24 -24
- data/lib/mods_display/country_codes.rb +385 -384
- data/lib/mods_display/fields/abstract.rb +7 -6
- data/lib/mods_display/fields/access_condition.rb +55 -55
- data/lib/mods_display/fields/audience.rb +7 -6
- data/lib/mods_display/fields/cartographics.rb +15 -14
- data/lib/mods_display/fields/collection.rb +32 -17
- data/lib/mods_display/fields/contact.rb +15 -13
- data/lib/mods_display/fields/contents.rb +7 -6
- data/lib/mods_display/fields/description.rb +21 -21
- data/lib/mods_display/fields/field.rb +164 -109
- data/lib/mods_display/fields/format.rb +36 -33
- data/lib/mods_display/fields/genre.rb +12 -11
- data/lib/mods_display/fields/identifier.rb +34 -34
- data/lib/mods_display/fields/imprint.rb +258 -214
- data/lib/mods_display/fields/language.rb +18 -16
- data/lib/mods_display/fields/location.rb +27 -26
- data/lib/mods_display/fields/name.rb +113 -118
- data/lib/mods_display/fields/note.rb +33 -34
- data/lib/mods_display/fields/related_item.rb +64 -66
- data/lib/mods_display/fields/resource_type.rb +13 -11
- data/lib/mods_display/fields/sub_title.rb +6 -4
- data/lib/mods_display/fields/subject.rb +92 -90
- data/lib/mods_display/fields/title.rb +54 -49
- data/lib/mods_display/fields/values.rb +7 -8
- data/lib/mods_display/html.rb +117 -96
- data/lib/mods_display/model_extension.rb +17 -16
- data/lib/mods_display/relator_codes.rb +269 -267
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +13 -12
- data/spec/configuration/access_condition_spec.rb +5 -5
- data/spec/configuration/base_spec.rb +24 -24
- data/spec/fields/abstract_spec.rb +24 -14
- data/spec/fields/access_condition_spec.rb +80 -55
- data/spec/fields/audience_spec.rb +15 -12
- data/spec/fields/cartographics_spec.rb +17 -18
- data/spec/fields/collection_spec.rb +65 -19
- data/spec/fields/contact_spec.rb +11 -9
- data/spec/fields/contents_spec.rb +15 -12
- data/spec/fields/description_spec.rb +40 -22
- data/spec/fields/format_spec.rb +28 -18
- data/spec/fields/genre_spec.rb +18 -16
- data/spec/fields/identifier_spec.rb +46 -34
- data/spec/fields/imprint_spec.rb +151 -125
- data/spec/fields/language_spec.rb +36 -20
- data/spec/fields/location_spec.rb +43 -27
- data/spec/fields/name_spec.rb +92 -92
- data/spec/fields/note_spec.rb +53 -40
- data/spec/fields/related_item_spec.rb +42 -40
- data/spec/fields/resource_type_spec.rb +20 -14
- data/spec/fields/sub_title_spec.rb +11 -9
- data/spec/fields/subject_spec.rb +61 -56
- data/spec/fields/title_spec.rb +53 -40
- data/spec/fixtures/access_condition_fixtures.rb +50 -0
- data/spec/fixtures/cartographics_fixtures.rb +1 -1
- data/spec/fixtures/imprint_fixtures.rb +49 -1
- data/spec/fixtures/name_fixtures.rb +195 -2
- data/spec/fixtures/related_item_fixtures.rb +107 -0
- data/spec/fixtures/subjects_fixtures.rb +15 -2
- data/spec/fixtures/title_fixtures.rb +101 -0
- data/spec/integration/configuration_spec.rb +23 -20
- data/spec/integration/html_spec.rb +40 -29
- data/spec/integration/installation_spec.rb +14 -14
- data/spec/spec_helper.rb +5 -8
- metadata +25 -3
data/spec/fields/contact_spec.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_contact(mods_record)
|
4
|
-
ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Contact do
|
8
8
|
before(:all) do
|
9
|
-
@contact_note = Stanford::Mods::Record.new.from_str(
|
9
|
+
@contact_note = Stanford::Mods::Record.new.from_str(
|
10
|
+
"<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false
|
11
|
+
).note
|
10
12
|
end
|
11
|
-
it
|
13
|
+
it 'should only get contact fields' do
|
12
14
|
fields = mods_display_contact(@contact_note).fields
|
13
|
-
fields.length.
|
14
|
-
fields.first.values.
|
15
|
+
expect(fields.length).to eq(1)
|
16
|
+
expect(fields.first.values).to include('jdoe@example.com')
|
15
17
|
end
|
16
|
-
it
|
18
|
+
it 'should not get any non-contact fields' do
|
17
19
|
fields = mods_display_contact(@contact_note).fields
|
18
|
-
fields.length.
|
19
|
-
fields.first.values.
|
20
|
+
expect(fields.length).to eq(1)
|
21
|
+
expect(fields.first.values).not_to include('Note Field')
|
20
22
|
end
|
21
23
|
end
|
@@ -1,21 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_contents(mods_record)
|
4
|
-
ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Contents do
|
8
8
|
before(:all) do
|
9
|
-
@contents = Stanford::Mods::Record.new.from_str(
|
10
|
-
|
9
|
+
@contents = Stanford::Mods::Record.new.from_str(
|
10
|
+
'<mods><tableOfContents>Content Note</tableOfContents></mods>', false
|
11
|
+
).tableOfContents
|
12
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
13
|
+
"<mods><tableOfContents displayLabel='Special Label'>Content Note</tableOfContents></mods>", false
|
14
|
+
).tableOfContents
|
11
15
|
end
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
mods_display_contents(@contents).label.
|
16
|
+
describe 'label' do
|
17
|
+
it 'should have a default label' do
|
18
|
+
expect(mods_display_contents(@contents).label).to eq('Table of contents:')
|
15
19
|
end
|
16
|
-
it
|
17
|
-
mods_display_contents(@display_label).label.
|
20
|
+
it 'should use the displayLabel attribute when one is available' do
|
21
|
+
expect(mods_display_contents(@display_label).label).to eq('Special Label:')
|
18
22
|
end
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,37 +1,55 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_description(mods)
|
4
|
-
ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Description do
|
8
8
|
before(:all) do
|
9
|
-
@form = Stanford::Mods::Record.new.from_str(
|
10
|
-
|
11
|
-
|
12
|
-
@
|
9
|
+
@form = Stanford::Mods::Record.new.from_str(
|
10
|
+
'<mods><physicalDescription><note>Description Note</note></physicalDescription></mods>', false
|
11
|
+
).physical_description
|
12
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
13
|
+
"<mods>
|
14
|
+
<physicalDescription displayLabel='SpecialLabel'><note>Description Note</note></physicalDescription>
|
15
|
+
</mods>", false
|
16
|
+
).physical_description
|
17
|
+
@child_display_label = Stanford::Mods::Record.new.from_str(
|
18
|
+
"<mods><physicalDescription><note displayLabel='Note Label'>Description Note</note></physicalDescription></mods>",
|
19
|
+
false
|
20
|
+
).physical_description
|
21
|
+
@mixed = Stanford::Mods::Record.new.from_str(
|
22
|
+
'<mods>
|
23
|
+
<physicalDescription>
|
24
|
+
<note>Description Note</note>
|
25
|
+
<digitalOrigin>Digital Origin Note</digitalOrigin>
|
26
|
+
</physicalDescription>
|
27
|
+
</mods>', false
|
28
|
+
).physical_description
|
13
29
|
end
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
mods_display_description(@display_label).fields.first.label.
|
30
|
+
describe 'labels' do
|
31
|
+
it 'should use the displayLabel if one is provided' do
|
32
|
+
expect(mods_display_description(@display_label).fields.first.label).to eq('SpecialLabel:')
|
17
33
|
end
|
18
|
-
it
|
19
|
-
mods_display_description(@form).fields.first.label.
|
34
|
+
it 'should get the default label for a child element' do
|
35
|
+
expect(mods_display_description(@form).fields.first.label).to eq('Note:')
|
20
36
|
end
|
21
|
-
it
|
22
|
-
mods_display_description(@mixed).fields.map
|
37
|
+
it 'should get multiple lables for mixed content' do
|
38
|
+
expect(mods_display_description(@mixed).fields.map(&:label)).to eq(['Note:', 'Digital origin:'])
|
23
39
|
end
|
24
|
-
it
|
25
|
-
mods_display_description(@child_display_label).fields.map
|
40
|
+
it 'should get the display label from child elements' do
|
41
|
+
expect(mods_display_description(@child_display_label).fields.map(&:label)).to eq(['Note Label:'])
|
26
42
|
end
|
27
43
|
end
|
28
|
-
|
29
|
-
describe
|
30
|
-
it
|
31
|
-
mods_display_description(@form).fields.first.values.
|
44
|
+
|
45
|
+
describe 'fields' do
|
46
|
+
it 'should get the value from a field in physicalDescription' do
|
47
|
+
expect(mods_display_description(@form).fields.first.values).to eq(['Description Note'])
|
32
48
|
end
|
33
|
-
it
|
34
|
-
mods_display_description(@mixed).fields.map
|
49
|
+
it 'should get multiple values for mixed content' do
|
50
|
+
expect(mods_display_description(@mixed).fields.map(&:values)).to eq(
|
51
|
+
[['Description Note'], ['Digital Origin Note']]
|
52
|
+
)
|
35
53
|
end
|
36
54
|
end
|
37
|
-
end
|
55
|
+
end
|
data/spec/fields/format_spec.rb
CHANGED
@@ -1,31 +1,41 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
def mods_display_format(mods)
|
3
|
-
ModsDisplay::Format.new(mods, ModsDisplay::Configuration::Base.new, double(
|
3
|
+
ModsDisplay::Format.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
|
4
4
|
end
|
5
5
|
|
6
6
|
describe ModsDisplay::Format do
|
7
7
|
before(:all) do
|
8
|
-
@format = Stanford::Mods::Record.new.from_str(
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
|
8
|
+
@format = Stanford::Mods::Record.new.from_str(
|
9
|
+
'<mods><typeOfResource>Format</typeOfResource></mods>', false
|
10
|
+
).typeOfResource
|
11
|
+
@duplicate_forms = Stanford::Mods::Record.new.from_str(
|
12
|
+
'<mods><physicalDescription><form>Map</form><form>Map</form></physicalDescription></mods>', false
|
13
|
+
)
|
14
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
15
|
+
"<mods><typeOfResource displayLabel='SpecialFormat'>Mixed Materials</typeOfResource></mods>", false
|
16
|
+
).typeOfResource
|
17
|
+
@space_format = Stanford::Mods::Record.new.from_str(
|
18
|
+
'<mods><typeOfResource>Mixed Materials</typeOfResource></mods>', false
|
19
|
+
).typeOfResource
|
20
|
+
@slash_format = Stanford::Mods::Record.new.from_str(
|
21
|
+
'<mods><typeOfResource>Manuscript/Archive</typeOfResource></mods>', false
|
22
|
+
).typeOfResource
|
13
23
|
end
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
ModsDisplay::Format.send(:format_class,
|
24
|
+
describe 'format_class' do
|
25
|
+
it 'should remove any spaces' do
|
26
|
+
expect(ModsDisplay::Format.send(:format_class, 'Mixed Materials')).to eq('mixed_materials')
|
17
27
|
end
|
18
|
-
it
|
19
|
-
ModsDisplay::Format.send(:format_class,
|
28
|
+
it 'should replace any slashes' do
|
29
|
+
expect(ModsDisplay::Format.send(:format_class, 'Manuscript/Archive')).to eq('manuscript_archive')
|
20
30
|
end
|
21
31
|
end
|
22
|
-
describe
|
23
|
-
describe
|
24
|
-
it
|
32
|
+
describe 'fields' do
|
33
|
+
describe 'form' do
|
34
|
+
it 'should remove duplicate values' do
|
25
35
|
fields = mods_display_format(@duplicate_forms).fields
|
26
|
-
fields.length.
|
27
|
-
fields.first.values.
|
36
|
+
expect(fields.length).to eq(1)
|
37
|
+
expect(fields.first.values).to eq(['Map'])
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
31
|
-
end
|
41
|
+
end
|
data/spec/fields/genre_spec.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_genre(mods_record)
|
4
|
-
ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Abstract do
|
8
8
|
before(:all) do
|
9
|
-
@genre = Stanford::Mods::Record.new.from_str(
|
10
|
-
@downcase = Stanford::Mods::Record.new.from_str(
|
11
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
9
|
+
@genre = Stanford::Mods::Record.new.from_str('<mods><genre>Map Data</genre></mods>', false).genre
|
10
|
+
@downcase = Stanford::Mods::Record.new.from_str('<mods><genre>map data</genre></mods>', false).genre
|
11
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
12
|
+
"<mods><genre displayLabel='Special label'>Catographic</genre></mods>", false
|
13
|
+
).genre
|
12
14
|
end
|
13
|
-
describe
|
15
|
+
describe 'labels' do
|
14
16
|
it "should return a default 'Genre' label" do
|
15
17
|
fields = mods_display_genre(@genre).fields
|
16
|
-
fields.length.
|
17
|
-
fields.first.label.
|
18
|
+
expect(fields.length).to eq(1)
|
19
|
+
expect(fields.first.label).to eq('Genre:')
|
18
20
|
end
|
19
|
-
it
|
21
|
+
it 'should use a display label when one is available' do
|
20
22
|
fields = mods_display_genre(@display_label).fields
|
21
|
-
fields.length.
|
22
|
-
fields.first.label.
|
23
|
+
expect(fields.length).to eq(1)
|
24
|
+
expect(fields.first.label).to eq('Special label:')
|
23
25
|
end
|
24
26
|
end
|
25
|
-
describe
|
26
|
-
it
|
27
|
+
describe 'fields' do
|
28
|
+
it 'should capitalize the first letter in a genre' do
|
27
29
|
fields = mods_display_genre(@downcase).fields
|
28
|
-
fields.length.
|
29
|
-
fields.first.values.
|
30
|
+
expect(fields.length).to eq(1)
|
31
|
+
expect(fields.first.values).to eq(['Map data'])
|
30
32
|
end
|
31
33
|
end
|
32
|
-
end
|
34
|
+
end
|
@@ -1,49 +1,61 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
def mods_display_id(mods_record)
|
4
|
-
ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double(
|
4
|
+
ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
5
|
end
|
6
6
|
|
7
7
|
describe ModsDisplay::Note do
|
8
8
|
before(:all) do
|
9
|
-
@id = Stanford::Mods::Record.new.from_str(
|
10
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
11
|
-
|
12
|
-
|
13
|
-
@
|
9
|
+
@id = Stanford::Mods::Record.new.from_str('<mods><identifier>12345</identifier></mods>', false).identifier
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str(
|
11
|
+
"<mods><identifier displayLabel='Special Label'>54321</identifier></mods>", false
|
12
|
+
).identifier
|
13
|
+
@issue_label = Stanford::Mods::Record.new.from_str(
|
14
|
+
"<mods><identifier type='issue number'>Issue 1</identifier></mods>", false
|
15
|
+
).identifier
|
16
|
+
@type_label = Stanford::Mods::Record.new.from_str(
|
17
|
+
"<mods><identifier type='Some other Type'>98765</identifier></mods>", false
|
18
|
+
).identifier
|
19
|
+
@complex_label = Stanford::Mods::Record.new.from_str(
|
20
|
+
"<mods>
|
21
|
+
<identifier>12345</identifier>
|
22
|
+
<identifier>54321</identifier>
|
23
|
+
<identifier type='issue number'>12345</identifier>
|
24
|
+
<identifier>98765</identifier>
|
25
|
+
</mods>", false
|
26
|
+
).identifier
|
14
27
|
end
|
15
|
-
describe
|
16
|
-
it
|
17
|
-
mods_display_id(@id).fields.first.label.
|
28
|
+
describe 'label' do
|
29
|
+
it 'should have a default label' do
|
30
|
+
expect(mods_display_id(@id).fields.first.label).to eq('Identifier:')
|
18
31
|
end
|
19
|
-
it
|
20
|
-
mods_display_id(@display_label).fields.first.label.
|
32
|
+
it 'should use the displayLabel attribute when one is available' do
|
33
|
+
expect(mods_display_id(@display_label).fields.first.label).to eq('Special Label:')
|
21
34
|
end
|
22
|
-
it
|
23
|
-
mods_display_id(@issue_label).fields.first.label.
|
35
|
+
it 'should use get a label from a list of translations' do
|
36
|
+
expect(mods_display_id(@issue_label).fields.first.label).to eq('Issue number:')
|
24
37
|
end
|
25
|
-
it
|
26
|
-
mods_display_id(@type_label).fields.first.label.
|
38
|
+
it 'should use use the raw type attribute if one is present' do
|
39
|
+
expect(mods_display_id(@type_label).fields.first.label).to eq('Some other Type:')
|
27
40
|
end
|
28
41
|
end
|
29
|
-
|
30
|
-
describe
|
31
|
-
it
|
42
|
+
|
43
|
+
describe 'fields' do
|
44
|
+
it 'should handle matching adjacent labels' do
|
32
45
|
fields = mods_display_id(@complex_label).fields
|
33
|
-
fields.length.
|
34
|
-
|
35
|
-
fields.first.label.
|
36
|
-
fields.first.values.length.
|
37
|
-
fields.first.values.
|
38
|
-
|
39
|
-
fields[1].label.
|
40
|
-
fields[1].values.length.
|
41
|
-
fields[1].values.
|
42
|
-
|
43
|
-
fields.last.label.
|
44
|
-
fields.last.values.length.
|
45
|
-
fields.last.values.
|
46
|
+
expect(fields.length).to eq(3)
|
47
|
+
|
48
|
+
expect(fields.first.label).to eq('Identifier:')
|
49
|
+
expect(fields.first.values.length).to eq(2)
|
50
|
+
expect(fields.first.values).to eq(%w(12345 54321))
|
51
|
+
|
52
|
+
expect(fields[1].label).to eq('Issue number:')
|
53
|
+
expect(fields[1].values.length).to eq(1)
|
54
|
+
expect(fields[1].values).to eq(['12345'])
|
55
|
+
|
56
|
+
expect(fields.last.label).to eq('Identifier:')
|
57
|
+
expect(fields.last.values.length).to eq(1)
|
58
|
+
expect(fields.last.values).to eq(['98765'])
|
46
59
|
end
|
47
60
|
end
|
48
|
-
|
49
|
-
end
|
61
|
+
end
|
data/spec/fields/imprint_spec.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/imprint_fixtures'
|
3
3
|
|
4
4
|
include ImprintFixtures
|
5
5
|
|
6
6
|
def mods_display_imprint(mods_record)
|
7
|
-
ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new, double(
|
7
|
+
ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new, double('controller'))
|
8
8
|
end
|
9
|
+
|
9
10
|
def mods_display_format_date_imprint(mods_record)
|
10
|
-
ModsDisplay::Imprint.new(
|
11
|
+
ModsDisplay::Imprint.new(
|
12
|
+
mods_record,
|
13
|
+
ModsDisplay::Configuration::Imprint.new do
|
14
|
+
full_date_format('(%Y) %B, %d')
|
15
|
+
short_date_format('%B (%Y)')
|
16
|
+
end,
|
17
|
+
double('controller')
|
18
|
+
)
|
11
19
|
end
|
12
20
|
|
13
21
|
describe ModsDisplay::Imprint do
|
@@ -37,209 +45,227 @@ describe ModsDisplay::Imprint do
|
|
37
45
|
@encoded_dates = Stanford::Mods::Record.new.from_str(encoded_dates, false).origin_info
|
38
46
|
@bad_dates = Stanford::Mods::Record.new.from_str(bad_dates, false).origin_info
|
39
47
|
@invalid_dates = Stanford::Mods::Record.new.from_str(invalid_dates, false).origin_info
|
48
|
+
@punctuation_imprint = Stanford::Mods::Record.new.from_str(punctuation_imprint_fixture, false).origin_info
|
49
|
+
@bc_ad_dates = Stanford::Mods::Record.new.from_str(bc_ad_imprint_date_fixture, false).origin_info
|
40
50
|
end
|
41
51
|
|
42
|
-
describe
|
43
|
-
it
|
44
|
-
mods_display_imprint(@imprint).fields.first.label.
|
52
|
+
describe 'labels' do
|
53
|
+
it 'should get the Imprint label by default' do
|
54
|
+
expect(mods_display_imprint(@imprint).fields.first.label).to eq('Imprint:')
|
45
55
|
end
|
46
|
-
it
|
56
|
+
it 'should get the label from non-imprint origin info fields' do
|
47
57
|
fields = mods_display_imprint(@edition_and_date).fields
|
48
|
-
fields.first.label.
|
49
|
-
fields.last.label.
|
58
|
+
expect(fields.first.label).to eq('Date valid:')
|
59
|
+
expect(fields.last.label).to eq('Issuance:')
|
50
60
|
end
|
51
|
-
it
|
52
|
-
mods_display_imprint(@mixed).fields.map
|
61
|
+
it 'should get multiple labels when we have mixed content' do
|
62
|
+
expect(mods_display_imprint(@mixed).fields.map(&:label)).to eq(['Imprint:', 'Date captured:', 'Issuance:'])
|
53
63
|
end
|
54
|
-
it
|
55
|
-
|
64
|
+
it 'should use the displayLabel when available' do
|
65
|
+
expect(mods_display_imprint(@display_label).fields.map(&:label)).to eq(['TheLabel:', 'IssuanceLabel:'])
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
59
|
-
describe
|
60
|
-
it
|
61
|
-
mods_display_imprint(@imprint).fields.map
|
69
|
+
describe 'fields' do
|
70
|
+
it 'should return various parts of the imprint' do
|
71
|
+
expect(mods_display_imprint(@imprint).fields.map(&:values).join(' ')).to eq(
|
72
|
+
'An edition - A Place : A Publisher, An Issue Date, Another Date'
|
73
|
+
)
|
62
74
|
end
|
63
|
-
it
|
64
|
-
values = mods_display_imprint(@no_edition).fields.map
|
65
|
-
values.strip.
|
66
|
-
values.
|
75
|
+
it 'should handle the punctuation when the edition is missing' do
|
76
|
+
values = mods_display_imprint(@no_edition).fields.map(&:values).join(' ')
|
77
|
+
expect(values.strip).not_to match(/^-/)
|
78
|
+
expect(values).to match(/^A Place/)
|
67
79
|
end
|
68
|
-
it
|
80
|
+
it 'should get the text for non-imprint origin info fields' do
|
69
81
|
fields = mods_display_imprint(@edition_and_date).fields
|
70
|
-
fields.first.values.
|
71
|
-
fields.last.values.
|
82
|
+
expect(fields.first.values).to eq(['A Valid Date'])
|
83
|
+
expect(fields.last.values).to eq(['The Issuance'])
|
72
84
|
end
|
73
|
-
it
|
85
|
+
it 'should handle mixed mods properly' do
|
74
86
|
values = mods_display_imprint(@mixed).fields
|
75
|
-
values.length.
|
76
|
-
values.map
|
77
|
-
values.map
|
78
|
-
values.map
|
87
|
+
expect(values.length).to eq(3)
|
88
|
+
expect(values.map(&:values)).to include(['A Place : A Publisher'])
|
89
|
+
expect(values.map(&:values)).to include(['The Issuance'])
|
90
|
+
expect(values.map(&:values)).to include(['The Capture Date'])
|
79
91
|
end
|
80
92
|
end
|
81
|
-
describe
|
82
|
-
describe
|
93
|
+
describe 'date processing' do
|
94
|
+
describe 'ranges' do
|
83
95
|
it "should join start and end point ranges with a '-'" do
|
84
96
|
fields = mods_display_imprint(@date_range).fields
|
85
|
-
fields.length.
|
86
|
-
fields.first.values.
|
97
|
+
expect(fields.length).to eq(1)
|
98
|
+
expect(fields.first.values).to eq(['1820-1825'])
|
87
99
|
end
|
88
|
-
it
|
100
|
+
it 'should handle open ranges properly' do
|
89
101
|
fields = mods_display_imprint(@open_date_range).fields
|
90
|
-
fields.length.
|
91
|
-
fields.first.values.
|
102
|
+
expect(fields.length).to eq(1)
|
103
|
+
expect(fields.first.values).to eq(['1820-'])
|
92
104
|
end
|
93
|
-
it
|
105
|
+
it 'should handle when there are more than 3 of the same date w/i a range' do
|
94
106
|
fields = mods_display_imprint(@three_imprint_dates).fields
|
95
|
-
fields.length.
|
96
|
-
fields.first.values.
|
107
|
+
expect(fields.length).to eq(1)
|
108
|
+
expect(fields.first.values).to eq(['[1820-1825?]'])
|
97
109
|
end
|
98
|
-
it
|
110
|
+
it 'should apply the qualifier decoration in the imprints' do
|
99
111
|
fields = mods_display_imprint(@qualified_imprint_date).fields
|
100
|
-
fields.length.
|
101
|
-
fields.first.values.
|
112
|
+
expect(fields.length).to eq(1)
|
113
|
+
expect(fields.first.values).to eq(['[1820?]'])
|
102
114
|
end
|
103
|
-
it
|
115
|
+
it 'should handle date ranges in imprints' do
|
104
116
|
fields = mods_display_imprint(@imprint_date_range).fields
|
105
|
-
fields.length.
|
106
|
-
fields.first.values.
|
117
|
+
expect(fields.length).to eq(1)
|
118
|
+
expect(fields.first.values).to eq(['1820-1825'])
|
107
119
|
end
|
108
|
-
it
|
120
|
+
it 'should handle encoded dates properly' do
|
109
121
|
fields = mods_display_imprint(@encoded_date_range).fields
|
110
|
-
fields.length.
|
111
|
-
fields.first.values.
|
122
|
+
expect(fields.length).to eq 1
|
123
|
+
expect(fields.first.values).to eq ['February 01, 2008-December 02, 2009']
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should handle B.C. and A.D. dates appropriately' do
|
127
|
+
fields = mods_display_imprint(@bc_ad_dates).fields
|
128
|
+
expect(fields.length).to eq 1
|
129
|
+
expect(fields.first.values).to eq ['12 B.C.-44 A.D.']
|
112
130
|
end
|
113
131
|
end
|
114
|
-
describe
|
115
|
-
it
|
132
|
+
describe 'duplication' do
|
133
|
+
it 'should only return the qualified date when present' do
|
116
134
|
fields = mods_display_imprint(@dup_qualified_date).fields
|
117
|
-
fields.length.
|
118
|
-
fields.first.values.
|
135
|
+
expect(fields.length).to eq(1)
|
136
|
+
expect(fields.first.values).to eq(['[1820?]'])
|
119
137
|
end
|
120
|
-
it
|
138
|
+
it 'should use the non-encoded date when prsent' do
|
121
139
|
fields = mods_display_imprint(@dup_unencoded_date).fields
|
122
|
-
fields.length.
|
123
|
-
fields.first.values.
|
140
|
+
expect(fields.length).to eq(1)
|
141
|
+
expect(fields.first.values).to eq(['[ca. 1820]'])
|
124
142
|
end
|
125
|
-
it
|
143
|
+
it 'should handle copyright dates correctly' do
|
126
144
|
fields = mods_display_imprint(@dup_copyright_date).fields
|
127
|
-
fields.length.
|
128
|
-
fields.first.values.
|
145
|
+
expect(fields.length).to eq(1)
|
146
|
+
expect(fields.first.values).to eq(['c1820'])
|
129
147
|
end
|
130
|
-
it
|
148
|
+
it 'should only return one when no attributes are present' do
|
131
149
|
fields = mods_display_imprint(@dup_date).fields
|
132
|
-
fields.length.
|
133
|
-
fields.first.values.
|
150
|
+
expect(fields.length).to eq(1)
|
151
|
+
expect(fields.first.values).to eq(['1820'])
|
134
152
|
end
|
135
153
|
end
|
136
|
-
describe
|
154
|
+
describe 'qualifier decoration' do
|
137
155
|
it "should prepend a 'c' to approximate dates" do
|
138
156
|
fields = mods_display_imprint(@approximate_date).fields
|
139
|
-
fields.length.
|
140
|
-
fields.first.values.
|
157
|
+
expect(fields.length).to eq(1)
|
158
|
+
expect(fields.first.values).to eq(['[ca. 1820]'])
|
141
159
|
end
|
142
160
|
it "should append a '?' to a questionable dates and wrap them in square-brackets" do
|
143
161
|
fields = mods_display_imprint(@questionable_date).fields
|
144
|
-
fields.length.
|
145
|
-
fields.first.values.
|
162
|
+
expect(fields.length).to eq(1)
|
163
|
+
expect(fields.first.values).to eq(['[1820?]'])
|
146
164
|
end
|
147
|
-
it
|
165
|
+
it 'should wrap inferred dates in square-brackets' do
|
148
166
|
fields = mods_display_imprint(@inferred_date).fields
|
149
|
-
fields.length.
|
150
|
-
fields.first.values.
|
167
|
+
expect(fields.length).to eq(1)
|
168
|
+
expect(fields.first.values).to eq(['[1820]'])
|
151
169
|
end
|
152
170
|
end
|
153
|
-
describe
|
154
|
-
describe
|
155
|
-
it
|
171
|
+
describe 'encoded dates' do
|
172
|
+
describe 'W3CDTF' do
|
173
|
+
it 'should handle single year dates properly' do
|
156
174
|
fields = mods_display_imprint(@encoded_dates).fields
|
157
|
-
fields.length.
|
158
|
-
fields.find do |field|
|
159
|
-
field.label ==
|
160
|
-
end.values.
|
175
|
+
expect(fields.length).to eq(4)
|
176
|
+
expect(fields.find do |field|
|
177
|
+
field.label == 'Imprint:'
|
178
|
+
end.values).to eq(['2013'])
|
161
179
|
end
|
162
|
-
it
|
180
|
+
it 'should handle month+year dates properly' do
|
163
181
|
fields = mods_display_imprint(@encoded_dates).fields
|
164
|
-
fields.length.
|
165
|
-
fields.find do |field|
|
166
|
-
field.label ==
|
167
|
-
end.values.
|
182
|
+
expect(fields.length).to eq(4)
|
183
|
+
expect(fields.find do |field|
|
184
|
+
field.label == 'Date captured:'
|
185
|
+
end.values).to eq(['July 2013'])
|
168
186
|
end
|
169
|
-
it
|
187
|
+
it 'should handle full dates properly' do
|
170
188
|
fields = mods_display_imprint(@encoded_dates).fields
|
171
|
-
fields.length.
|
172
|
-
fields.find do |field|
|
173
|
-
field.label ==
|
174
|
-
end.values.
|
189
|
+
expect(fields.length).to eq(4)
|
190
|
+
expect(fields.find do |field|
|
191
|
+
field.label == 'Date created:'
|
192
|
+
end.values).to eq(['July 10, 2013'])
|
175
193
|
end
|
176
194
|
it "should not try to handle dates we can't parse" do
|
177
195
|
fields = mods_display_imprint(@encoded_dates).fields
|
178
|
-
fields.length.
|
179
|
-
fields.find do |field|
|
180
|
-
field.label ==
|
181
|
-
end.values.
|
196
|
+
expect(fields.length).to eq(4)
|
197
|
+
expect(fields.find do |field|
|
198
|
+
field.label == 'Date modified:'
|
199
|
+
end.values).to eq(['Jul. 22, 2013'])
|
182
200
|
end
|
183
|
-
it
|
201
|
+
it 'should accept date configurations' do
|
184
202
|
fields = mods_display_format_date_imprint(@encoded_dates).fields
|
185
|
-
fields.length.
|
186
|
-
fields.find do |field|
|
187
|
-
field.label ==
|
188
|
-
end.values.
|
189
|
-
fields.find do |field|
|
190
|
-
field.label ==
|
191
|
-
end.values.
|
203
|
+
expect(fields.length).to eq(4)
|
204
|
+
expect(fields.find do |field|
|
205
|
+
field.label == 'Date created:'
|
206
|
+
end.values).to eq(['(2013) July, 10'])
|
207
|
+
expect(fields.find do |field|
|
208
|
+
field.label == 'Date captured:'
|
209
|
+
end.values).to eq(['July (2013)'])
|
192
210
|
end
|
193
211
|
end
|
194
212
|
end
|
195
|
-
describe
|
196
|
-
it
|
213
|
+
describe 'bad dates' do
|
214
|
+
it 'should ignore date values' do
|
197
215
|
fields = mods_display_imprint(@bad_dates).fields
|
198
|
-
fields.length.
|
216
|
+
expect(fields.length).to eq(2)
|
199
217
|
fields.each do |field|
|
200
|
-
field.values.join.
|
218
|
+
expect(field.values.join).not_to include '9999'
|
201
219
|
end
|
202
220
|
end
|
203
|
-
it
|
221
|
+
it 'should handle invalid dates by returning the original value' do
|
204
222
|
fields = mods_display_imprint(@invalid_dates).fields
|
205
|
-
fields.length.
|
206
|
-
fields.last.values.
|
223
|
+
expect(fields.length).to eq(2)
|
224
|
+
expect(fields.last.values).to eq(['1920-09-00'])
|
207
225
|
end
|
208
226
|
end
|
209
227
|
end
|
210
|
-
|
211
|
-
|
228
|
+
|
229
|
+
describe 'punctuation' do
|
230
|
+
it 'should not duplicate punctuation' do
|
231
|
+
fields = mods_display_imprint(@punctuation_imprint).fields
|
232
|
+
expect(fields.length).to eq 1
|
233
|
+
expect(fields.first.values).to eq ['San Francisco : Chronicle Books, 2015.']
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe 'place processing' do
|
238
|
+
it 'should exclude encoded places' do
|
212
239
|
fields = mods_display_imprint(@encoded_place).fields
|
213
|
-
fields.length.
|
214
|
-
fields.first.values.
|
240
|
+
expect(fields.length).to eq(1)
|
241
|
+
expect(fields.first.values).to eq(['[Amsterdam]', '[United States]', 'Netherlands'])
|
215
242
|
end
|
216
243
|
it "should translate encoded place if there isn't a text (or non-typed) value available" do
|
217
244
|
fields = mods_display_imprint(@encoded_place).fields
|
218
|
-
fields.length.
|
219
|
-
fields.first.values.
|
245
|
+
expect(fields.length).to eq(1)
|
246
|
+
expect(fields.first.values).to include 'Netherlands'
|
220
247
|
end
|
221
248
|
it "should ignore 'xx' country codes" do
|
222
249
|
fields = mods_display_imprint(@xx_country_code).fields
|
223
|
-
fields.length.
|
224
|
-
fields.first.values.
|
250
|
+
expect(fields.length).to eq(1)
|
251
|
+
expect(fields.first.values).to eq(['1994'])
|
225
252
|
end
|
226
253
|
end
|
227
|
-
describe
|
228
|
-
it
|
254
|
+
describe 'to_html' do
|
255
|
+
it 'should return the display form if one is available' do
|
229
256
|
html = mods_display_imprint(@display_form).to_html
|
230
|
-
html.scan(/<dd>/).length.
|
231
|
-
html.scan(
|
257
|
+
expect(html.scan(/<dd>/).length).to eq(2)
|
258
|
+
expect(html.scan(%r{<dd>The Display Form</dd>}).length).to eq(2)
|
232
259
|
end
|
233
260
|
it "should return the displayLabel when present if we're using the displayForm" do
|
234
|
-
mods_display_imprint(@display_form_with_label).to_html.
|
261
|
+
expect(mods_display_imprint(@display_form_with_label).to_html).to match(%r{<dt title='TheLabel'>TheLabel:</dt>})
|
235
262
|
end
|
236
|
-
it
|
263
|
+
it 'should have individual dt/dd pairs for mixed content' do
|
237
264
|
html = mods_display_imprint(@mixed).to_html
|
238
|
-
html.scan(
|
239
|
-
html.scan(
|
240
|
-
html.scan(
|
241
|
-
html.scan(/<dd>/).length.
|
265
|
+
expect(html.scan(%r{<dt title='Imprint'>Imprint:</dt>}).length).to eq(1)
|
266
|
+
expect(html.scan(%r{<dt title='Issuance'>Issuance:</dt>}).length).to eq(1)
|
267
|
+
expect(html.scan(%r{<dt title='Date captured'>Date captured:</dt>}).length).to eq(1)
|
268
|
+
expect(html.scan(/<dd>/).length).to eq(3)
|
242
269
|
end
|
243
270
|
end
|
244
|
-
|
245
|
-
end
|
271
|
+
end
|