mods_display 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +16 -0
  3. data/.rubocop_todo.yml +60 -0
  4. data/.travis.yml +2 -2
  5. data/Rakefile +10 -2
  6. data/lib/mods_display.rb +42 -42
  7. data/lib/mods_display/configuration.rb +69 -67
  8. data/lib/mods_display/configuration/access_condition.rb +17 -13
  9. data/lib/mods_display/configuration/base.rb +27 -24
  10. data/lib/mods_display/configuration/format.rb +8 -4
  11. data/lib/mods_display/configuration/genre.rb +8 -4
  12. data/lib/mods_display/configuration/imprint.rb +12 -7
  13. data/lib/mods_display/configuration/name.rb +8 -4
  14. data/lib/mods_display/configuration/note.rb +8 -4
  15. data/lib/mods_display/configuration/related_item.rb +8 -4
  16. data/lib/mods_display/configuration/subject.rb +11 -9
  17. data/lib/mods_display/configuration/title.rb +8 -4
  18. data/lib/mods_display/controller_extension.rb +24 -24
  19. data/lib/mods_display/country_codes.rb +385 -384
  20. data/lib/mods_display/fields/abstract.rb +7 -6
  21. data/lib/mods_display/fields/access_condition.rb +55 -55
  22. data/lib/mods_display/fields/audience.rb +7 -6
  23. data/lib/mods_display/fields/cartographics.rb +15 -14
  24. data/lib/mods_display/fields/collection.rb +32 -17
  25. data/lib/mods_display/fields/contact.rb +15 -13
  26. data/lib/mods_display/fields/contents.rb +7 -6
  27. data/lib/mods_display/fields/description.rb +21 -21
  28. data/lib/mods_display/fields/field.rb +164 -109
  29. data/lib/mods_display/fields/format.rb +36 -33
  30. data/lib/mods_display/fields/genre.rb +12 -11
  31. data/lib/mods_display/fields/identifier.rb +34 -34
  32. data/lib/mods_display/fields/imprint.rb +258 -214
  33. data/lib/mods_display/fields/language.rb +18 -16
  34. data/lib/mods_display/fields/location.rb +27 -26
  35. data/lib/mods_display/fields/name.rb +113 -118
  36. data/lib/mods_display/fields/note.rb +33 -34
  37. data/lib/mods_display/fields/related_item.rb +64 -66
  38. data/lib/mods_display/fields/resource_type.rb +13 -11
  39. data/lib/mods_display/fields/sub_title.rb +6 -4
  40. data/lib/mods_display/fields/subject.rb +92 -90
  41. data/lib/mods_display/fields/title.rb +54 -49
  42. data/lib/mods_display/fields/values.rb +7 -8
  43. data/lib/mods_display/html.rb +117 -96
  44. data/lib/mods_display/model_extension.rb +17 -16
  45. data/lib/mods_display/relator_codes.rb +269 -267
  46. data/lib/mods_display/version.rb +1 -1
  47. data/mods_display.gemspec +13 -12
  48. data/spec/configuration/access_condition_spec.rb +5 -5
  49. data/spec/configuration/base_spec.rb +24 -24
  50. data/spec/fields/abstract_spec.rb +24 -14
  51. data/spec/fields/access_condition_spec.rb +80 -55
  52. data/spec/fields/audience_spec.rb +15 -12
  53. data/spec/fields/cartographics_spec.rb +17 -18
  54. data/spec/fields/collection_spec.rb +65 -19
  55. data/spec/fields/contact_spec.rb +11 -9
  56. data/spec/fields/contents_spec.rb +15 -12
  57. data/spec/fields/description_spec.rb +40 -22
  58. data/spec/fields/format_spec.rb +28 -18
  59. data/spec/fields/genre_spec.rb +18 -16
  60. data/spec/fields/identifier_spec.rb +46 -34
  61. data/spec/fields/imprint_spec.rb +151 -125
  62. data/spec/fields/language_spec.rb +36 -20
  63. data/spec/fields/location_spec.rb +43 -27
  64. data/spec/fields/name_spec.rb +92 -92
  65. data/spec/fields/note_spec.rb +53 -40
  66. data/spec/fields/related_item_spec.rb +42 -40
  67. data/spec/fields/resource_type_spec.rb +20 -14
  68. data/spec/fields/sub_title_spec.rb +11 -9
  69. data/spec/fields/subject_spec.rb +61 -56
  70. data/spec/fields/title_spec.rb +53 -40
  71. data/spec/fixtures/access_condition_fixtures.rb +50 -0
  72. data/spec/fixtures/cartographics_fixtures.rb +1 -1
  73. data/spec/fixtures/imprint_fixtures.rb +49 -1
  74. data/spec/fixtures/name_fixtures.rb +195 -2
  75. data/spec/fixtures/related_item_fixtures.rb +107 -0
  76. data/spec/fixtures/subjects_fixtures.rb +15 -2
  77. data/spec/fixtures/title_fixtures.rb +101 -0
  78. data/spec/integration/configuration_spec.rb +23 -20
  79. data/spec/integration/html_spec.rb +40 -29
  80. data/spec/integration/installation_spec.rb +14 -14
  81. data/spec/spec_helper.rb +5 -8
  82. metadata +25 -3
