mods_display 0.0.1.beta3 → 0.0.1.beta4
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.
- data/lib/mods_display/fields/field.rb +35 -7
- data/lib/mods_display/fields/location.rb +7 -13
- data/lib/mods_display/fields/name.rb +6 -6
- data/lib/mods_display/fields/related_item.rb +25 -3
- data/lib/mods_display/fields/related_location.rb +6 -3
- data/lib/mods_display/fields/subject.rb +2 -2
- data/lib/mods_display/html.rb +8 -1
- data/lib/mods_display/version.rb +1 -1
- data/spec/fields/name_spec.rb +4 -0
- data/spec/fields/related_item_spec.rb +13 -0
- data/spec/fields/related_location_spec.rb +4 -0
- data/spec/fields/subject_spec.rb +4 -0
- data/spec/fixtures/subjects_fixtures.rb +10 -0
- metadata +3 -3
@@ -6,8 +6,34 @@ class ModsDisplay::Field
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def fields
|
9
|
+
return_values = []
|
10
|
+
current_label = nil
|
11
|
+
prev_label = nil
|
12
|
+
buffer = []
|
13
|
+
@value.each_with_index do |val, index|
|
14
|
+
current_label = displayLabel(val)
|
15
|
+
current_text = (text || val.text).strip
|
16
|
+
if @value.length == 1
|
17
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
|
18
|
+
elsif index == (@value.length-1)
|
19
|
+
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
20
|
+
if current_label != prev_label
|
21
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
22
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
|
23
|
+
else
|
24
|
+
buffer << current_text
|
25
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
26
|
+
end
|
27
|
+
elsif prev_label and (current_label != prev_label)
|
28
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
29
|
+
buffer = []
|
30
|
+
end
|
31
|
+
buffer << current_text
|
32
|
+
prev_label = current_label
|
33
|
+
end
|
34
|
+
return_values
|
9
35
|
@value.map do |val|
|
10
|
-
ModsDisplay::Values.new(:label => displayLabel(val), :values => [text || val.text].flatten)
|
36
|
+
ModsDisplay::Values.new(:label => displayLabel(val) || label, :values => [text || val.text].flatten)
|
11
37
|
end
|
12
38
|
end
|
13
39
|
|
@@ -27,12 +53,14 @@ class ModsDisplay::Field
|
|
27
53
|
return nil if fields.empty?
|
28
54
|
output = ""
|
29
55
|
fields.each do |field|
|
30
|
-
|
31
|
-
|
32
|
-
output <<
|
33
|
-
|
34
|
-
|
35
|
-
|
56
|
+
if field.values.any?{|f| !f.empty? }
|
57
|
+
output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
|
58
|
+
output << "<dd#{value_class}>"
|
59
|
+
output << field.values.map do |val|
|
60
|
+
@config.link ? link_to_value(val.to_s) : val.to_s
|
61
|
+
end.join(@config.delimiter)
|
62
|
+
output << "</dd>"
|
63
|
+
end
|
36
64
|
end
|
37
65
|
output
|
38
66
|
end
|
@@ -1,23 +1,17 @@
|
|
1
1
|
class ModsDisplay::Location < ModsDisplay::Field
|
2
|
-
|
3
|
-
def fields
|
4
|
-
return_values = []
|
5
|
-
@value.each do |val|
|
6
|
-
return_values << ModsDisplay::Values.new(:label => label || location_label(val), :values => [val.text])
|
7
|
-
end
|
8
|
-
return_values
|
9
|
-
end
|
10
|
-
|
2
|
+
|
11
3
|
private
|
12
|
-
|
4
|
+
|
5
|
+
def displayLabel(element)
|
6
|
+
super(element) || location_label(element) || "Location"
|
7
|
+
end
|
8
|
+
|
13
9
|
def location_label(element)
|
14
10
|
if element.attributes["type"].respond_to?(:value) && location_labels.has_key?(element.attributes["type"].value)
|
15
11
|
location_labels[element.attributes["type"].value]
|
16
|
-
else
|
17
|
-
"Location"
|
18
12
|
end
|
19
13
|
end
|
20
|
-
|
14
|
+
|
21
15
|
def location_labels
|
22
16
|
{"repository" => "Repository"}
|
23
17
|
end
|
@@ -21,21 +21,21 @@ class ModsDisplay::Name < ModsDisplay::Field
|
|
21
21
|
name_parts = val.namePart.map do |name_part|
|
22
22
|
name_part.text
|
23
23
|
end.join(", ")
|
24
|
-
people << ModsDisplay::Name::Person.new(:name => name_parts, :role => role)
|
24
|
+
people << ModsDisplay::Name::Person.new(:name => name_parts, :role => role) unless name_parts.empty?
|
25
25
|
end
|
26
26
|
if @value.length == 1
|
27
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten)
|
27
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten) unless people.empty?
|
28
28
|
elsif index == (@value.length-1)
|
29
29
|
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
30
30
|
if current_label != prev_label
|
31
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
32
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten)
|
31
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten) unless buffer.flatten.empty?
|
32
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten) unless people.empty?
|
33
33
|
else
|
34
34
|
buffer << people
|
35
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
35
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten) unless buffer.flatten.empty?
|
36
36
|
end
|
37
37
|
elsif prev_label and (current_label != prev_label)
|
38
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
38
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten) unless buffer.flatten.empty?
|
39
39
|
buffer = []
|
40
40
|
end
|
41
41
|
buffer << people
|
@@ -2,7 +2,11 @@ class ModsDisplay::RelatedItem < ModsDisplay::Field
|
|
2
2
|
|
3
3
|
def fields
|
4
4
|
return_values = []
|
5
|
-
|
5
|
+
current_label = nil
|
6
|
+
prev_label = nil
|
7
|
+
buffer = []
|
8
|
+
@value.each_with_index do |val, index|
|
9
|
+
current_label = (displayLabel(val) || "Related Item")
|
6
10
|
unless (val.typeOfResource.length > 0 and
|
7
11
|
val.typeOfResource.attributes.length > 0 and
|
8
12
|
val.typeOfResource.attributes.first.has_key?("collection") and
|
@@ -13,8 +17,26 @@ class ModsDisplay::RelatedItem < ModsDisplay::Field
|
|
13
17
|
location = nil
|
14
18
|
location = val.location.url.text if (val.location.length > 0 and
|
15
19
|
val.location.url.length > 0)
|
16
|
-
return_text = "<a href='#{location}'>#{title}</a>" if location
|
17
|
-
|
20
|
+
return_text = "<a href='#{location}'>#{title}</a>" if location and !title.empty?
|
21
|
+
end
|
22
|
+
unless return_text.empty?
|
23
|
+
if @value.length == 1
|
24
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
|
25
|
+
elsif index == (@value.length-1)
|
26
|
+
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
27
|
+
if current_label != prev_label
|
28
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
29
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
|
30
|
+
else
|
31
|
+
buffer << return_text
|
32
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
33
|
+
end
|
34
|
+
elsif prev_label and (current_label != prev_label)
|
35
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
36
|
+
buffer = []
|
37
|
+
end
|
38
|
+
buffer << return_text
|
39
|
+
prev_label = current_label
|
18
40
|
end
|
19
41
|
end
|
20
42
|
end
|
@@ -1,14 +1,17 @@
|
|
1
1
|
class ModsDisplay::RelatedLocation < ModsDisplay::Field
|
2
2
|
|
3
|
-
|
4
3
|
def fields
|
5
4
|
return_values = []
|
6
5
|
@value.each do |val|
|
7
|
-
if val.location.length > 0
|
8
|
-
return_values << ModsDisplay::Values.new(:label => displayLabel(val)
|
6
|
+
if val.location.length > 0 and val.titleInfo.length < 1
|
7
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(val), :values => [val.location.text.strip])
|
9
8
|
end
|
10
9
|
end
|
11
10
|
return_values
|
12
11
|
end
|
13
12
|
|
13
|
+
def displayLabel(element)
|
14
|
+
super(element) || "Location"
|
15
|
+
end
|
16
|
+
|
14
17
|
end
|
@@ -6,12 +6,12 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
6
6
|
return_text = []
|
7
7
|
selected_subjects(val).each do |child|
|
8
8
|
if self.respond_to?(:"process_#{child.name}")
|
9
|
-
return_text << self.send(:"process_#{child.name}", child)
|
9
|
+
return_text << self.send(:"process_#{child.name}", child) unless self.send(:"process_#{child.name}", child).to_s.empty?
|
10
10
|
else
|
11
11
|
if child.text.include?("--")
|
12
12
|
return_text << child.text.split("--").map{|t| t.strip }
|
13
13
|
else
|
14
|
-
return_text << child.text
|
14
|
+
return_text << child.text unless child.text.empty?
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/mods_display/html.rb
CHANGED
@@ -55,7 +55,7 @@ class ModsDisplay::HTML
|
|
55
55
|
|
56
56
|
def field_config(field_key)
|
57
57
|
begin
|
58
|
-
@config.send(field_key)
|
58
|
+
@config.send(field_key_translation[field_key] || field_key)
|
59
59
|
rescue
|
60
60
|
ModsDisplay::Configuration::Base.new
|
61
61
|
end
|
@@ -84,4 +84,11 @@ class ModsDisplay::HTML
|
|
84
84
|
:identifier => :identifier,
|
85
85
|
:location => :location}
|
86
86
|
end
|
87
|
+
|
88
|
+
def field_key_translation
|
89
|
+
{:relatedLocation => :related_location,
|
90
|
+
:relatedItem => :related_item
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
87
94
|
end
|
data/lib/mods_display/version.rb
CHANGED
data/spec/fields/name_spec.rb
CHANGED
@@ -16,6 +16,7 @@ end
|
|
16
16
|
describe ModsDisplay::Language do
|
17
17
|
before(:all) do
|
18
18
|
@name = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name></mods>", false).plain_name
|
19
|
+
@blank_name = Stanford::Mods::Record.new.from_str("<mods><name><namePart/><role><roleTerm></roleTerm></role></name></mods>", false).plain_name
|
19
20
|
@conf_name = Stanford::Mods::Record.new.from_str("<mods><name type='conference'><namePart>John Doe</namePart></name></mods>", false).plain_name
|
20
21
|
@display_form = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><displayForm>Mr. John Doe</displayForm></name></mods>", false).plain_name
|
21
22
|
@collapse_label = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart></name></mods>", false).plain_name
|
@@ -46,6 +47,9 @@ describe ModsDisplay::Language do
|
|
46
47
|
fields.first.values.first.should be_a(ModsDisplay::Name::Person)
|
47
48
|
fields.first.values.first.role.should == "Depicted"
|
48
49
|
end
|
50
|
+
it "should not add blank names" do
|
51
|
+
mods_display_name(@blank_name).fields.should == []
|
52
|
+
end
|
49
53
|
it "should collapse adjacent matching labels" do
|
50
54
|
fields = mods_display_name(@collapse_label).fields
|
51
55
|
fields.length.should == 1
|
@@ -10,6 +10,8 @@ describe ModsDisplay::RelatedItem do
|
|
10
10
|
@linked_item = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo>A Related Item</titleInfo><location><url>http://library.stanford.edu/</url></location></relatedItem></mods>", false).related_item
|
11
11
|
@collection = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo>This is a Collection</titleInfo><typeOfResource collection='yes' /></relatedItem></mods>", false).related_item
|
12
12
|
@display_label = Stanford::Mods::Record.new.from_str("<mods><relatedItem displayLabel='Special Item'><titleInfo>A Related Item</titleInfo></relatedItem></mods>", false).related_item
|
13
|
+
@blank_item = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo><title></title></titleInfo><location><url></url></location></relatedItem></mods>", false).related_item
|
14
|
+
@multi_items = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo><title>Library</title></titleInfo><location><url>http://library.stanford.edu</url></location></relatedItem><relatedItem><titleInfo><title>SDR</title></titleInfo><location><url>http://purl.stanford.edu</url></location></relatedItem></mods>", false).related_item
|
13
15
|
end
|
14
16
|
describe "label" do
|
15
17
|
it "should default to Related Item" do
|
@@ -33,5 +35,16 @@ describe ModsDisplay::RelatedItem do
|
|
33
35
|
it "should not return any fields if the described related item is a collection" do
|
34
36
|
mods_display_item(@collection).fields.should == []
|
35
37
|
end
|
38
|
+
it "should not return empty links when there is no title or link" do
|
39
|
+
mods_display_item(@blank_item).fields.should == []
|
40
|
+
end
|
41
|
+
it "should collapse labels down into the same record" do
|
42
|
+
fields = mods_display_item(@multi_items).fields
|
43
|
+
fields.length.should == 1
|
44
|
+
fields.first.label.should == "Related Item"
|
45
|
+
fields.first.values.length.should == 2
|
46
|
+
fields.first.values.first.should =~ /<a href=.*>Library<\/a>/ or
|
47
|
+
fields.first.values.last.should =~ /<a href=.*>SDR<\/a>/
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
@@ -8,6 +8,7 @@ describe ModsDisplay::RelatedLocation do
|
|
8
8
|
before(:all) do
|
9
9
|
@location = Stanford::Mods::Record.new.from_str("<mods><relatedItem><location>The Location</location></relatedItem></mods>", false).related_item
|
10
10
|
@non_location = Stanford::Mods::Record.new.from_str("<mods><relatedItem><title>No Location</title></relatedItem></mods>", false).related_item
|
11
|
+
@related_item = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo>Do not display as Related Location</titleInfo><location>The Location</location></relatedItem></mods>", false).related_item
|
11
12
|
@display_label = Stanford::Mods::Record.new.from_str("<mods><relatedItem displayLabel='Special Location'><location>The Location</location></relatedItem></mods>", false).related_item
|
12
13
|
end
|
13
14
|
describe "label" do
|
@@ -27,5 +28,8 @@ describe ModsDisplay::RelatedLocation do
|
|
27
28
|
it "should not return any fields if there is no location" do
|
28
29
|
mods_display_related_location(@non_location).fields.should == []
|
29
30
|
end
|
31
|
+
it "should not return locations that are already related items" do
|
32
|
+
mods_display_related_location(@related_item).fields.should == []
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
data/spec/fields/subject_spec.rb
CHANGED
@@ -20,6 +20,7 @@ end
|
|
20
20
|
describe ModsDisplay::Subject do
|
21
21
|
before(:all) do
|
22
22
|
@subject = Stanford::Mods::Record.new.from_str(subjects, false).subject
|
23
|
+
@blank_subject = Stanford::Mods::Record.new.from_str(blank_subject, false).subject
|
23
24
|
@emdash_subject = Stanford::Mods::Record.new.from_str(emdash_subjects, false).subject
|
24
25
|
@geo_subject = Stanford::Mods::Record.new.from_str(hierarchical_geo_subjects, false).subject
|
25
26
|
@name_subject = Stanford::Mods::Record.new.from_str(name_subjects, false).subject
|
@@ -42,6 +43,9 @@ describe ModsDisplay::Subject do
|
|
42
43
|
fields.length.should == 1
|
43
44
|
fields.first.values.should == [["United States", "California", "Stanford"]]
|
44
45
|
end
|
46
|
+
it "should handle blank subjects properly" do
|
47
|
+
mods_display_subject(@blank_subject).fields.should == []
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
describe "name subjects" do
|
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.1.
|
4
|
+
version: 0.0.1.beta4
|
5
5
|
prerelease: 6
|
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-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stanford-mods
|
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
segments:
|
141
141
|
- 0
|
142
|
-
hash: -
|
142
|
+
hash: -2208754655843204973
|
143
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
144
|
none: false
|
145
145
|
requirements:
|