mods_display 0.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +26 -0
- data/README.md +136 -0
- data/Rakefile +5 -0
- data/lib/mods_display.rb +30 -0
- data/lib/mods_display/configuration.rb +73 -0
- data/lib/mods_display/configuration/base.rb +23 -0
- data/lib/mods_display/configuration/subject.rb +11 -0
- data/lib/mods_display/controller_extension.rb +32 -0
- data/lib/mods_display/fields/abstract.rb +32 -0
- data/lib/mods_display/fields/audience.rb +7 -0
- data/lib/mods_display/fields/cartographics.rb +21 -0
- data/lib/mods_display/fields/collection.rb +21 -0
- data/lib/mods_display/fields/contents.rb +7 -0
- data/lib/mods_display/fields/description.rb +30 -0
- data/lib/mods_display/fields/field.rb +89 -0
- data/lib/mods_display/fields/format.rb +34 -0
- data/lib/mods_display/fields/identifier.rb +60 -0
- data/lib/mods_display/fields/imprint.rb +68 -0
- data/lib/mods_display/fields/language.rb +33 -0
- data/lib/mods_display/fields/location.rb +25 -0
- data/lib/mods_display/fields/name.rb +97 -0
- data/lib/mods_display/fields/note.rb +49 -0
- data/lib/mods_display/fields/related_item.rb +24 -0
- data/lib/mods_display/fields/related_location.rb +14 -0
- data/lib/mods_display/fields/subject.rb +103 -0
- data/lib/mods_display/fields/title.rb +49 -0
- data/lib/mods_display/fields/values.rb +11 -0
- data/lib/mods_display/html.rb +87 -0
- data/lib/mods_display/model_extension.rb +20 -0
- data/lib/mods_display/version.rb +3 -0
- data/mods_display.gemspec +24 -0
- data/spec/configuration/base_spec.rb +29 -0
- data/spec/fields/abstract_spec.rb +21 -0
- data/spec/fields/audience_spec.rb +21 -0
- data/spec/fields/cartographics_spec.rb +39 -0
- data/spec/fields/collection_spec.rb +31 -0
- data/spec/fields/contents_spec.rb +21 -0
- data/spec/fields/description_spec.rb +37 -0
- data/spec/fields/format_spec.rb +35 -0
- data/spec/fields/identifier_spec.rb +49 -0
- data/spec/fields/imprint_spec.rb +78 -0
- data/spec/fields/language_spec.rb +55 -0
- data/spec/fields/location_spec.rb +25 -0
- data/spec/fields/name_spec.rb +88 -0
- data/spec/fields/note_spec.rb +53 -0
- data/spec/fields/related_item_spec.rb +37 -0
- data/spec/fields/related_location_spec.rb +31 -0
- data/spec/fields/subject_spec.rb +89 -0
- data/spec/fields/title_spec.rb +47 -0
- data/spec/fixtures/cartographics_fixtures.rb +52 -0
- data/spec/fixtures/imprint_fixtures.rb +89 -0
- data/spec/fixtures/name_fixtures.rb +3 -0
- data/spec/fixtures/subjects_fixtures.rb +70 -0
- data/spec/integration/configuration_spec.rb +37 -0
- data/spec/integration/installation_spec.rb +26 -0
- data/spec/spec_helper.rb +35 -0
- metadata +182 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
class ModsDisplay::Description < ModsDisplay::Field
|
2
|
+
|
3
|
+
def fields
|
4
|
+
description_fields.map do |description|
|
5
|
+
ModsDisplay::Values.new({:label => (label || description_label(description) || labels[description.name.to_sym] || "Physical Description"),
|
6
|
+
:values => [description.text]})
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def description_label(element)
|
11
|
+
element.attributes["displayLabel"].value if element.attributes["displayLabel"].respond_to?(:value)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def description_fields
|
17
|
+
@value.children.select do |child|
|
18
|
+
labels.keys.include?(child.name.to_sym)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def labels
|
23
|
+
{:form => "Form",
|
24
|
+
:extent => "Extent",
|
25
|
+
:digitalOrigin => "Digital Origin",
|
26
|
+
:note => "Note"
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
class ModsDisplay::Field
|
2
|
+
def initialize(value, config, klass)
|
3
|
+
@value = value
|
4
|
+
@config = config
|
5
|
+
@klass = klass
|
6
|
+
end
|
7
|
+
|
8
|
+
def fields
|
9
|
+
@value.map do |val|
|
10
|
+
ModsDisplay::Values.new(:label => displayLabel(val), :values => [text || val.text].flatten)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def label
|
15
|
+
return nil if @value.nil?
|
16
|
+
displayLabel(@value.first)
|
17
|
+
end
|
18
|
+
|
19
|
+
def text
|
20
|
+
return nil if @value.nil?
|
21
|
+
if displayForm(@value)
|
22
|
+
displayForm(@value).text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_html
|
27
|
+
return nil if fields.empty?
|
28
|
+
output = ""
|
29
|
+
fields.each do |field|
|
30
|
+
output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
|
31
|
+
output << "<dd#{value_class}>"
|
32
|
+
output << field.values.map do |val|
|
33
|
+
@config.link ? link_to_value(val.to_s) : val.to_s
|
34
|
+
end.join(@config.delimiter)
|
35
|
+
output << "</dd>"
|
36
|
+
end
|
37
|
+
output
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def label_class
|
43
|
+
" class='#{@config.label_class}'" unless @config.label_class == ""
|
44
|
+
end
|
45
|
+
|
46
|
+
def value_class
|
47
|
+
" class='#{@config.value_class}'" unless @config.value_class == ""
|
48
|
+
end
|
49
|
+
|
50
|
+
def link_to_value(link_text, link_href=nil)
|
51
|
+
"<a href='#{@klass.send(@config.link[0], replace_tokens(@config.link[1], link_href || link_text))}'>#{link_text}</a>"
|
52
|
+
end
|
53
|
+
|
54
|
+
def displayForm(element)
|
55
|
+
element.children.find{|c| c.name == "displayForm"}
|
56
|
+
end
|
57
|
+
|
58
|
+
def displayLabel(element)
|
59
|
+
if (element.respond_to?(:attributes) and
|
60
|
+
element.attributes["displayLabel"].respond_to?(:value))
|
61
|
+
element.attributes["displayLabel"].value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def replace_tokens(object, value)
|
66
|
+
object = object.dup
|
67
|
+
if object.is_a?(Hash)
|
68
|
+
object.each do |k,v|
|
69
|
+
object[k] = replace_token(v, value)
|
70
|
+
end
|
71
|
+
elsif object.is_a?(String)
|
72
|
+
object = replace_token(object, value)
|
73
|
+
end
|
74
|
+
object
|
75
|
+
end
|
76
|
+
|
77
|
+
def replace_token(string, value)
|
78
|
+
string = string.dup
|
79
|
+
tokens.each do |token|
|
80
|
+
string.gsub!(token, value)
|
81
|
+
end
|
82
|
+
string
|
83
|
+
end
|
84
|
+
|
85
|
+
def tokens
|
86
|
+
["%value%"]
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ModsDisplay::Format < ModsDisplay::Field
|
2
|
+
|
3
|
+
def fields
|
4
|
+
return [] if (text.nil? and @value.text.strip.empty?)
|
5
|
+
return_values = @value.map{|v| v.text }
|
6
|
+
return_values = [text] unless text.nil?
|
7
|
+
[ModsDisplay::Values.new(:label => label || 'Format', :values => return_values)]
|
8
|
+
end
|
9
|
+
|
10
|
+
def text
|
11
|
+
return super unless super.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_html
|
15
|
+
output = ""
|
16
|
+
fields.each do |field|
|
17
|
+
output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
|
18
|
+
output << "<dd#{value_class}>"
|
19
|
+
field.values.map do |val|
|
20
|
+
output << "<span class='#{self.class.format_class(val)}'>#{val}</span>"
|
21
|
+
end.join(@config.delimiter)
|
22
|
+
output << "</dd>"
|
23
|
+
end
|
24
|
+
output
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.format_class(format)
|
30
|
+
return format if format.nil?
|
31
|
+
format.strip.downcase.gsub(/\/|\\|\s+/, "_")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class ModsDisplay::Identifier < ModsDisplay::Field
|
2
|
+
|
3
|
+
def fields
|
4
|
+
return_values = []
|
5
|
+
current_label = nil
|
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
|
27
|
+
end
|
28
|
+
return_values
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def identifier_label(element)
|
34
|
+
if element.attributes["type"].respond_to?(:value)
|
35
|
+
return identifier_labels[element.attributes["type"].value] || element.attributes["type"].value
|
36
|
+
end
|
37
|
+
"Identifier"
|
38
|
+
end
|
39
|
+
|
40
|
+
def identifier_labels
|
41
|
+
{"local" => "Identifier",
|
42
|
+
"isbn" => "ISBN",
|
43
|
+
"issn" => "ISSN",
|
44
|
+
"issn-l" => "ISSN",
|
45
|
+
"doi" => "DOI",
|
46
|
+
"hdl" => "Handle",
|
47
|
+
"isrc" => "ISRC",
|
48
|
+
"ismn" => "ISMN",
|
49
|
+
"issue number" => "Issue Number",
|
50
|
+
"lccn" => "LCCN",
|
51
|
+
"matrix number" => "Matrix Number",
|
52
|
+
"music publisher" => "Music Publisher",
|
53
|
+
"music plate" => "Music Plate",
|
54
|
+
"sici" => "SICI",
|
55
|
+
"upc" => "UPC",
|
56
|
+
"videorecording identifier" => "Videorecording Identifier",
|
57
|
+
"stock number" => "Stock Number"}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class ModsDisplay::Imprint < ModsDisplay::Field
|
2
|
+
|
3
|
+
def fields
|
4
|
+
return_values = []
|
5
|
+
@value.each do |val|
|
6
|
+
if imprint_display_form(val)
|
7
|
+
return_values << imprint_display_form(val)
|
8
|
+
else
|
9
|
+
place = nil
|
10
|
+
publisher = nil
|
11
|
+
placePub = nil
|
12
|
+
place = val.place.map do |p|
|
13
|
+
p.text unless p.text.strip.empty?
|
14
|
+
end.compact.join(" : ").strip unless val.place.text.strip.empty?
|
15
|
+
publisher = val.publisher.map do |p|
|
16
|
+
p.text unless p.text.strip.empty?
|
17
|
+
end.compact.join(" : ").strip unless val.publisher.text.strip.empty?
|
18
|
+
placePub = [place, publisher].compact.join(" : ")
|
19
|
+
placePub = nil if placePub.strip.empty?
|
20
|
+
parts = val.children.select do |child|
|
21
|
+
["dateCreated", "dateIssued", "dateCaptured", "dateOther"].include?(child.name) and !child.attributes.has_key?("encoding")
|
22
|
+
end.map do |child|
|
23
|
+
child.text.strip unless child.text.strip.empty?
|
24
|
+
end.compact.join(", ")
|
25
|
+
parts = nil if parts.strip.empty?
|
26
|
+
unless [placePub, parts].compact.join(", ").strip.empty?
|
27
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(val) || "Imprint", :values => [[placePub, parts].compact.join(", ")])
|
28
|
+
end
|
29
|
+
if other_pub_info(val).length > 0
|
30
|
+
other_pub_info(val).each do |pub_info|
|
31
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(val) || pub_info_labels[pub_info.name.to_sym], :values => [pub_info.text.strip])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
return_values
|
37
|
+
end
|
38
|
+
|
39
|
+
def other_pub_info(element)
|
40
|
+
element.children.select do |child|
|
41
|
+
pub_info_parts.include?(child.name.to_sym)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def imprint_display_form(element)
|
46
|
+
display_form = element.children.find do |child|
|
47
|
+
child.name == "displayForm"
|
48
|
+
end
|
49
|
+
ModsDisplay::Values.new(:label => displayLabel(element) || "Imprint", :values => [display_form.text]) if display_form
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def pub_info_parts
|
55
|
+
pub_info_labels.keys
|
56
|
+
end
|
57
|
+
|
58
|
+
def pub_info_labels
|
59
|
+
{:dateValid => "Date Valid",
|
60
|
+
:dateModified => "Date Modified",
|
61
|
+
:copyrightDate => "Copyright Date",
|
62
|
+
:edition => "Edition",
|
63
|
+
:issuance => "Issuance",
|
64
|
+
:frequency => "Frequency"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class ModsDisplay::Language < ModsDisplay::Field
|
2
|
+
def label
|
3
|
+
return super unless super.nil?
|
4
|
+
"Language"
|
5
|
+
end
|
6
|
+
|
7
|
+
def fields
|
8
|
+
return [] if @value.languageTerm.length < 1 or @value.languageTerm.text.strip.empty?
|
9
|
+
return_values = []
|
10
|
+
@value.each do |val|
|
11
|
+
languages = []
|
12
|
+
val.languageTerm.select do |term|
|
13
|
+
term.attributes["type"].respond_to?(:value) && term.attributes["type"].value == "code"
|
14
|
+
end.each do |term|
|
15
|
+
languages << language_codes[term.text]
|
16
|
+
end
|
17
|
+
return_values << ModsDisplay::Values.new(:label => displayLabel(val) || "Language", :values => languages)
|
18
|
+
end
|
19
|
+
return_values
|
20
|
+
end
|
21
|
+
|
22
|
+
def text
|
23
|
+
return super unless super.nil?
|
24
|
+
language_codes[@value.text.strip] || @value.text.strip
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def language_codes
|
30
|
+
SEARCHWORKS_LANGUAGES
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def location_label(element)
|
14
|
+
if element.attributes["type"].respond_to?(:value) && location_labels.has_key?(element.attributes["type"].value)
|
15
|
+
location_labels[element.attributes["type"].value]
|
16
|
+
else
|
17
|
+
"Location"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def location_labels
|
22
|
+
{"repository" => "Repository"}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
class ModsDisplay::Name < ModsDisplay::Field
|
2
|
+
|
3
|
+
def fields
|
4
|
+
return_values = []
|
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 = []
|
11
|
+
role = nil
|
12
|
+
if val.role.length > 0 and val.role.roleTerm.length > 0
|
13
|
+
role = val.role.roleTerm.find do |term|
|
14
|
+
term.attributes["type"].respond_to?(:value) and
|
15
|
+
term.attributes["type"].value == "text"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
if val.displayForm.length > 0
|
19
|
+
people << ModsDisplay::Name::Person.new(:name => val.displayForm.text, :role => role)
|
20
|
+
else
|
21
|
+
name_parts = val.namePart.map do |name_part|
|
22
|
+
name_part.text
|
23
|
+
end.join(", ")
|
24
|
+
people << ModsDisplay::Name::Person.new(:name => name_parts, :role => role)
|
25
|
+
end
|
26
|
+
if @value.length == 1
|
27
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten)
|
28
|
+
elsif index == (@value.length-1)
|
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)
|
32
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten)
|
33
|
+
else
|
34
|
+
buffer << people
|
35
|
+
return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
|
36
|
+
end
|
37
|
+
elsif prev_label and (current_label != prev_label)
|
38
|
+
return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
|
39
|
+
buffer = []
|
40
|
+
end
|
41
|
+
buffer << people
|
42
|
+
prev_label = current_label
|
43
|
+
end
|
44
|
+
return_values
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_html
|
48
|
+
return nil if fields.empty?
|
49
|
+
output = ""
|
50
|
+
fields.each do |field|
|
51
|
+
output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
|
52
|
+
output << "<dd#{value_class}>"
|
53
|
+
output << field.values.map do |val|
|
54
|
+
if @config.link
|
55
|
+
txt = link_to_value(val.name)
|
56
|
+
txt << " (#{val.role})" if val.role
|
57
|
+
txt
|
58
|
+
else
|
59
|
+
val.to_s
|
60
|
+
end
|
61
|
+
end.join(@config.delimiter)
|
62
|
+
output << "</dd>"
|
63
|
+
end
|
64
|
+
output
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def name_label(element)
|
70
|
+
if element.attributes.has_key?("type") && name_labels.has_key?(element.attributes["type"].value)
|
71
|
+
return name_labels[element.attributes["type"].value]
|
72
|
+
end
|
73
|
+
"Creator/Contributor"
|
74
|
+
end
|
75
|
+
|
76
|
+
def name_labels
|
77
|
+
{"personal" => "Author/Creator",
|
78
|
+
"corporate" => "Corporate Author",
|
79
|
+
"conference" => "Meeting",
|
80
|
+
"family" => "Family Author"}
|
81
|
+
end
|
82
|
+
|
83
|
+
class Person
|
84
|
+
attr_accessor :name, :role
|
85
|
+
def initialize(data)
|
86
|
+
@name = data[:name]
|
87
|
+
@role = data[:role] ? data[:role].text : nil
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_s
|
91
|
+
text = @name.dup
|
92
|
+
text << " (#{@role})" if @role
|
93
|
+
text
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|