@@ -1,42 +1,45 @@
1
- class ModsDisplay::Format < ModsDisplay::Field
2
-
3
- def fields
4
- return_fields = []
5
- if @values.respond_to?(:format) and
6
- !@values.format.nil? and
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? or description.form.empty?
14
- return_fields << ModsDisplay::Values.new(:label => displayLabel(description) || format_label,
15
- :values => [description.form.map{|f| f.text.strip }.uniq.join(", ")])
16
- end
17
- unless description.extent.nil? or description.extent.empty?
18
- return_fields << ModsDisplay::Values.new(:label => displayLabel(description) || format_label,
19
- :values => [description.extent.map{|e| e.text }.join(", ")])
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
- private
28
+ private
27
29
 
28
- def decorate_formats(formats)
29
- formats.map do |format|
30
- "<span data-mods-display-format='#{self.class.format_class(format)}'>#{format}</span>"
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
- def self.format_class(format)
35
- return format if format.nil?
36
- format.strip.downcase.gsub(/\/|\\|\s+/, "_")
37
- end
36
+ def self.format_class(format)
37
+ return format if format.nil?
38
+ format.strip.downcase.gsub(%r{/|\\|\s+}, '_')
39
+ end
38
40
 
39
- def format_label
40
- I18n.t('mods_display.format')
41
+ def format_label
42
+ I18n.t('mods_display.format')
43
+ end
41
44
  end
42
- end
45
+ end
@@ -1,15 +1,16 @@
1
- class ModsDisplay::Genre < ModsDisplay::Field
2
-
3
- def fields
4
- return_fields = @values.map do |value|
5
- ModsDisplay::Values.new(:label => displayLabel(value) || label, :values => [value.text.strip.capitalize].flatten)
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
- private
10
+ private
11
11
 
12
- def displayLabel(element)
13
- super(element) || I18n.t('mods_display.genre')
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
- class ModsDisplay::Identifier < ModsDisplay::Field
2
-
3
- def fields
4
- return_fields = @values.map do |value|
5
- ModsDisplay::Values.new(:label => displayLabel(value) || identifier_label(value), :values => [value.text])
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
- private
10
+ private
11
11
 
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}:"
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
- 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')}
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
- class ModsDisplay::Imprint < ModsDisplay::Field
2
- include ModsDisplay::CountryCodes
3
- def fields
4
- return_fields = []
5
- @values.each do |value|
6
- if imprint_display_form(value)
7
- return_fields << imprint_display_form(value)
8
- else
9
- edition = nil
10
- place = nil
11
- publisher = nil
12
- placePub = nil
13
- edition = value.edition.map do |e|
14
- e.text unless e.text.strip.empty?
15
- end.compact.join(" ").strip
16
- place = place_terms(value).map do |p|
17
- p.text unless p.text.strip.empty?
18
- end.compact.join(" : ").strip unless value.place.text.strip.empty?
19
- publisher = value.publisher.map do |p|
20
- p.text unless p.text.strip.empty?
21
- end.compact.join(" : ").strip unless value.publisher.text.strip.empty?
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
- end.flatten.map do |date|
27
- date.strip unless date.strip.empty?
28
- end.compact.join(", ")
29
- edition = nil if edition.strip.empty?
30
- parts = nil if parts.strip.empty?
31
- placePub = [place, publisher].compact.join(" : ")
32
- placePub = nil if placePub.strip.empty?
33
- editionPlace = [edition, placePub].compact.join(" - ")
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
- collapse_fields(return_fields)
49
- end
50
- def dates(element)
51
- date_field_keys.map do |date_field|
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
- unless elements.empty?
55
- ModsDisplay::Values.new(:label => displayLabel(element) || pub_info_labels[elements.first.name.to_sym], :values => parse_dates(elements))
56
- end
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
- end
68
- def process_encoded_dates(date_fields)
69
- date_fields.map do |date_field|
70
- if date_is_w3cdtf?(date_field)
71
- process_w3cdtf_date(date_field)
72
- else
73
- date_field
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
- end
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)
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
- 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
- if date.text == start_date.text
95
- date.content = "#{start_date.text}-"
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
- else
100
- date_fields
114
+ return_fields.map(&:text)
101
115
  end
