mods_display 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mods_display/fields/cartographics.rb +7 -7
- data/lib/mods_display/fields/collection.rb +9 -9
- data/lib/mods_display/fields/contact.rb +6 -28
- data/lib/mods_display/fields/description.rb +4 -25
- data/lib/mods_display/fields/field.rb +39 -37
- data/lib/mods_display/fields/format.rb +5 -8
- data/lib/mods_display/fields/identifier.rb +7 -28
- data/lib/mods_display/fields/imprint.rb +18 -18
- data/lib/mods_display/fields/language.rb +9 -21
- data/lib/mods_display/fields/name.rb +11 -32
- data/lib/mods_display/fields/note.rb +7 -28
- data/lib/mods_display/fields/related_item.rb +13 -35
- data/lib/mods_display/fields/related_location.rb +5 -6
- data/lib/mods_display/fields/sub_title.rb +1 -1
- data/lib/mods_display/fields/subject.rb +2 -2
- data/lib/mods_display/fields/title.rb +9 -10
- data/lib/mods_display/version.rb +1 -1
- data/spec/fields/imprint_spec.rb +1 -1
- data/spec/fields/language_spec.rb +0 -20
- metadata +4 -4
@@ -1,21 +1,21 @@
|
|
1
1
|
class ModsDisplay::Cartographics < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
return nil if @
|
5
|
-
|
6
|
-
@
|
7
|
-
if
|
8
|
-
|
4
|
+
return nil if @values.nil?
|
5
|
+
return_fields = []
|
6
|
+
@values.each do |value|
|
7
|
+
if value.respond_to?(:cartographics)
|
8
|
+
value.cartographics.each do |field|
|
9
9
|
scale = field.scale.empty? ? "Scale not given" : field.scale.text
|
10
10
|
projection = field.projection.empty? ? nil : field.projection.text
|
11
11
|
coordinates = field.coordinates.empty? ? nil : field.coordinates.text
|
12
12
|
post_scale = [projection, coordinates].compact.length > 0 ? [projection, coordinates].compact.join(" ") : nil
|
13
|
-
|
13
|
+
return_fields << ModsDisplay::Values.new({:label => (displayLabel(field) || label || "Map data"),
|
14
14
|
:values => [[scale, post_scale].compact.join(" ; ")]})
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
collapse_fields(return_fields)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -5,17 +5,17 @@ class ModsDisplay::Collection < ModsDisplay::Field
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def fields
|
8
|
-
|
9
|
-
@
|
10
|
-
if
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
return_fields = []
|
9
|
+
@values.each do |value|
|
10
|
+
if value.respond_to?(:titleInfo) and
|
11
|
+
value.respond_to?(:typeOfResource) and
|
12
|
+
value.typeOfResource.attributes.length > 0 and
|
13
|
+
value.typeOfResource.attributes.first.has_key?("collection") and
|
14
|
+
value.typeOfResource.attributes.first["collection"].value == "yes"
|
15
|
+
return_fields << ModsDisplay::Values.new(:label => label, :values => [value.titleInfo.text.strip])
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
collapse_fields(return_fields)
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
@@ -1,38 +1,16 @@
|
|
1
1
|
class ModsDisplay::Contact < ModsDisplay::Field
|
2
2
|
def fields
|
3
|
-
|
4
|
-
|
5
|
-
prev_label = nil
|
6
|
-
buffer = []
|
7
|
-
contact_fields.each_with_index do |val, index|
|
8
|
-
current_label = (displayLabel(val) || "Contact")
|
9
|
-
if contact_fields.length == 1
|
10
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
11
|
-
elsif index == (contact_fields.length-1)
|
12
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
13
|
-
if current_label != prev_label
|
14
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
15
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
16
|
-
else
|
17
|
-
buffer << val.text
|
18
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
19
|
-
end
|
20
|
-
elsif prev_label and (current_label != prev_label)
|
21
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
22
|
-
buffer = []
|
23
|
-
end
|
24
|
-
buffer << val.text
|
25
|
-
prev_label = current_label
|
3
|
+
return_fields = contact_fields.map do |value|
|
4
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || "Contact", :values => [value.text])
|
26
5
|
end
|
27
|
-
|
6
|
+
collapse_fields(return_fields)
|
28
7
|
end
|
29
8
|
|
30
|
-
|
31
9
|
private
|
32
10
|
def contact_fields
|
33
|
-
@
|
34
|
-
|
35
|
-
|
11
|
+
@values.select do |value|
|
12
|
+
value.attributes["type"].respond_to?(:value) and
|
13
|
+
value.attributes["type"].value.downcase == "contact"
|
36
14
|
end
|
37
15
|
end
|
38
16
|
|
@@ -1,31 +1,10 @@
|
|
1
1
|
class ModsDisplay::Description < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
|
6
|
-
prev_label = nil
|
7
|
-
buffer = []
|
8
|
-
description_fields.each_with_index do |val, index|
|
9
|
-
current_label = description_label(val)
|
10
|
-
if description_fields.length == 1
|
11
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
12
|
-
elsif index == (description_fields.length-1)
|
13
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
14
|
-
if current_label != prev_label
|
15
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
16
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
17
|
-
else
|
18
|
-
buffer << val.text
|
19
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
20
|
-
end
|
21
|
-
elsif prev_label and (current_label != prev_label)
|
22
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
23
|
-
buffer = []
|
24
|
-
end
|
25
|
-
buffer << val.text
|
26
|
-
prev_label = current_label
|
4
|
+
return_fields = description_fields.map do |value|
|
5
|
+
ModsDisplay::Values.new(:label => description_label(value), :values => [value.text])
|
27
6
|
end
|
28
|
-
|
7
|
+
collapse_fields(return_fields)
|
29
8
|
end
|
30
9
|
|
31
10
|
def description_label(element)
|
@@ -35,7 +14,7 @@ class ModsDisplay::Description < ModsDisplay::Field
|
|
35
14
|
private
|
36
15
|
|
37
16
|
def description_fields
|
38
|
-
@
|
17
|
+
@values.children.select do |child|
|
39
18
|
labels.keys.include?(child.name.to_sym)
|
40
19
|
end
|
41
20
|
end
|
@@ -1,50 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
class ModsDisplay::Field
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(values, config, klass)
|
4
|
+
@values = values
|
5
5
|
@config = config
|
6
6
|
@klass = klass
|
7
7
|
end
|
8
8
|
|
9
9
|
def fields
|
10
|
-
|
11
|
-
|
12
|
-
prev_label = nil
|
13
|
-
buffer = []
|
14
|
-
@value.each_with_index do |val, index|
|
15
|
-
current_label = displayLabel(val)
|
16
|
-
current_text = (text || val.text).strip
|
17
|
-
if @value.length == 1
|
18
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
|
19
|
-
elsif index == (@value.length-1)
|
20
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
21
|
-
if current_label != prev_label
|
22
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
23
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
|
24
|
-
else
|
25
|
-
buffer << current_text
|
26
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
27
|
-
end
|
28
|
-
elsif prev_label and (current_label != prev_label)
|
29
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
30
|
-
buffer = []
|
31
|
-
end
|
32
|
-
buffer << current_text
|
33
|
-
prev_label = current_label
|
10
|
+
return_fields = @values.map do |value|
|
11
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || label, :values => [displayForm(@values) || value.text].flatten)
|
34
12
|
end
|
35
|
-
|
13
|
+
collapse_fields(return_fields)
|
36
14
|
end
|
37
15
|
|
38
16
|
def label
|
39
|
-
return nil if @
|
40
|
-
displayLabel(@
|
41
|
-
end
|
42
|
-
|
43
|
-
def text
|
44
|
-
return nil if @value.nil?
|
45
|
-
if displayForm(@value)
|
46
|
-
displayForm(@value).text
|
47
|
-
end
|
17
|
+
return nil if @values.nil?
|
18
|
+
displayLabel(@values.first)
|
48
19
|
end
|
49
20
|
|
50
21
|
def to_html
|
@@ -78,7 +49,9 @@ class ModsDisplay::Field
|
|
78
49
|
end
|
79
50
|
|
80
51
|
def displayForm(element)
|
81
|
-
element
|
52
|
+
return element unless element # basically return nil
|
53
|
+
display = element.children.find{|c| c.name == "displayForm"}
|
54
|
+
return display.text if display
|
82
55
|
end
|
83
56
|
|
84
57
|
def displayLabel(element)
|
@@ -131,4 +104,33 @@ class ModsDisplay::Field
|
|
131
104
|
val
|
132
105
|
end
|
133
106
|
|
107
|
+
def collapse_fields(display_fields)
|
108
|
+
return_values = []
|
109
|
+
current_label = nil
|
110
|
+
prev_label = nil
|
111
|
+
buffer = []
|
112
|
+
display_fields.each_with_index do |field, index|
|
113
|
+
current_label = field.label
|
114
|
+
current_values = field.values
|
115
|
+
if display_fields.length == 1
|
116
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
|
117
|
+
elsif index == (display_fields.length-1)
|
118
|
+
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
119
|
+
if current_label != prev_label
|
120
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
121
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
|
122
|
+
else
|
123
|
+
buffer.concat(current_values)
|
124
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
125
|
+
end
|
126
|
+
elsif prev_label and (current_label != prev_label)
|
127
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
128
|
+
buffer = []
|
129
|
+
end
|
130
|
+
buffer.concat(current_values)
|
131
|
+
prev_label = current_label
|
132
|
+
end
|
133
|
+
return_values
|
134
|
+
end
|
135
|
+
|
134
136
|
end
|
@@ -1,14 +1,11 @@
|
|
1
1
|
class ModsDisplay::Format < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
return [] if
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def text
|
11
|
-
return super unless super.nil?
|
4
|
+
return [] if @values.text.strip.empty?
|
5
|
+
return_fields = @values.map do |value|
|
6
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || "Format", :values => [displayForm(value) || value.text])
|
7
|
+
end
|
8
|
+
collapse_fields(return_fields)
|
12
9
|
end
|
13
10
|
|
14
11
|
def to_html
|
@@ -1,42 +1,21 @@
|
|
1
1
|
class ModsDisplay::Identifier < ModsDisplay::Field
|
2
|
-
|
2
|
+
|
3
3
|
def fields
|
4
|
-
|
5
|
-
|
6
|
-
prev_label = nil
|
7
|
-
buffer = []
|
8
|
-
@value.each_with_index do |val, index|
|
9
|
-
current_label = (displayLabel(val) || identifier_label(val))
|
10
|
-
if @value.length == 1
|
11
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
12
|
-
elsif index == (@value.length-1)
|
13
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
14
|
-
if current_label != prev_label
|
15
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
16
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
17
|
-
else
|
18
|
-
buffer << val.text
|
19
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
20
|
-
end
|
21
|
-
elsif prev_label and (current_label != prev_label)
|
22
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
23
|
-
buffer = []
|
24
|
-
end
|
25
|
-
buffer << val.text
|
26
|
-
prev_label = current_label
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || identifier_label(value), :values => [value.text])
|
27
6
|
end
|
28
|
-
|
7
|
+
collapse_fields(return_fields)
|
29
8
|
end
|
30
|
-
|
9
|
+
|
31
10
|
private
|
32
|
-
|
11
|
+
|
33
12
|
def identifier_label(element)
|
34
13
|
if element.attributes["type"].respond_to?(:value)
|
35
14
|
return identifier_labels[element.attributes["type"].value] || element.attributes["type"].value
|
36
15
|
end
|
37
16
|
"Identifier"
|
38
17
|
end
|
39
|
-
|
18
|
+
|
40
19
|
def identifier_labels
|
41
20
|
{"local" => "Identifier",
|
42
21
|
"isbn" => "ISBN",
|
@@ -1,27 +1,27 @@
|
|
1
1
|
class ModsDisplay::Imprint < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
@
|
6
|
-
if imprint_display_form(
|
7
|
-
|
4
|
+
return_fields = []
|
5
|
+
@values.each do |value|
|
6
|
+
if imprint_display_form(value)
|
7
|
+
return_fields << imprint_display_form(value)
|
8
8
|
else
|
9
9
|
edition = nil
|
10
10
|
place = nil
|
11
11
|
publisher = nil
|
12
12
|
placePub = nil
|
13
|
-
edition =
|
13
|
+
edition = value.edition.map do |e|
|
14
14
|
e.text unless e.text.strip.empty?
|
15
15
|
end.compact.join(" ").strip
|
16
|
-
place =
|
16
|
+
place = value.place.map do |p|
|
17
17
|
p.text unless p.text.strip.empty?
|
18
|
-
end.compact.join(" : ").strip unless
|
19
|
-
publisher =
|
18
|
+
end.compact.join(" : ").strip unless value.place.text.strip.empty?
|
19
|
+
publisher = value.publisher.map do |p|
|
20
20
|
p.text unless p.text.strip.empty?
|
21
|
-
end.compact.join(" : ").strip unless
|
21
|
+
end.compact.join(" : ").strip unless value.publisher.text.strip.empty?
|
22
22
|
parts = ["dateIssued", "dateOther"].map do |date_field_name|
|
23
|
-
if
|
24
|
-
parse_dates(
|
23
|
+
if value.respond_to?(date_field_name.to_sym)
|
24
|
+
parse_dates(value.send(date_field_name.to_sym))
|
25
25
|
end
|
26
26
|
end.flatten.map do |date|
|
27
27
|
date.strip unless date.strip.empty?
|
@@ -33,19 +33,19 @@ class ModsDisplay::Imprint < ModsDisplay::Field
|
|
33
33
|
editionPlace = [edition, placePub].compact.join(" - ")
|
34
34
|
editionPlace = nil if editionPlace.strip.empty?
|
35
35
|
unless [editionPlace, parts].compact.join(", ").strip.empty?
|
36
|
-
|
36
|
+
return_fields << ModsDisplay::Values.new(:label => displayLabel(value) || "Imprint", :values => [[editionPlace, parts].compact.join(", ")])
|
37
37
|
end
|
38
|
-
if dates(
|
39
|
-
|
38
|
+
if dates(value).length > 0
|
39
|
+
return_fields.concat(dates(value))
|
40
40
|
end
|
41
|
-
if other_pub_info(
|
42
|
-
other_pub_info(
|
43
|
-
|
41
|
+
if other_pub_info(value).length > 0
|
42
|
+
other_pub_info(value).each do |pub_info|
|
43
|
+
return_fields << ModsDisplay::Values.new(:label => displayLabel(value) || pub_info_labels[pub_info.name.to_sym], :values => [pub_info.text.strip])
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
collapse_fields(return_fields)
|
49
49
|
end
|
50
50
|
def dates(element)
|
51
51
|
date_field_keys.map do |date_field|
|
@@ -1,27 +1,15 @@
|
|
1
1
|
class ModsDisplay::Language < ModsDisplay::Field
|
2
|
-
def label
|
3
|
-
return super unless super.nil?
|
4
|
-
"Language"
|
5
|
-
end
|
6
|
-
|
7
2
|
def fields
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
languages << language_codes[term.text]
|
3
|
+
return_fields = @values.map do |value|
|
4
|
+
if value.respond_to?(:languageTerm)
|
5
|
+
value.languageTerm.map do |term|
|
6
|
+
if term.attributes["type"].respond_to?(:value) and term.attributes["type"].value == "code"
|
7
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || displayLabel(term) || "Language", :values => [displayForm(value) || language_codes[term.text]].flatten)
|
8
|
+
end
|
9
|
+
end.flatten.compact
|
16
10
|
end
|
17
|
-
|
18
|
-
|
19
|
-
return_values
|
20
|
-
end
|
21
|
-
|
22
|
-
def text
|
23
|
-
return super unless super.nil?
|
24
|
-
language_codes[@value.text.strip] || @value.text.strip
|
11
|
+
end.flatten.compact
|
12
|
+
collapse_fields(return_fields)
|
25
13
|
end
|
26
14
|
|
27
15
|
private
|
@@ -1,47 +1,26 @@
|
|
1
1
|
class ModsDisplay::Name < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
current_label = nil
|
6
|
-
prev_label = nil
|
7
|
-
buffer = []
|
8
|
-
@value.each_with_index do |val, index|
|
9
|
-
current_label = (displayLabel(val) || name_label(val))
|
10
|
-
people = []
|
4
|
+
return_fields = @values.map do |value|
|
11
5
|
role = nil
|
12
|
-
|
13
|
-
|
6
|
+
person = nil
|
7
|
+
if value.role.length > 0 and value.role.roleTerm.length > 0
|
8
|
+
role = value.role.roleTerm.find do |term|
|
14
9
|
term.attributes["type"].respond_to?(:value) and
|
15
10
|
term.attributes["type"].value == "text"
|
16
11
|
end
|
17
12
|
end
|
18
|
-
if
|
19
|
-
|
13
|
+
if value.displayForm.length > 0
|
14
|
+
person = ModsDisplay::Name::Person.new(:name => value.displayForm.text, :role => role)
|
20
15
|
else
|
21
|
-
name_parts =
|
16
|
+
name_parts = value.namePart.map do |name_part|
|
22
17
|
name_part.text
|
23
18
|
end.join(", ")
|
24
|
-
|
19
|
+
person = ModsDisplay::Name::Person.new(:name => name_parts, :role => role) unless name_parts.empty?
|
25
20
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
30
|
-
if current_label != prev_label
|
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
|
-
else
|
34
|
-
buffer << people
|
35
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten) unless buffer.flatten.empty?
|
36
|
-
end
|
37
|
-
elsif prev_label and (current_label != prev_label)
|
38
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten) unless buffer.flatten.empty?
|
39
|
-
buffer = []
|
40
|
-
end
|
41
|
-
buffer << people
|
42
|
-
prev_label = current_label
|
43
|
-
end
|
44
|
-
return_values
|
21
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || name_label(value), :values => [person]) if person
|
22
|
+
end.compact
|
23
|
+
collapse_fields(return_fields)
|
45
24
|
end
|
46
25
|
|
47
26
|
def to_html
|
@@ -1,41 +1,20 @@
|
|
1
1
|
class ModsDisplay::Note < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
|
6
|
-
prev_label = nil
|
7
|
-
buffer = []
|
8
|
-
note_fields.each_with_index do |val, index|
|
9
|
-
current_label = (displayLabel(val) || note_label(val))
|
10
|
-
if note_fields.length == 1
|
11
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
12
|
-
elsif index == (note_fields.length-1)
|
13
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
14
|
-
if current_label != prev_label
|
15
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
16
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
|
17
|
-
else
|
18
|
-
buffer << val.text
|
19
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
20
|
-
end
|
21
|
-
elsif prev_label and (current_label != prev_label)
|
22
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
23
|
-
buffer = []
|
24
|
-
end
|
25
|
-
buffer << val.text
|
26
|
-
prev_label = current_label
|
4
|
+
return_fields = note_fields.map do |value|
|
5
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || note_label(value), :values => [value.text])
|
27
6
|
end
|
28
|
-
|
7
|
+
collapse_fields(return_fields)
|
29
8
|
end
|
30
9
|
|
31
10
|
|
32
11
|
private
|
33
12
|
|
34
13
|
def note_fields
|
35
|
-
@
|
36
|
-
(!
|
37
|
-
(
|
38
|
-
|
14
|
+
@values.select do |value|
|
15
|
+
(!value.attributes["type"].respond_to?(:value) or
|
16
|
+
(value.attributes["type"].respond_to?(:value) and
|
17
|
+
value.attributes["type"].value.downcase != "contact"))
|
39
18
|
end
|
40
19
|
end
|
41
20
|
|
@@ -1,47 +1,25 @@
|
|
1
1
|
class ModsDisplay::RelatedItem < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
unless (val.typeOfResource.length > 0 and
|
12
|
-
val.typeOfResource.attributes.length > 0 and
|
13
|
-
val.typeOfResource.attributes.first.has_key?("collection") and
|
14
|
-
val.typeOfResource.attributes.first["collection"].value == "yes")
|
15
|
-
if val.titleInfo.length > 0
|
16
|
-
title = val.titleInfo.text.strip
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
unless (value.typeOfResource.length > 0 and
|
6
|
+
value.typeOfResource.attributes.length > 0 and
|
7
|
+
value.typeOfResource.attributes.first.has_key?("collection") and
|
8
|
+
value.typeOfResource.attributes.first["collection"].value == "yes")
|
9
|
+
if value.titleInfo.length > 0
|
10
|
+
title = value.titleInfo.text.strip
|
17
11
|
return_text = title
|
18
12
|
location = nil
|
19
|
-
location =
|
20
|
-
|
13
|
+
location = value.location.url.text if (value.location.length > 0 and
|
14
|
+
value.location.url.length > 0)
|
21
15
|
return_text = "<a href='#{location}'>#{title}</a>" if location and !title.empty?
|
22
|
-
|
23
|
-
|
24
|
-
if @value.length == 1
|
25
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
|
26
|
-
elsif index == (@value.length-1)
|
27
|
-
# need to deal w/ when we have a last element but we have separate labels in the buffer.
|
28
|
-
if current_label != prev_label
|
29
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
30
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
|
31
|
-
else
|
32
|
-
buffer << return_text
|
33
|
-
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
34
|
-
end
|
35
|
-
elsif prev_label and (current_label != prev_label)
|
36
|
-
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
37
|
-
buffer = []
|
16
|
+
unless return_text.empty?
|
17
|
+
ModsDisplay::Values.new(:label => displayLabel(value) || "Related item", :values => [return_text])
|
38
18
|
end
|
39
|
-
buffer << return_text
|
40
|
-
prev_label = current_label
|
41
19
|
end
|
42
20
|
end
|
43
|
-
end
|
44
|
-
|
21
|
+
end.compact
|
22
|
+
collapse_fields(return_fields)
|
45
23
|
end
|
46
24
|
|
47
25
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
class ModsDisplay::RelatedLocation < ModsDisplay::Field
|
2
2
|
|
3
3
|
def fields
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
return_values << ModsDisplay::Values.new(:label => displayLabel(val), :values => [val.location.text.strip])
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
if value.location.length > 0 and value.titleInfo.length < 1
|
6
|
+
ModsDisplay::Values.new(:label => displayLabel(value), :values => [value.location.text.strip])
|
8
7
|
end
|
9
|
-
end
|
10
|
-
|
8
|
+
end.compact
|
9
|
+
collapse_fields(return_fields)
|
11
10
|
end
|
12
11
|
|
13
12
|
def displayLabel(element)
|
@@ -2,9 +2,9 @@ class ModsDisplay::Subject < ModsDisplay::Field
|
|
2
2
|
|
3
3
|
def fields
|
4
4
|
return_values = []
|
5
|
-
@
|
5
|
+
@values.each do |value|
|
6
6
|
return_text = []
|
7
|
-
selected_subjects(
|
7
|
+
selected_subjects(value).each do |child|
|
8
8
|
if self.respond_to?(:"process_#{child.name}")
|
9
9
|
return_text << self.send(:"process_#{child.name}", child) unless self.send(:"process_#{child.name}", child).to_s.empty?
|
10
10
|
else
|
@@ -1,29 +1,28 @@
|
|
1
1
|
class ModsDisplay::Title < ModsDisplay::Field
|
2
2
|
|
3
|
-
|
4
3
|
def fields
|
5
4
|
return_values = []
|
6
|
-
@
|
7
|
-
if displayForm(
|
8
|
-
return_values << ModsDisplay::Values.new(:label => displayLabel(
|
5
|
+
@values.each do |value|
|
6
|
+
if displayForm(value)
|
7
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [displayForm(value)])
|
9
8
|
else
|
10
9
|
nonSort = nil
|
11
10
|
title = nil
|
12
11
|
subTitle = nil
|
13
|
-
nonSort =
|
14
|
-
title =
|
15
|
-
subTitle =
|
12
|
+
nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
|
13
|
+
title = value.title.text.strip unless value.title.text.strip.empty?
|
14
|
+
subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
|
16
15
|
preSubTitle = [nonSort, title].compact.join(" ")
|
17
16
|
preSubTitle = nil if preSubTitle.strip.empty?
|
18
17
|
preParts = [preSubTitle, subTitle].compact.join(" : ")
|
19
18
|
preParts = nil if preParts.strip.empty?
|
20
|
-
parts =
|
19
|
+
parts = value.children.select do |child|
|
21
20
|
["partName", "partNumber"].include?(child.name)
|
22
21
|
end.map do |child|
|
23
22
|
child.text
|
24
|
-
end.compact.join(parts_delimiter(
|
23
|
+
end.compact.join(parts_delimiter(value))
|
25
24
|
parts = nil if parts.strip.empty?
|
26
|
-
return_values << ModsDisplay::Values.new(:label => displayLabel(
|
25
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [[preParts, parts].compact.join(". ")])
|
27
26
|
end
|
28
27
|
end
|
29
28
|
return_values
|
data/lib/mods_display/version.rb
CHANGED
data/spec/fields/imprint_spec.rb
CHANGED
@@ -42,7 +42,7 @@ describe ModsDisplay::Imprint do
|
|
42
42
|
mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint", "Date captured", "Issuance"]
|
43
43
|
end
|
44
44
|
it "should use the displayLabel when available" do
|
45
|
-
mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "IssuanceLabel"
|
45
|
+
mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "IssuanceLabel"]
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -13,14 +13,6 @@ describe ModsDisplay::Language do
|
|
13
13
|
@multi = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm type='code'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
|
14
14
|
@display_form = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm>zzzxxx</languageTerm><displayForm>Klingon</displayForm></language></mods>", false).language
|
15
15
|
end
|
16
|
-
describe "label" do
|
17
|
-
it "should default to Language when no displayLabel is available" do
|
18
|
-
mods_display_language(@language).label.should == "Language"
|
19
|
-
end
|
20
|
-
it "should use the displayLabel attribute when present" do
|
21
|
-
mods_display_language(@display_label).label.should == "Lang"
|
22
|
-
end
|
23
|
-
end
|
24
16
|
describe "fields" do
|
25
17
|
it "should return an array with a label/values object" do
|
26
18
|
values = mods_display_language(@display_label).fields
|
@@ -40,16 +32,4 @@ describe ModsDisplay::Language do
|
|
40
32
|
values.first.values.should == ["German", "English"]
|
41
33
|
end
|
42
34
|
end
|
43
|
-
describe "text" do
|
44
|
-
it "should return the language code translation" do
|
45
|
-
mods_display_language(@language).text.should == "English"
|
46
|
-
end
|
47
|
-
it "should return the code if the languages table does not have a translation" do
|
48
|
-
mods_display_language(@no_lang).text.should == "zzzxxx"
|
49
|
-
end
|
50
|
-
it "should return a displayForm if there is one" do
|
51
|
-
mods_display_language(@display_form).text.should == "Klingon"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
35
|
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.0
|
4
|
+
version: 0.1.0
|
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-08-
|
12
|
+
date: 2013-08-06 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: -3982244066691895178
|
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: -3982244066691895178
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
166
|
rubygems_version: 1.8.25
|