mods_display 0.2.0 → 0.2.1
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/lib/mods_display/fields/subject.rb +38 -4
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +1 -1
- data/spec/fields/subject_spec.rb +17 -1
- data/spec/fixtures/subjects_fixtures.rb +23 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6fbeb6e358da70acf9959feba56cea0b735f47b
|
4
|
+
data.tar.gz: b4236dd3026d7d7cb3c5a93217e64491c6fd6528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e555e1dd3269a8ad2fea3aa1426e042b417992cba343369dc4c8ba3a27c66c18d2ab637df006e9a9f69550a31d44237ed7535994093da65bcf3f916460dbb2
|
7
|
+
data.tar.gz: 91caac5689b774665d1e027b20cb4dbdcded4f62950799c46c77a062781968588e36a8313049695cb9b6baaf54494057d65cbf1289de2191d02ec156093cc0b7
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class ModsDisplay::Subject < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
4
|
+
return_fields = []
|
5
5
|
@values.each do |value|
|
6
|
+
return_values = []
|
7
|
+
label = displayLabel(value) || "Subject"
|
6
8
|
return_text = []
|
7
9
|
selected_subjects(value).each do |child|
|
8
10
|
if self.respond_to?(:"process_#{child.name}")
|
@@ -18,9 +20,11 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
18
20
|
unless return_text.empty?
|
19
21
|
return_values << return_text.flatten
|
20
22
|
end
|
23
|
+
unless return_values.empty?
|
24
|
+
return_fields << ModsDisplay::Values.new(:label => label, :values => return_values)
|
25
|
+
end
|
21
26
|
end
|
22
|
-
|
23
|
-
[ModsDisplay::Values.new(:label => "Subject", :values => return_values)]
|
27
|
+
collapse_subjects return_fields
|
24
28
|
end
|
25
29
|
|
26
30
|
# Would really like to clean this up, but it works and is tested for now.
|
@@ -99,5 +103,35 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
99
103
|
def omit_elements
|
100
104
|
[:cartographics, :geographicCode, :text]
|
101
105
|
end
|
102
|
-
|
106
|
+
|
107
|
+
# Providing subject specific collapsing method so we can
|
108
|
+
# collapse the labels w/o flattening all the subject fields.
|
109
|
+
def collapse_subjects(display_fields)
|
110
|
+
return_values = []
|
111
|
+
current_label = nil
|
112
|
+
prev_label = nil
|
113
|
+
buffer = []
|
114
|
+
display_fields.each_with_index do |field, index|
|
115
|
+
current_label = field.label
|
116
|
+
current_values = field.values
|
117
|
+
if display_fields.length == 1
|
118
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
|
119
|
+
elsif index == (display_fields.length-1)
|
120
|
+
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
121
|
+
if current_label != prev_label
|
122
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => [buffer.flatten(1)])
|
123
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
|
124
|
+
else
|
125
|
+
buffer.concat(current_values)
|
126
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten(0))
|
127
|
+
end
|
128
|
+
elsif prev_label and (current_label != prev_label)
|
129
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten(0))
|
130
|
+
buffer = []
|
131
|
+
end
|
132
|
+
buffer.concat(current_values)
|
133
|
+
prev_label = current_label
|
134
|
+
end
|
135
|
+
return_values
|
136
|
+
end
|
103
137
|
end
|
data/lib/mods_display/version.rb
CHANGED
data/mods_display.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["jessie.keck@gmail.com"]
|
11
11
|
gem.description = %q{MODS Display is a gem to centralize the display logic of MODS medadata.}
|
12
12
|
gem.summary = %q{The MODS Display gem allows implementers to configure a customized display of MODS metadata. This display implements the specifications defined at Stanford for how to display MODS.}
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "https://github.com/sul-dlss/mods_display"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/spec/fields/subject_spec.rb
CHANGED
@@ -25,8 +25,8 @@ describe ModsDisplay::Subject do
|
|
25
25
|
@geo_subject = Stanford::Mods::Record.new.from_str(hierarchical_geo_subjects, false).subject
|
26
26
|
@name_subject = Stanford::Mods::Record.new.from_str(name_subjects, false).subject
|
27
27
|
@complex_subject = Stanford::Mods::Record.new.from_str(complex_subjects, false).subject
|
28
|
+
@display_label = Stanford::Mods::Record.new.from_str(display_label_subjects, false).subject
|
28
29
|
end
|
29
|
-
|
30
30
|
describe "fields" do
|
31
31
|
it "should split individual child elments of subject into separate parts" do
|
32
32
|
fields = mods_display_subject(@subject).fields
|
@@ -43,6 +43,16 @@ describe ModsDisplay::Subject do
|
|
43
43
|
fields.length.should == 1
|
44
44
|
fields.first.values.should == [["United States", "California", "Stanford"]]
|
45
45
|
end
|
46
|
+
it "should handle display labels properly" do
|
47
|
+
fields = mods_display_subject(@display_label).fields
|
48
|
+
fields.length.should == 3
|
49
|
+
fields.first.label.should == "Subject"
|
50
|
+
fields.first.values.should == [["A Subject", "Another Subject"], ["B Subject", "Another B Subject"]]
|
51
|
+
fields[1].label.should == "Subject Heading"
|
52
|
+
fields[1].values.should == [["Jazz", "Japan", "History and criticism"]]
|
53
|
+
fields.last.label.should == "Subject"
|
54
|
+
fields.last.values.should == [["Bay Area", "Stanford"]]
|
55
|
+
end
|
46
56
|
it "should handle blank subjects properly" do
|
47
57
|
mods_display_subject(@blank_subject).fields.should == []
|
48
58
|
end
|
@@ -88,6 +98,12 @@ describe ModsDisplay::Subject do
|
|
88
98
|
html.scan(/<br\/>/).length.should == 1
|
89
99
|
html.scan(/ > /).length.should == 3
|
90
100
|
end
|
101
|
+
it "should handle complex display labels" do
|
102
|
+
html = mods_display_subject(@display_label).to_html
|
103
|
+
html.scan(/<dt title='Subject'>Subject:<\/dt>/).length.should eq 2
|
104
|
+
html.scan(/<dt title='Subject Heading'>Subject Heading:<\/dt>/).length.should eq 1
|
105
|
+
html.scan(/<dd>/).length.should == 3
|
106
|
+
end
|
91
107
|
end
|
92
108
|
|
93
109
|
end
|
@@ -76,5 +76,27 @@ module SubjectsFixtures
|
|
76
76
|
</mods>
|
77
77
|
XML
|
78
78
|
end
|
79
|
-
|
79
|
+
def display_label_subjects
|
80
|
+
<<-XML
|
81
|
+
<mods>
|
82
|
+
<subject>
|
83
|
+
<topic>A Subject</topic>
|
84
|
+
<geographical>Another Subject</geographical>
|
85
|
+
</subject>
|
86
|
+
<subject>
|
87
|
+
<topic>B Subject</topic>
|
88
|
+
<geographical>Another B Subject</geographical>
|
89
|
+
</subject>
|
90
|
+
<subject displayLabel="Subject Heading">
|
91
|
+
<topic>Jazz</topic>
|
92
|
+
<geographical>Japan</geographical>
|
93
|
+
<topic>History and criticism</topic>
|
94
|
+
</subject>
|
95
|
+
<subject>
|
96
|
+
<topic>Bay Area</topic>
|
97
|
+
<geographical>Stanford</geographical>
|
98
|
+
</subject>
|
99
|
+
</mods>
|
100
|
+
XML
|
101
|
+
end
|
80
102
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jessie Keck
|
@@ -137,7 +137,7 @@ files:
|
|
137
137
|
- spec/integration/html_spec.rb
|
138
138
|
- spec/integration/installation_spec.rb
|
139
139
|
- spec/spec_helper.rb
|
140
|
-
homepage:
|
140
|
+
homepage: https://github.com/sul-dlss/mods_display
|
141
141
|
licenses: []
|
142
142
|
metadata: {}
|
143
143
|
post_install_message:
|