Class: ModsDisplay::Imprint
Defined Under Namespace
Classes: DateRange, DateValue
Instance Method Summary
collapse
#country_codes
Methods inherited from Field
#initialize, #label, #render_in, #to_html
Instance Method Details
#date_values(element) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/mods_display/fields/imprint.rb', line 42
def date_values(element)
date_field_keys.map do |date_field|
next unless element.respond_to?(date_field)
elements = element.send(date_field)
next if elements.empty?
ModsDisplay::Values.new(
label: displayLabel(element) || pub_info_labels[elements.first.name.to_sym],
values: parse_dates(elements)
)
end.compact
end
|
#fields ⇒ Object
7
8
9
|
# File 'lib/mods_display/fields/imprint.rb', line 7
def fields
collapse_fields(origin_info_data.flatten)
end
|
#origin_info_data ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mods_display/fields/imprint.rb', line 11
def origin_info_data
@values.map do |value|
return_fields = []
edition = edition_element(value)
place = place_element(value)
publisher = publisher_element(value)
parts = parts_element(value)
place_pub = compact_and_join_with_delimiter([place, publisher], ' : ')
edition_place = compact_and_join_with_delimiter([edition, place_pub], ' - ')
joined_place_parts = compact_and_join_with_delimiter([edition_place, parts], ', ')
unless joined_place_parts.empty?
return_fields << ModsDisplay::Values.new(
label: displayLabel(value) || I18n.t('mods_display.imprint'),
values: [joined_place_parts]
)
end
return_fields.concat(date_values(value))
other_pub_info(value).each do |pub_info|
return_fields << ModsDisplay::Values.new(
label: displayLabel(value) || pub_info_labels[pub_info.name.to_sym],
values: [element_text(pub_info)]
)
end
return_fields.compact
end
end
|
#other_pub_info(element) ⇒ Object
199
200
201
202
203
|
# File 'lib/mods_display/fields/imprint.rb', line 199
def other_pub_info(element)
element.children.select do |child|
pub_info_parts.include?(child.name.to_sym)
end
end
|
#parse_dates(elements) ⇒ Object
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/mods_display/fields/imprint.rb', line 162
def parse_dates(elements)
dates = elements.map(&:as_object).flatten.map { |element| DateValue.new(element) }.select(&:valid?)
point, nonpoint = dates.partition(&:point)
if point.any?
range = DateRange.new(start: point.find { |date| date.point == 'start' },
stop: point.find { |date| date.point == 'end' })
nonpoint.unshift(range)
end
dates = nonpoint
dates = dates.group_by(&:base_value).map do |_value, group|
group.first if group.one?
if group.reject(&:encoding).any?
group.reject(&:encoding).first
else
group.last
end
end
range_base_values = dates.select { |date| date.is_a?(DateRange) }
.map(&:base_values).flatten
dates = dates.reject { |date| range_base_values.include?(date.base_value) }
dates.map(&:qualified_value)
end
|
#place_terms(element) ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/mods_display/fields/imprint.rb', line 205
def place_terms(element)
return [] unless element.respond_to?(:place) &&
element.place.respond_to?(:placeTerm)
if unencoded_place_terms?(element)
element.place.placeTerm.select do |term|
!term.attributes['type'].respond_to?(:value) ||
term.attributes['type'].value == 'text'
end.compact
else
element.place.placeTerm.map do |term|
next unless term.attributes['type'].respond_to?(:value) &&
term.attributes['type'].value == 'code' &&
term.attributes['authority'].respond_to?(:value) &&
term.attributes['authority'].value == 'marccountry' &&
country_codes.include?(term.text.strip)
term = term.clone
term.content = country_codes[term.text.strip]
term
end.compact
end
end
|
#unencoded_place_terms?(element) ⇒ Boolean
229
230
231
232
233
234
|
# File 'lib/mods_display/fields/imprint.rb', line 229
def unencoded_place_terms?(element)
element.place.placeTerm.any? do |term|
!term.attributes['type'].respond_to?(:value) ||
term.attributes['type'].value == 'text'
end
end
|