102
- end
103
- def apply_date_qualifier_decoration(date_fields)
104
- return_fields = date_fields.map do |date|
105
- date = date.clone
106
- if date_is_approximate?(date)
107
- date.content = "[ca. #{date.text}]"
108
- elsif date_is_questionable?(date)
109
- date.content = "[#{date.text}?]"
110
- elsif date_is_inferred?(date)
111
- date.content = "[#{date.text}]"
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
- return_fields.map{|d| d.text }
116
- end
117
- def date_is_approximate?(date_field)
118
- date_field.attributes["qualifier"] and
119
- date_field.attributes["qualifier"].respond_to?(:value) and
120
- date_field.attributes["qualifier"].value == "approximate"
121
- end
122
- def date_is_questionable?(date_field)
123
- date_field.attributes["qualifier"] and
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
- end
143
- def dates_are_range?(date_fields)
144
- attributes = date_fields.map do |date|
145
- if date.attributes["point"].respond_to?(:value)
146
- date.attributes["point"].value
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
- attributes.include?("start") and
150
- attributes.include?("end")
151
- end
152
- def date_is_w3cdtf?(date_field)
153
- date_field.attributes["encoding"] and
154
- date_field.attributes["encoding"].respond_to?(:value) and
155
- date_field.attributes["encoding"].value.downcase == "w3cdtf"
156
- end
157
- def process_w3cdtf_date(date_field)
158
- date_field = date_field.clone
159
- date_field.content = begin
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
- date_field.content
188
+ date_fields
166
189
  end
167
- rescue
168
- date_field.content
169
190
  end
170
- date_field
171
- end
172
- def dedup_dates(date_fields)
173
- date_text = date_fields.map{|d| normalize_date(d.text) }
174
- if date_text != date_text.uniq
175
- if date_fields.find{ |d| d.attributes["qualifier"].respond_to?(:value) }
176
- [date_fields.find{ |d| d.attributes["qualifier"].respond_to?(:value) }]
177
- elsif date_fields.find{ |d| !d.attributes["encoding"] }
178
- [date_fields.find{ |d| !d.attributes["encoding"] }]
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
- [date_fields.first]
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
- end
186
- def normalize_date(date)
187
- date.strip.gsub(/^\[*ca\.\s*|c|\[|\]|\?/, "")
188
- end
189
- def other_pub_info(element)
190
- element.children.select do |child|
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
- end
194
- def place_terms(element)
195
- return [] unless element.respond_to?(:place) and
196
- element.place.respond_to?(:placeTerm)
197
- if unencoded_place_terms?(element)
198
- element.place.placeTerm.select do |term|
199
- !term.attributes["type"].respond_to?(:value) or
200
- term.attributes["type"].value == "text"
201
- end.compact
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
- end
216
- def unencoded_place_terms?(element)
217
- element.place.placeTerm.any? do |term|
218
- !term.attributes["type"].respond_to?(:value) or
219
- term.attributes["type"].value == "text"
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
- end
222
- def imprint_display_form(element)
223
- display_form = element.children.find do |child|
224
- child.name == "displayForm"
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
- private
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
- def pub_info_parts
232
- [:issuance, :frequency]
233
- end
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
- def date_field_keys
236
- [:dateCreated, :dateCaptured, :dateValid, :dateModified, :copyrightDate]
237
- end
275
+ def pub_info_parts
276
+ [:issuance, :frequency]
277
+ end
238
278
 
239
- def pub_info_labels
240
- {:dateCreated => I18n.t('mods_display.date_created'),
241
- :dateCaptured => I18n.t('mods_display.date_captured'),
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
- end
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