Class: ModsDisplay::Imprint
- Inherits:
-
Field
- Object
- Field
- ModsDisplay::Imprint
show all
- Defined in:
- lib/mods_display/fields/imprint.rb
Instance Method Summary
collapse
Methods inherited from Field
#initialize, #label, #to_html
Instance Method Details
#apply_date_qualifier_decoration(date_fields) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/mods_display/fields/imprint.rb', line 89
def apply_date_qualifier_decoration(date_fields)
return_fields = date_fields.map do |date|
date = date.clone
if date_is_approximate?(date)
date.content = "[ca. #{date.text}]"
elsif date_is_questionable?(date)
date.content = "[#{date.text}?]"
elsif date_is_inferred?(date)
date.content = "[#{date.text}]"
end
date
end
return_fields.map{|d| d.text }
end
|
#date_is_approximate?(date_field) ⇒ Boolean
103
104
105
106
107
|
# File 'lib/mods_display/fields/imprint.rb', line 103
def date_is_approximate?(date_field)
date_field.attributes["qualifier"] and
date_field.attributes["qualifier"].respond_to?(:value) and
date_field.attributes["qualifier"].value == "approximate"
end
|
#date_is_inferred?(date_field) ⇒ Boolean
113
114
115
116
117
|
# File 'lib/mods_display/fields/imprint.rb', line 113
def date_is_inferred?(date_field)
date_field.attributes["qualifier"] and
date_field.attributes["qualifier"].respond_to?(:value) and
date_field.attributes["qualifier"].value == "inferred"
end
|
#date_is_questionable?(date_field) ⇒ Boolean
108
109
110
111
112
|
# File 'lib/mods_display/fields/imprint.rb', line 108
def date_is_questionable?(date_field)
date_field.attributes["qualifier"] and
date_field.attributes["qualifier"].respond_to?(:value) and
date_field.attributes["qualifier"].value == "questionable"
end
|
#dates(element) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/mods_display/fields/imprint.rb', line 50
def dates(element)
date_field_keys.map do |date_field|
if element.respond_to?(date_field)
elements = element.send(date_field)
unless elements.empty?
ModsDisplay::Values.new(:label => displayLabel(element) || pub_info_labels[elements.first.name.to_sym], :values => parse_dates(elements))
end
end
end.compact
end
|
#dates_are_open_range?(date_fields) ⇒ Boolean
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/mods_display/fields/imprint.rb', line 118
def dates_are_open_range?(date_fields)
date_fields.any? do |field|
field.attributes["point"] and
field.attributes["point"].respond_to?(:value) and
field.attributes["point"].value == "start"
end and !date_fields.any? do |field|
field.attributes["point"] and
field.attributes["point"].respond_to?(:value) and
field.attributes["point"].value == "end"
end
end
|
#dates_are_range?(date_fields) ⇒ Boolean
129
130
131
132
133
134
135
136
137
|
# File 'lib/mods_display/fields/imprint.rb', line 129
def dates_are_range?(date_fields)
attributes = date_fields.map do |date|
if date.attributes["point"].respond_to?(:value)
date.attributes["point"].value
end
end
attributes.include?("start") and
attributes.include?("end")
end
|
#dedup_dates(date_fields) ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/mods_display/fields/imprint.rb', line 138
def dedup_dates(date_fields)
date_text = date_fields.map{|d| normalize_date(d.text) }
if date_text != date_text.uniq
if date_fields.find{ |d| d.attributes["qualifier"].respond_to?(:value) }
[date_fields.find{ |d| d.attributes["qualifier"].respond_to?(:value) }]
elsif date_fields.find{ |d| !d.attributes["encoding"] }
[date_fields.find{ |d| !d.attributes["encoding"] }]
else
[date_fields.first]
end
else
date_fields
end
end
|
#fields ⇒ Object
3
4
5
6
7
8
9
10
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
41
42
43
44
45
46
47
48
49
|
# File 'lib/mods_display/fields/imprint.rb', line 3
def fields
return_fields = []
@values.each do |value|
if imprint_display_form(value)
return_fields << imprint_display_form(value)
else
edition = nil
place = nil
publisher = nil
placePub = nil
edition = value.edition.map do |e|
e.text unless e.text.strip.empty?
end.compact.join(" ").strip
place = value.place.map do |p|
p.text unless p.text.strip.empty?
end.compact.join(" : ").strip unless value.place.text.strip.empty?
publisher = value.publisher.map do |p|
p.text unless p.text.strip.empty?
end.compact.join(" : ").strip unless value.publisher.text.strip.empty?
parts = ["dateIssued", "dateOther"].map do |date_field_name|
if value.respond_to?(date_field_name.to_sym)
parse_dates(value.send(date_field_name.to_sym))
end
end.flatten.map do |date|
date.strip unless date.strip.empty?
end.compact.join(", ")
edition = nil if edition.strip.empty?
parts = nil if parts.strip.empty?
placePub = [place, publisher].compact.join(" : ")
placePub = nil if placePub.strip.empty?
editionPlace = [edition, placePub].compact.join(" - ")
editionPlace = nil if editionPlace.strip.empty?
unless [editionPlace, parts].compact.join(", ").strip.empty?
return_fields << ModsDisplay::Values.new(:label => displayLabel(value) || "Imprint", :values => [[editionPlace, parts].compact.join(", ")])
end
if dates(value).length > 0
return_fields.concat(dates(value))
end
if other_pub_info(value).length > 0
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 => [pub_info.text.strip])
end
end
end
end
collapse_fields(return_fields)
end
|
161
162
163
164
165
166
|
# File 'lib/mods_display/fields/imprint.rb', line 161
def imprint_display_form(element)
display_form = element.children.find do |child|
child.name == "displayForm"
end
ModsDisplay::Values.new(:label => displayLabel(element) || "Imprint", :values => [display_form.text]) if display_form
end
|
#join_date_ranges(date_fields) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/mods_display/fields/imprint.rb', line 63
def join_date_ranges(date_fields)
if dates_are_range?(date_fields)
start_date = date_fields.find{|d| d.attributes["point"] && d.attributes["point"].value == "start"}
end_date = date_fields.find{|d| d.attributes["point"] && d.attributes["point"].value == "end"}
date_fields.map do |date|
date = date.clone
if normalize_date(date.text) == start_date.text
date.content = [start_date.text, end_date.text].join("-")
date
elsif normalize_date(date.text) != end_date.text
date
end
end.compact
elsif dates_are_open_range?(date_fields)
start_date = date_fields.find{|d| d.attributes["point"] && d.attributes["point"].value == "start"}
date_fields.map do |date|
date = date.clone
if date.text == start_date.text
date.content = "#{start_date.text}-"
end
date
end
else
date_fields
end
end
|
#normalize_date(date) ⇒ Object
152
153
154
|
# File 'lib/mods_display/fields/imprint.rb', line 152
def normalize_date(date)
date.strip.gsub(/^\s*c\s*|\[|\]|\?/, "")
end
|
#other_pub_info(element) ⇒ Object
155
156
157
158
159
|
# File 'lib/mods_display/fields/imprint.rb', line 155
def other_pub_info(element)
element.children.select do |child|
pub_info_parts.include?(child.name.to_sym)
end
end
|
#parse_dates(date_field) ⇒ Object
60
61
62
|
# File 'lib/mods_display/fields/imprint.rb', line 60
def parse_dates(date_field)
apply_date_qualifier_decoration dedup_dates join_date_ranges date_field
end
|