mods_display 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -6,25 +6,32 @@ class ModsDisplay::Imprint < ModsDisplay::Field
|
|
6
6
|
if imprint_display_form(val)
|
7
7
|
return_values << imprint_display_form(val)
|
8
8
|
else
|
9
|
+
edition = nil
|
9
10
|
place = nil
|
10
11
|
publisher = nil
|
11
12
|
placePub = nil
|
13
|
+
edition = val.edition.map do |e|
|
14
|
+
e.text unless e.text.strip.empty?
|
15
|
+
end.compact.join(" ").strip
|
12
16
|
place = val.place.map do |p|
|
13
17
|
p.text unless p.text.strip.empty?
|
14
18
|
end.compact.join(" : ").strip unless val.place.text.strip.empty?
|
15
19
|
publisher = val.publisher.map do |p|
|
16
20
|
p.text unless p.text.strip.empty?
|
17
21
|
end.compact.join(" : ").strip unless val.publisher.text.strip.empty?
|
18
|
-
placePub = [place, publisher].compact.join(" : ")
|
19
|
-
placePub = nil if placePub.strip.empty?
|
20
22
|
parts = val.children.select do |child|
|
21
|
-
["
|
23
|
+
["dateIssued", "dateOther"].include?(child.name) and !child.attributes.has_key?("encoding")
|
22
24
|
end.map do |child|
|
23
25
|
child.text.strip unless child.text.strip.empty?
|
24
26
|
end.compact.join(", ")
|
27
|
+
edition = nil if edition.strip.empty?
|
25
28
|
parts = nil if parts.strip.empty?
|
26
|
-
|
27
|
-
|
29
|
+
placePub = [place, publisher].compact.join(" : ")
|
30
|
+
placePub = nil if placePub.strip.empty?
|
31
|
+
editionPlace = [edition, placePub].compact.join(" - ")
|
32
|
+
editionPlace = nil if editionPlace.strip.empty?
|
33
|
+
unless [editionPlace, parts].compact.join(", ").strip.empty?
|
34
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(val) || "Imprint", :values => [[editionPlace, parts].compact.join(", ")])
|
28
35
|
end
|
29
36
|
if other_pub_info(val).length > 0
|
30
37
|
other_pub_info(val).each do |pub_info|
|
@@ -56,10 +63,11 @@ class ModsDisplay::Imprint < ModsDisplay::Field
|
|
56
63
|
end
|
57
64
|
|
58
65
|
def pub_info_labels
|
59
|
-
{:
|
66
|
+
{:dateCreated => "Date created",
|
67
|
+
:dateCaptured => "Date captured",
|
68
|
+
:dateValid => "Date valid",
|
60
69
|
:dateModified => "Date modified",
|
61
70
|
:copyrightDate => "Copyright date",
|
62
|
-
:edition => "Edition",
|
63
71
|
:issuance => "Issuance",
|
64
72
|
:frequency => "Frequency"
|
65
73
|
}
|
@@ -21,7 +21,7 @@ class ModsDisplay::Title < ModsDisplay::Field
|
|
21
21
|
["partName", "partNumber"].include?(child.name)
|
22
22
|
end.map do |child|
|
23
23
|
child.text
|
24
|
-
end.compact.join(
|
24
|
+
end.compact.join(parts_delimiter(val))
|
25
25
|
parts = nil if parts.strip.empty?
|
26
26
|
return_values << ModsDisplay::Values.new(:label => displayLabel(val) || title_label(val), :values => [[preParts, parts].compact.join(". ")])
|
27
27
|
end
|
@@ -31,6 +31,15 @@ class ModsDisplay::Title < ModsDisplay::Field
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
+
def parts_delimiter(element)
|
35
|
+
children = element.children.to_a
|
36
|
+
# index will retun nil which is not comparable so we call 100 if the element isn't present (thus meaning it's at the end of the list)
|
37
|
+
if (children.index{ |c| c.name == "partNumber" } || 100) < (children.index{|c| c.name == "partName"} || 100)
|
38
|
+
return ", "
|
39
|
+
end
|
40
|
+
". "
|
41
|
+
end
|
42
|
+
|
34
43
|
def title_label(element)
|
35
44
|
if (element.attributes["type"].respond_to?(:value) and
|
36
45
|
title_labels.has_key?(element.attributes["type"].value))
|
data/lib/mods_display/version.rb
CHANGED
data/spec/fields/imprint_spec.rb
CHANGED
@@ -10,6 +10,7 @@ end
|
|
10
10
|
describe ModsDisplay::Imprint do
|
11
11
|
before(:all) do
|
12
12
|
@imprint = Stanford::Mods::Record.new.from_str(imprint_mods, false).origin_info
|
13
|
+
@no_edition = Stanford::Mods::Record.new.from_str(no_edition_mods, false).origin_info
|
13
14
|
@edition_and_date = Stanford::Mods::Record.new.from_str(origin_info_mods, false).origin_info
|
14
15
|
@encoded_date = Stanford::Mods::Record.new.from_str(encoded_date, false).origin_info
|
15
16
|
@encoded_only = Stanford::Mods::Record.new.from_str(only_encoded_data, false).origin_info
|
@@ -26,24 +27,29 @@ describe ModsDisplay::Imprint do
|
|
26
27
|
it "should get the label from non-imprint origin info fields" do
|
27
28
|
fields = mods_display_imprint(@edition_and_date).fields
|
28
29
|
fields.first.label.should == "Date valid"
|
29
|
-
fields.last.label.should == "
|
30
|
+
fields.last.label.should == "Issuance"
|
30
31
|
end
|
31
32
|
it "should get multiple labels when we have mixed content" do
|
32
|
-
mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint", "
|
33
|
+
mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint", "Issuance", "Date captured"]
|
33
34
|
end
|
34
35
|
it "should use the displayLabel when available" do
|
35
|
-
mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "
|
36
|
+
mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "IssuanceLabel", "IssuanceLabel"]
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
40
|
describe "fields" do
|
40
41
|
it "should return various parts of the imprint" do
|
41
|
-
mods_display_imprint(@imprint).fields.map{|val| val.values }.join(" ").should == "A Place : A Publisher,
|
42
|
+
mods_display_imprint(@imprint).fields.map{|val| val.values }.join(" ").should == "An edition - A Place : A Publisher, An Issue Date, Another Date"
|
43
|
+
end
|
44
|
+
it "should handle the punctuation when the edition is missing" do
|
45
|
+
values = mods_display_imprint(@no_edition).fields.map{|val| val.values }.join(" ")
|
46
|
+
values.strip.should_not match(/^-/)
|
47
|
+
values.should match(/^A Place/)
|
42
48
|
end
|
43
49
|
it "should get the text for non-imprint origin info fields" do
|
44
50
|
fields = mods_display_imprint(@edition_and_date).fields
|
45
51
|
fields.first.values.should == ["A Valid Date"]
|
46
|
-
fields.last.values.should == ["The
|
52
|
+
fields.last.values.should == ["The Issuance"]
|
47
53
|
end
|
48
54
|
it "should omit dates with an encoding attribute" do
|
49
55
|
mods_display_imprint(@encoded_date).fields.map{|val| val.values }.join.should_not include("An Encoded Date")
|
@@ -53,9 +59,10 @@ describe ModsDisplay::Imprint do
|
|
53
59
|
end
|
54
60
|
it "should handle mixed mods properly" do
|
55
61
|
values = mods_display_imprint(@mixed).fields
|
56
|
-
values.length.should ==
|
62
|
+
values.length.should == 3
|
57
63
|
values.map{|val| val.values}.should include(["A Place : A Publisher"])
|
58
|
-
values.map{|val| val.values}.should include(["The
|
64
|
+
values.map{|val| val.values}.should include(["The Issuance"])
|
65
|
+
values.map{|val| val.values}.should include(["The Capture Date"])
|
59
66
|
end
|
60
67
|
end
|
61
68
|
describe "to_html" do
|
@@ -70,8 +77,9 @@ describe ModsDisplay::Imprint do
|
|
70
77
|
it "should have individual dt/dd pairs for mixed content" do
|
71
78
|
html = mods_display_imprint(@mixed).to_html
|
72
79
|
html.scan(/<dt title='Imprint'>Imprint:<\/dt>/).length.should == 1
|
73
|
-
html.scan(/<dt title='
|
74
|
-
html.scan(/<
|
80
|
+
html.scan(/<dt title='Issuance'>Issuance:<\/dt>/).length.should == 1
|
81
|
+
html.scan(/<dt title='Date captured'>Date captured:<\/dt>/).length.should == 1
|
82
|
+
html.scan(/<dd>/).length.should == 3
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
data/spec/fields/title_spec.rb
CHANGED
@@ -7,7 +7,8 @@ end
|
|
7
7
|
describe ModsDisplay::Title do
|
8
8
|
before(:all) do
|
9
9
|
@title = Stanford::Mods::Record.new.from_str("<mods><titleInfo><title>Title</title></titleInfo></mods>", false).title_info
|
10
|
-
@title_parts = Stanford::Mods::Record.new.from_str("<mods><titleInfo><nonSort>The</nonSort><title>Title</title><subTitle>For</subTitle><partName>Something</partName><partNumber>62</partNumber></titleInfo></mods>", false).title_info
|
10
|
+
@title_parts = Stanford::Mods::Record.new.from_str("<mods><titleInfo><nonSort>The</nonSort><title>Title</title><subTitle>For</subTitle><partName>Something</partName><partNumber>Part 62</partNumber></titleInfo></mods>", false).title_info
|
11
|
+
@reverse_title_parts = Stanford::Mods::Record.new.from_str("<mods><titleInfo><nonSort>The</nonSort><title>Title</title><subTitle>For</subTitle><partNumber>Part 62</partNumber><partName>Something</partName></titleInfo></mods>", false).title_info
|
11
12
|
@display_label = Stanford::Mods::Record.new.from_str("<mods><titleInfo displayLabel='MyTitle'><title>Title</title></titleInfo></mods>", false).title_info
|
12
13
|
@display_form = Stanford::Mods::Record.new.from_str("<mods><titleInfo><title>Title</title><displayForm>The Title of This Item</displayForm></titleInfo></mods>", false).title_info
|
13
14
|
@alt_title = Stanford::Mods::Record.new.from_str("<mods><titleInfo type='alternative'><title>Title</title></titleInfo></mods>", false).title_info
|
@@ -34,7 +35,10 @@ describe ModsDisplay::Title do
|
|
34
35
|
end
|
35
36
|
describe "text" do
|
36
37
|
it "should construct all the elements in titleInfo" do
|
37
|
-
mods_display_title(@title_parts).fields.first.values.should include "The Title : For. Something
|
38
|
+
mods_display_title(@title_parts).fields.first.values.should include "The Title : For. Something. Part 62"
|
39
|
+
end
|
40
|
+
it "should use the correct delimiter in the case that a partNumber comes before a partName" do
|
41
|
+
mods_display_title(@reverse_title_parts).fields.first.values.should include "The Title : For. Part 62, Something"
|
38
42
|
end
|
39
43
|
it "should use the displayForm when available" do
|
40
44
|
mods_display_title(@display_form).fields.first.values.should include "The Title of This Item"
|
@@ -1,5 +1,18 @@
|
|
1
1
|
module ImprintFixtures
|
2
2
|
def imprint_mods
|
3
|
+
<<-MODS
|
4
|
+
<mods>
|
5
|
+
<originInfo>
|
6
|
+
<edition>An edition</edition>
|
7
|
+
<place>A Place</place>
|
8
|
+
<publisher>A Publisher</publisher>
|
9
|
+
<dateIssued>An Issue Date</dateIssued>
|
10
|
+
<dateOther>Another Date</dateOther>
|
11
|
+
</originInfo>
|
12
|
+
</mods>
|
13
|
+
MODS
|
14
|
+
end
|
15
|
+
def no_edition_mods
|
3
16
|
<<-MODS
|
4
17
|
<mods>
|
5
18
|
<originInfo>
|
@@ -20,7 +33,7 @@ module ImprintFixtures
|
|
20
33
|
<dateValid>A Valid Date</dateValid>
|
21
34
|
</originInfo>
|
22
35
|
<originInfo>
|
23
|
-
<
|
36
|
+
<issuance>The Issuance</issuance>
|
24
37
|
</originInfo>
|
25
38
|
</mods>
|
26
39
|
MODS
|
@@ -50,7 +63,8 @@ module ImprintFixtures
|
|
50
63
|
<originInfo>
|
51
64
|
<place>A Place</place>
|
52
65
|
<publisher>A Publisher</publisher>
|
53
|
-
<
|
66
|
+
<issuance>The Issuance</issuance>
|
67
|
+
<dateCaptured>The Capture Date</dateCaptured>
|
54
68
|
</originInfo>
|
55
69
|
</mods>
|
56
70
|
MODS
|
@@ -75,13 +89,14 @@ module ImprintFixtures
|
|
75
89
|
<<-MODS
|
76
90
|
<mods>
|
77
91
|
<originInfo displayLabel="TheLabel">
|
92
|
+
<edition>The edition</edition>
|
78
93
|
<place>A Place</place>
|
79
94
|
<publisher>A Publisher</publisher>
|
80
95
|
</originInfo>
|
81
|
-
<originInfo displayLabel="
|
96
|
+
<originInfo displayLabel="IssuanceLabel">
|
82
97
|
<place>A Place</place>
|
83
98
|
<publisher>A Publisher</publisher>
|
84
|
-
<
|
99
|
+
<issuance>The Edition</issuance>
|
85
100
|
</originInfo>
|
86
101
|
</mods>
|
87
102
|
MODS
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mods_display
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stanford-mods
|
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: '0'
|
152
152
|
segments:
|
153
153
|
- 0
|
154
|
-
hash: -
|
154
|
+
hash: -1792709584890457737
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
none: false
|
157
157
|
requirements:
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
segments:
|
162
162
|
- 0
|
163
|
-
hash: -
|
163
|
+
hash: -1792709584890457737
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
166
|
rubygems_version: 1.8.25
|