mods_display 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +60 -0
- data/.travis.yml +2 -2
- data/Rakefile +10 -2
- data/lib/mods_display.rb +42 -42
- data/lib/mods_display/configuration.rb +69 -67
- data/lib/mods_display/configuration/access_condition.rb +17 -13
- data/lib/mods_display/configuration/base.rb +27 -24
- data/lib/mods_display/configuration/format.rb +8 -4
- data/lib/mods_display/configuration/genre.rb +8 -4
- data/lib/mods_display/configuration/imprint.rb +12 -7
- data/lib/mods_display/configuration/name.rb +8 -4
- data/lib/mods_display/configuration/note.rb +8 -4
- data/lib/mods_display/configuration/related_item.rb +8 -4
- data/lib/mods_display/configuration/subject.rb +11 -9
- data/lib/mods_display/configuration/title.rb +8 -4
- data/lib/mods_display/controller_extension.rb +24 -24
- data/lib/mods_display/country_codes.rb +385 -384
- data/lib/mods_display/fields/abstract.rb +7 -6
- data/lib/mods_display/fields/access_condition.rb +55 -55
- data/lib/mods_display/fields/audience.rb +7 -6
- data/lib/mods_display/fields/cartographics.rb +15 -14
- data/lib/mods_display/fields/collection.rb +32 -17
- data/lib/mods_display/fields/contact.rb +15 -13
- data/lib/mods_display/fields/contents.rb +7 -6
- data/lib/mods_display/fields/description.rb +21 -21
- data/lib/mods_display/fields/field.rb +164 -109
- data/lib/mods_display/fields/format.rb +36 -33
- data/lib/mods_display/fields/genre.rb +12 -11
- data/lib/mods_display/fields/identifier.rb +34 -34
- data/lib/mods_display/fields/imprint.rb +258 -214
- data/lib/mods_display/fields/language.rb +18 -16
- data/lib/mods_display/fields/location.rb +27 -26
- data/lib/mods_display/fields/name.rb +113 -118
- data/lib/mods_display/fields/note.rb +33 -34
- data/lib/mods_display/fields/related_item.rb +64 -66
- data/lib/mods_display/fields/resource_type.rb +13 -11
- data/lib/mods_display/fields/sub_title.rb +6 -4
- data/lib/mods_display/fields/subject.rb +92 -90
- data/lib/mods_display/fields/title.rb +54 -49
- data/lib/mods_display/fields/values.rb +7 -8
- data/lib/mods_display/html.rb +117 -96
- data/lib/mods_display/model_extension.rb +17 -16
- data/lib/mods_display/relator_codes.rb +269 -267
- data/lib/mods_display/version.rb +1 -1
- data/mods_display.gemspec +13 -12
- data/spec/configuration/access_condition_spec.rb +5 -5
- data/spec/configuration/base_spec.rb +24 -24
- data/spec/fields/abstract_spec.rb +24 -14
- data/spec/fields/access_condition_spec.rb +80 -55
- data/spec/fields/audience_spec.rb +15 -12
- data/spec/fields/cartographics_spec.rb +17 -18
- data/spec/fields/collection_spec.rb +65 -19
- data/spec/fields/contact_spec.rb +11 -9
- data/spec/fields/contents_spec.rb +15 -12
- data/spec/fields/description_spec.rb +40 -22
- data/spec/fields/format_spec.rb +28 -18
- data/spec/fields/genre_spec.rb +18 -16
- data/spec/fields/identifier_spec.rb +46 -34
- data/spec/fields/imprint_spec.rb +151 -125
- data/spec/fields/language_spec.rb +36 -20
- data/spec/fields/location_spec.rb +43 -27
- data/spec/fields/name_spec.rb +92 -92
- data/spec/fields/note_spec.rb +53 -40
- data/spec/fields/related_item_spec.rb +42 -40
- data/spec/fields/resource_type_spec.rb +20 -14
- data/spec/fields/sub_title_spec.rb +11 -9
- data/spec/fields/subject_spec.rb +61 -56
- data/spec/fields/title_spec.rb +53 -40
- data/spec/fixtures/access_condition_fixtures.rb +50 -0
- data/spec/fixtures/cartographics_fixtures.rb +1 -1
- data/spec/fixtures/imprint_fixtures.rb +49 -1
- data/spec/fixtures/name_fixtures.rb +195 -2
- data/spec/fixtures/related_item_fixtures.rb +107 -0
- data/spec/fixtures/subjects_fixtures.rb +15 -2
- data/spec/fixtures/title_fixtures.rb +101 -0
- data/spec/integration/configuration_spec.rb +23 -20
- data/spec/integration/html_spec.rb +40 -29
- data/spec/integration/installation_spec.rb +14 -14
- data/spec/spec_helper.rb +5 -8
- metadata +25 -3
@@ -1,42 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Format < Field
|
3
|
+
def fields
|
4
|
+
return_fields = []
|
5
|
+
if @values.respond_to?(:format) &&
|
6
|
+
!@values.format.nil? &&
|
7
|
+
!@values.format.empty?
|
8
|
+
return_fields << ModsDisplay::Values.new(label: format_label,
|
9
|
+
values: [decorate_formats(@values.format).join(', ')])
|
10
|
+
end
|
11
|
+
unless @values.physical_description.nil?
|
12
|
+
@values.physical_description.each do |description|
|
13
|
+
unless description.form.nil? || description.form.empty?
|
14
|
+
return_fields << ModsDisplay::Values.new(
|
15
|
+
label: displayLabel(description) || format_label,
|
16
|
+
values: [description.form.map { |f| f.text.strip }.uniq.join(', ')]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
unless description.extent.nil? || description.extent.empty?
|
20
|
+
return_fields << ModsDisplay::Values.new(label: displayLabel(description) || format_label,
|
21
|
+
values: [description.extent.map(&:text).join(', ')])
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
25
|
+
collapse_fields(return_fields)
|
22
26
|
end
|
23
|
-
collapse_fields(return_fields)
|
24
|
-
end
|
25
27
|
|
26
|
-
|
28
|
+
private
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
def decorate_formats(formats)
|
31
|
+
formats.map do |format|
|
32
|
+
"<span data-mods-display-format='#{self.class.format_class(format)}'>#{format}</span>"
|
33
|
+
end
|
31
34
|
end
|
32
|
-
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def self.format_class(format)
|
37
|
+
return format if format.nil?
|
38
|
+
format.strip.downcase.gsub(%r{/|\\|\s+}, '_')
|
39
|
+
end
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
def format_label
|
42
|
+
I18n.t('mods_display.format')
|
43
|
+
end
|
41
44
|
end
|
42
|
-
end
|
45
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Genre < Field
|
3
|
+
def fields
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
ModsDisplay::Values.new(label: displayLabel(value) || label, values: [value.text.strip.capitalize].flatten)
|
6
|
+
end
|
7
|
+
collapse_fields(return_fields)
|
6
8
|
end
|
7
|
-
collapse_fields(return_fields)
|
8
|
-
end
|
9
9
|
|
10
|
-
|
10
|
+
private
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
def displayLabel(element)
|
13
|
+
super(element) || I18n.t('mods_display.genre')
|
14
|
+
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ModsDisplay
|
2
|
+
class Identifier < Field
|
3
|
+
def fields
|
4
|
+
return_fields = @values.map do |value|
|
5
|
+
ModsDisplay::Values.new(label: displayLabel(value) || identifier_label(value), values: [value.text])
|
6
|
+
end
|
7
|
+
collapse_fields(return_fields)
|
6
8
|
end
|
7
|
-
collapse_fields(return_fields)
|
8
|
-
end
|
9
9
|
|
10
|
-
|
10
|
+
private
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def identifier_label(element)
|
13
|
+
if element.attributes['type'].respond_to?(:value)
|
14
|
+
return identifier_labels[element.attributes['type'].value] || "#{element.attributes['type'].value}:"
|
15
|
+
end
|
16
|
+
I18n.t('mods_display.identifier')
|
15
17
|
end
|
16
|
-
I18n.t('mods_display.identifier')
|
17
|
-
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
19
|
+
def identifier_labels
|
20
|
+
{ 'local' => I18n.t('mods_display.identifier'),
|
21
|
+
'isbn' => I18n.t('mods_display.isbn'),
|
22
|
+
'issn' => I18n.t('mods_display.issn'),
|
23
|
+
'issn-l' => I18n.t('mods_display.issn'),
|
24
|
+
'doi' => I18n.t('mods_display.doi'),
|
25
|
+
'hdl' => I18n.t('mods_display.handle'),
|
26
|
+
'isrc' => I18n.t('mods_display.isrc'),
|
27
|
+
'ismn' => I18n.t('mods_display.ismn'),
|
28
|
+
'issue number' => I18n.t('mods_display.issue_number'),
|
29
|
+
'lccn' => I18n.t('mods_display.lccn'),
|
30
|
+
'oclc' => I18n.t('mods_display.oclc'),
|
31
|
+
'matrix number' => I18n.t('mods_display.matrix_number'),
|
32
|
+
'music publisher' => I18n.t('mods_display.music_publisher'),
|
33
|
+
'music plate' => I18n.t('mods_display.music_plate'),
|
34
|
+
'sici' => I18n.t('mods_display.sici'),
|
35
|
+
'upc' => I18n.t('mods_display.upc'),
|
36
|
+
'videorecording identifier' => I18n.t('mods_display.videorecording_identifier'),
|
37
|
+
'stock number' => I18n.t('mods_display.stock_number') }
|
38
|
+
end
|
38
39
|
end
|
39
|
-
|
40
|
-
end
|
40
|
+
end
|
@@ -1,250 +1,294 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
parts = ["dateIssued", "dateOther"].map do |date_field_name|
|
23
|
-
if value.respond_to?(date_field_name.to_sym)
|
24
|
-
parse_dates(value.send(date_field_name.to_sym))
|
1
|
+
module ModsDisplay
|
2
|
+
class Imprint < Field
|
3
|
+
include ModsDisplay::CountryCodes
|
4
|
+
def fields
|
5
|
+
return_fields = []
|
6
|
+
@values.each do |value|
|
7
|
+
if imprint_display_form(value)
|
8
|
+
return_fields << imprint_display_form(value)
|
9
|
+
else
|
10
|
+
edition = edition_element(value)
|
11
|
+
place = place_element(value)
|
12
|
+
publisher = publisher_element(value)
|
13
|
+
parts = parts_element(value)
|
14
|
+
place_pub = compact_and_join_with_delimiter([place, publisher], ' : ')
|
15
|
+
edition_place = compact_and_join_with_delimiter([edition, place_pub], ' - ')
|
16
|
+
joined_place_parts = compact_and_join_with_delimiter([edition_place, parts], ', ')
|
17
|
+
unless joined_place_parts.empty?
|
18
|
+
return_fields << ModsDisplay::Values.new(
|
19
|
+
label: displayLabel(value) || I18n.t('mods_display.imprint'),
|
20
|
+
values: [joined_place_parts]
|
21
|
+
)
|
25
22
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
editionPlace = nil if editionPlace.strip.empty?
|
35
|
-
unless [editionPlace, parts].compact.join(", ").strip.empty?
|
36
|
-
return_fields << ModsDisplay::Values.new(:label => displayLabel(value) || I18n.t('mods_display.imprint'), :values => [[editionPlace, parts].compact.join(", ")])
|
37
|
-
end
|
38
|
-
if dates(value).length > 0
|
39
|
-
return_fields.concat(dates(value))
|
40
|
-
end
|
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])
|
23
|
+
return_fields.concat(dates(value)) if dates(value).length > 0
|
24
|
+
if other_pub_info(value).length > 0
|
25
|
+
other_pub_info(value).each do |pub_info|
|
26
|
+
return_fields << ModsDisplay::Values.new(
|
27
|
+
label: displayLabel(value) || pub_info_labels[pub_info.name.to_sym],
|
28
|
+
values: [pub_info.text.strip]
|
29
|
+
)
|
30
|
+
end
|
44
31
|
end
|
45
32
|
end
|
46
33
|
end
|
34
|
+
collapse_fields(return_fields)
|
47
35
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if element.respond_to?(date_field)
|
36
|
+
|
37
|
+
def dates(element)
|
38
|
+
date_field_keys.map do |date_field|
|
39
|
+
next unless element.respond_to?(date_field)
|
53
40
|
elements = element.send(date_field)
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
next if elements.empty?
|
42
|
+
ModsDisplay::Values.new(
|
43
|
+
label: displayLabel(element) || pub_info_labels[elements.first.name.to_sym],
|
44
|
+
values: parse_dates(elements)
|
45
|
+
)
|
46
|
+
end.compact
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_dates(date_field)
|
50
|
+
apply_date_qualifier_decoration(
|
51
|
+
dedup_dates(
|
52
|
+
join_date_ranges(
|
53
|
+
process_bc_ad_dates(
|
54
|
+
process_encoded_dates(ignore_bad_dates(date_field))
|
55
|
+
)
|
56
|
+
)
|
57
|
+
)
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def ignore_bad_dates(date_fields)
|
62
|
+
date_fields.select do |date_field|
|
63
|
+
date_field.text.strip != '9999'
|
57
64
|
end
|
58
|
-
end.compact
|
59
|
-
end
|
60
|
-
def parse_dates(date_field)
|
61
|
-
apply_date_qualifier_decoration dedup_dates join_date_ranges process_encoded_dates ignore_bad_dates date_field
|
62
|
-
end
|
63
|
-
def ignore_bad_dates(date_fields)
|
64
|
-
date_fields.select do |date_field|
|
65
|
-
date_field.text.strip != "9999"
|
66
65
|
end
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
|
67
|
+
def process_encoded_dates(date_fields)
|
68
|
+
date_fields.map do |date_field|
|
69
|
+
if date_is_w3cdtf?(date_field)
|
70
|
+
process_w3cdtf_date(date_field)
|
71
|
+
else
|
72
|
+
date_field
|
73
|
+
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
76
|
+
|
77
|
+
def join_date_ranges(date_fields)
|
78
|
+
if dates_are_range?(date_fields)
|
79
|
+
start_date = date_fields.find { |d| d.attributes['point'] && d.attributes['point'].value == 'start' }
|
80
|
+
end_date = date_fields.find { |d| d.attributes['point'] && d.attributes['point'].value == 'end' }
|
81
|
+
date_fields.map do |date|
|
82
|
+
date = date.clone # clone the date object so we don't append the same one
|
83
|
+
if normalize_date(date.text) == normalize_date(start_date.text)
|
84
|
+
date.content = [start_date.text, end_date.text].join('-')
|
85
|
+
date
|
86
|
+
elsif normalize_date(date.text) != normalize_date(end_date.text)
|
87
|
+
date
|
88
|
+
end
|
89
|
+
end.compact
|
90
|
+
elsif dates_are_open_range?(date_fields)
|
91
|
+
start_date = date_fields.find { |d| d.attributes['point'] && d.attributes['point'].value == 'start' }
|
92
|
+
date_fields.map do |date|
|
93
|
+
date = date.clone # clone the date object so we don't append the same one
|
94
|
+
date.content = "#{start_date.text}-" if date.text == start_date.text
|
87
95
|
date
|
88
96
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
97
|
+
else
|
98
|
+
date_fields
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def apply_date_qualifier_decoration(date_fields)
|
103
|
+
return_fields = date_fields.map do |date|
|
104
|
+
date = date.clone
|
105
|
+
if date_is_approximate?(date)
|
106
|
+
date.content = "[ca. #{date.text}]"
|
107
|
+
elsif date_is_questionable?(date)
|
108
|
+
date.content = "[#{date.text}?]"
|
109
|
+
elsif date_is_inferred?(date)
|
110
|
+
date.content = "[#{date.text}]"
|
96
111
|
end
|
97
112
|
date
|
98
113
|
end
|
99
|
-
|
100
|
-
date_fields
|
114
|
+
return_fields.map(&:text)
|
101
115
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
116
|
+
|
117
|
+
def date_is_approximate?(date_field)
|
118
|
+
date_field.attributes['qualifier'] &&
|
119
|
+
date_field.attributes['qualifier'].respond_to?(:value) &&
|
120
|
+
date_field.attributes['qualifier'].value == 'approximate'
|
121
|
+
end
|
122
|
+
|
123
|
+
def date_is_questionable?(date_field)
|
124
|
+
date_field.attributes['qualifier'] &&
|
125
|
+
date_field.attributes['qualifier'].respond_to?(:value) &&
|
126
|
+
date_field.attributes['qualifier'].value == 'questionable'
|
127
|
+
end
|
128
|
+
|
129
|
+
def date_is_inferred?(date_field)
|
130
|
+
date_field.attributes['qualifier'] &&
|
131
|
+
date_field.attributes['qualifier'].respond_to?(:value) &&
|
132
|
+
date_field.attributes['qualifier'].value == 'inferred'
|
133
|
+
end
|
134
|
+
|
135
|
+
def dates_are_open_range?(date_fields)
|
136
|
+
date_fields.any? do |field|
|
137
|
+
field.attributes['point'] &&
|
138
|
+
field.attributes['point'].respond_to?(:value) &&
|
139
|
+
field.attributes['point'].value == 'start'
|
140
|
+
end && !date_fields.any? do |field|
|
141
|
+
field.attributes['point'] &&
|
142
|
+
field.attributes['point'].respond_to?(:value) &&
|
143
|
+
field.attributes['point'].value == 'end'
|
112
144
|
end
|
113
|
-
date
|
114
145
|
end
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
date_field.attributes["qualifier"].respond_to?(:value) and
|
125
|
-
date_field.attributes["qualifier"].value == "questionable"
|
126
|
-
end
|
127
|
-
def date_is_inferred?(date_field)
|
128
|
-
date_field.attributes["qualifier"] and
|
129
|
-
date_field.attributes["qualifier"].respond_to?(:value) and
|
130
|
-
date_field.attributes["qualifier"].value == "inferred"
|
131
|
-
end
|
132
|
-
def dates_are_open_range?(date_fields)
|
133
|
-
date_fields.any? do |field|
|
134
|
-
field.attributes["point"] and
|
135
|
-
field.attributes["point"].respond_to?(:value) and
|
136
|
-
field.attributes["point"].value == "start"
|
137
|
-
end and !date_fields.any? do |field|
|
138
|
-
field.attributes["point"] and
|
139
|
-
field.attributes["point"].respond_to?(:value) and
|
140
|
-
field.attributes["point"].value == "end"
|
146
|
+
|
147
|
+
def dates_are_range?(date_fields)
|
148
|
+
attributes = date_fields.map do |date|
|
149
|
+
if date.attributes['point'].respond_to?(:value)
|
150
|
+
date.attributes['point'].value
|
151
|
+
end
|
152
|
+
end
|
153
|
+
attributes.include?('start') &&
|
154
|
+
attributes.include?('end')
|
141
155
|
end
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
156
|
+
|
157
|
+
def date_is_w3cdtf?(date_field)
|
158
|
+
field_is_encoded?(date_field, 'w3cdtf')
|
159
|
+
end
|
160
|
+
|
161
|
+
def process_w3cdtf_date(date_field)
|
162
|
+
date_field = date_field.clone
|
163
|
+
date_field.content = begin
|
164
|
+
if date_field.text.strip =~ /^\d{4}-\d{2}-\d{2}$/
|
165
|
+
Date.parse(date_field.text).strftime(@config.full_date_format)
|
166
|
+
elsif date_field.text.strip =~ /^\d{4}-\d{2}$/
|
167
|
+
Date.parse("#{date_field.text}-01").strftime(@config.short_date_format)
|
168
|
+
else
|
169
|
+
date_field.content
|
170
|
+
end
|
171
|
+
rescue
|
172
|
+
date_field.content
|
147
173
|
end
|
174
|
+
date_field
|
148
175
|
end
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
if date_field.text.strip =~ /^\d{4}-\d{2}-\d{2}$/
|
161
|
-
Date.parse(date_field.text).strftime(@config.full_date_format)
|
162
|
-
elsif date_field.text.strip =~ /^\d{4}-\d{2}$/
|
163
|
-
Date.parse("#{date_field.text}-01").strftime(@config.short_date_format)
|
176
|
+
|
177
|
+
def dedup_dates(date_fields)
|
178
|
+
date_text = date_fields.map { |d| normalize_date(d.text) }
|
179
|
+
if date_text != date_text.uniq
|
180
|
+
if date_fields.find { |d| d.attributes['qualifier'].respond_to?(:value) }
|
181
|
+
[date_fields.find { |d| d.attributes['qualifier'].respond_to?(:value) }]
|
182
|
+
elsif date_fields.find { |d| !d.attributes['encoding'] }
|
183
|
+
[date_fields.find { |d| !d.attributes['encoding'] }]
|
184
|
+
else
|
185
|
+
[date_fields.first]
|
186
|
+
end
|
164
187
|
else
|
165
|
-
|
188
|
+
date_fields
|
166
189
|
end
|
167
|
-
rescue
|
168
|
-
date_field.content
|
169
190
|
end
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
191
|
+
|
192
|
+
def normalize_date(date)
|
193
|
+
date.strip.gsub(/^\[*ca\.\s*|c|\[|\]|\?/, '')
|
194
|
+
end
|
195
|
+
|
196
|
+
def other_pub_info(element)
|
197
|
+
element.children.select do |child|
|
198
|
+
pub_info_parts.include?(child.name.to_sym)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def place_terms(element)
|
203
|
+
return [] unless element.respond_to?(:place) &&
|
204
|
+
element.place.respond_to?(:placeTerm)
|
205
|
+
if unencoded_place_terms?(element)
|
206
|
+
element.place.placeTerm.select do |term|
|
207
|
+
!term.attributes['type'].respond_to?(:value) ||
|
208
|
+
term.attributes['type'].value == 'text'
|
209
|
+
end.compact
|
179
210
|
else
|
180
|
-
|
211
|
+
element.place.placeTerm.map do |term|
|
212
|
+
next unless term.attributes['type'].respond_to?(:value) &&
|
213
|
+
term.attributes['type'].value == 'code' &&
|
214
|
+
term.attributes['authority'].respond_to?(:value) &&
|
215
|
+
term.attributes['authority'].value == 'marccountry' &&
|
216
|
+
country_codes.include?(term.text.strip)
|
217
|
+
term = term.clone
|
218
|
+
term.content = country_codes[term.text.strip]
|
219
|
+
term
|
220
|
+
end.compact
|
181
221
|
end
|
182
|
-
else
|
183
|
-
date_fields
|
184
222
|
end
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
pub_info_parts.include?(child.name.to_sym)
|
223
|
+
|
224
|
+
def unencoded_place_terms?(element)
|
225
|
+
element.place.placeTerm.any? do |term|
|
226
|
+
!term.attributes['type'].respond_to?(:value) ||
|
227
|
+
term.attributes['type'].value == 'text'
|
228
|
+
end
|
192
229
|
end
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
else
|
203
|
-
element.place.placeTerm.map do |term|
|
204
|
-
if term.attributes["type"].respond_to?(:value) and
|
205
|
-
term.attributes["type"].value == "code" and
|
206
|
-
term.attributes["authority"].respond_to?(:value) and
|
207
|
-
term.attributes["authority"].value == "marccountry" and
|
208
|
-
country_codes.include?(term.text.strip)
|
209
|
-
term = term.clone
|
210
|
-
term.content = country_codes[term.text.strip]
|
211
|
-
term
|
212
|
-
end
|
213
|
-
end.compact
|
230
|
+
|
231
|
+
def imprint_display_form(element)
|
232
|
+
display_form = element.children.find do |child|
|
233
|
+
child.name == 'displayForm'
|
234
|
+
end
|
235
|
+
ModsDisplay::Values.new(
|
236
|
+
label: displayLabel(element) || I18n.t('mods_display.imprint'),
|
237
|
+
values: [display_form.text]
|
238
|
+
) if display_form
|
214
239
|
end
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
240
|
+
|
241
|
+
private
|
242
|
+
|
243
|
+
def edition_element(value)
|
244
|
+
value.edition.reject do |e|
|
245
|
+
e.text.strip.empty?
|
246
|
+
end.map(&:text).join(' ').strip
|
220
247
|
end
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
248
|
+
|
249
|
+
def place_element(value)
|
250
|
+
return if value.place.text.strip.empty?
|
251
|
+
places = place_terms(value).reject do |p|
|
252
|
+
p.text.strip.empty?
|
253
|
+
end.map(&:text)
|
254
|
+
compact_and_join_with_delimiter(places, ' : ')
|
225
255
|
end
|
226
|
-
ModsDisplay::Values.new(:label => displayLabel(element) || I18n.t('mods_display.imprint'), :values => [display_form.text]) if display_form
|
227
|
-
end
|
228
256
|
|
229
|
-
|
257
|
+
def publisher_element(value)
|
258
|
+
return if value.publisher.text.strip.empty?
|
259
|
+
publishers = value.publisher.reject do |p|
|
260
|
+
p.text.strip.empty?
|
261
|
+
end.map(&:text)
|
262
|
+
compact_and_join_with_delimiter(publishers, ' : ')
|
263
|
+
end
|
230
264
|
|
231
|
-
|
232
|
-
|
233
|
-
|
265
|
+
def parts_element(value)
|
266
|
+
date_elements = %w(dateIssued dateOther).map do |date_field_name|
|
267
|
+
next unless value.respond_to?(date_field_name.to_sym)
|
268
|
+
parse_dates(value.send(date_field_name.to_sym))
|
269
|
+
end.flatten.compact.reject do |date|
|
270
|
+
date.strip.empty?
|
271
|
+
end.map(&:strip)
|
272
|
+
compact_and_join_with_delimiter(date_elements, ', ')
|
273
|
+
end
|
234
274
|
|
235
|
-
|
236
|
-
|
237
|
-
|
275
|
+
def pub_info_parts
|
276
|
+
[:issuance, :frequency]
|
277
|
+
end
|
238
278
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
:dateValid => I18n.t('mods_display.date_valid'),
|
243
|
-
:dateModified => I18n.t('mods_display.date_modified'),
|
244
|
-
:copyrightDate => I18n.t('mods_display.copyright_date'),
|
245
|
-
:issuance => I18n.t('mods_display.issuance'),
|
246
|
-
:frequency => I18n.t('mods_display.frequency')
|
247
|
-
}
|
248
|
-
end
|
279
|
+
def date_field_keys
|
280
|
+
[:dateCreated, :dateCaptured, :dateValid, :dateModified, :copyrightDate]
|
281
|
+
end
|
249
282
|
|
250
|
-
|
283
|
+
def pub_info_labels
|
284
|
+
{ dateCreated: I18n.t('mods_display.date_created'),
|
285
|
+
dateCaptured: I18n.t('mods_display.date_captured'),
|
286
|
+
dateValid: I18n.t('mods_display.date_valid'),
|
287
|
+
dateModified: I18n.t('mods_display.date_modified'),
|
288
|
+
copyrightDate: I18n.t('mods_display.copyright_date'),
|
289
|
+
issuance: I18n.t('mods_display.issuance'),
|
290
|
+
frequency: I18n.t('mods_display.frequency')
|
291
|
+
}
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|