mods_display 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,21 @@
1
1
  class ModsDisplay::Cartographics < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return nil if @value.nil?
5
- return_values = []
6
- @value.each do |val|
7
- if val.respond_to?(:cartographics)
8
- val.cartographics.each do |field|
4
+ return nil if @values.nil?
5
+ return_fields = []
6
+ @values.each do |value|
7
+ if value.respond_to?(:cartographics)
8
+ value.cartographics.each do |field|
9
9
  scale = field.scale.empty? ? "Scale not given" : field.scale.text
10
10
  projection = field.projection.empty? ? nil : field.projection.text
11
11
  coordinates = field.coordinates.empty? ? nil : field.coordinates.text
12
12
  post_scale = [projection, coordinates].compact.length > 0 ? [projection, coordinates].compact.join(" ") : nil
13
- return_values << ModsDisplay::Values.new({:label => (displayLabel(field) || label || "Map data"),
13
+ return_fields << ModsDisplay::Values.new({:label => (displayLabel(field) || label || "Map data"),
14
14
  :values => [[scale, post_scale].compact.join(" ; ")]})
15
15
  end
16
16
  end
17
17
  end
18
- return_values
18
+ collapse_fields(return_fields)
19
19
  end
20
20
 
21
21
  end
@@ -5,17 +5,17 @@ class ModsDisplay::Collection < ModsDisplay::Field
5
5
  end
6
6
 
7
7
  def fields
8
- return_values = []
9
- @value.each do |val|
10
- if val.respond_to?(:titleInfo) and
11
- val.respond_to?(:typeOfResource) and
12
- val.typeOfResource.attributes.length > 0 and
13
- val.typeOfResource.attributes.first.has_key?("collection") and
14
- val.typeOfResource.attributes.first["collection"].value == "yes"
15
- return_values << ModsDisplay::Values.new(:label => label, :values => [val.titleInfo.text.strip])
8
+ return_fields = []
9
+ @values.each do |value|
10
+ if value.respond_to?(:titleInfo) and
11
+ value.respond_to?(:typeOfResource) and
12
+ value.typeOfResource.attributes.length > 0 and
13
+ value.typeOfResource.attributes.first.has_key?("collection") and
14
+ value.typeOfResource.attributes.first["collection"].value == "yes"
15
+ return_fields << ModsDisplay::Values.new(:label => label, :values => [value.titleInfo.text.strip])
16
16
  end
17
17
  end
18
- return_values
18
+ collapse_fields(return_fields)
19
19
  end
20
20
 
21
21
  end
@@ -1,38 +1,16 @@
1
1
  class ModsDisplay::Contact < ModsDisplay::Field
2
2
  def fields
3
- return_values = []
4
- current_label = nil
5
- prev_label = nil
6
- buffer = []
7
- contact_fields.each_with_index do |val, index|
8
- current_label = (displayLabel(val) || "Contact")
9
- if contact_fields.length == 1
10
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
11
- elsif index == (contact_fields.length-1)
12
- # need to deal w/ when we have a last element but we have separate labels in the buffer.
13
- if current_label != prev_label
14
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
15
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
16
- else
17
- buffer << val.text
18
- return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
19
- end
20
- elsif prev_label and (current_label != prev_label)
21
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
22
- buffer = []
23
- end
24
- buffer << val.text
25
- prev_label = current_label
3
+ return_fields = contact_fields.map do |value|
4
+ ModsDisplay::Values.new(:label => displayLabel(value) || "Contact", :values => [value.text])
26
5
  end
27
- return_values
6
+ collapse_fields(return_fields)
28
7
  end
29
8
 
30
-
31
9
  private
32
10
  def contact_fields
33
- @value.select do |val|
34
- val.attributes["type"].respond_to?(:value) and
35
- val.attributes["type"].value.downcase == "contact"
11
+ @values.select do |value|
12
+ value.attributes["type"].respond_to?(:value) and
13
+ value.attributes["type"].value.downcase == "contact"
36
14
  end
37
15
  end
38
16
 
@@ -1,31 +1,10 @@
1
1
  class ModsDisplay::Description < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return_values = []
5
- current_label = nil
6
- prev_label = nil
7
- buffer = []
8
- description_fields.each_with_index do |val, index|
9
- current_label = description_label(val)
10
- if description_fields.length == 1
11
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
12
- elsif index == (description_fields.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
4
+ return_fields = description_fields.map do |value|
5
+ ModsDisplay::Values.new(:label => description_label(value), :values => [value.text])
27
6
  end
28
- return_values
7
+ collapse_fields(return_fields)
29
8
  end
30
9
 
31
10
  def description_label(element)
@@ -35,7 +14,7 @@ class ModsDisplay::Description < ModsDisplay::Field
35
14
  private
36
15
 
37
16
  def description_fields
38
- @value.children.select do |child|
17
+ @values.children.select do |child|
39
18
  labels.keys.include?(child.name.to_sym)
40
19
  end
41
20
  end
@@ -1,50 +1,21 @@
1
1
  # encoding: utf-8
2
2
  class ModsDisplay::Field
3
- def initialize(value, config, klass)
4
- @value = value
3
+ def initialize(values, config, klass)
4
+ @values = values
5
5
  @config = config
6
6
  @klass = klass
7
7
  end
8
8
 
9
9
  def fields
10
- return_values = []
11
- current_label = nil
12
- prev_label = nil
13
- buffer = []
14
- @value.each_with_index do |val, index|
15
- current_label = displayLabel(val)
16
- current_text = (text || val.text).strip
17
- if @value.length == 1
18
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
19
- elsif index == (@value.length-1)
20
- # need to deal w/ when we have a last element but we have separate labels in the buffer.
21
- if current_label != prev_label
22
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
23
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [current_text])
24
- else
25
- buffer << current_text
26
- return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
27
- end
28
- elsif prev_label and (current_label != prev_label)
29
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
30
- buffer = []
31
- end
32
- buffer << current_text
33
- prev_label = current_label
10
+ return_fields = @values.map do |value|
11
+ ModsDisplay::Values.new(:label => displayLabel(value) || label, :values => [displayForm(@values) || value.text].flatten)
34
12
  end
35
- return_values
13
+ collapse_fields(return_fields)
36
14
  end
37
15
 
38
16
  def label
39
- return nil if @value.nil?
40
- displayLabel(@value.first)
41
- end
42
-
43
- def text
44
- return nil if @value.nil?
45
- if displayForm(@value)
46
- displayForm(@value).text
47
- end
17
+ return nil if @values.nil?
18
+ displayLabel(@values.first)
48
19
  end
49
20
 
50
21
  def to_html
@@ -78,7 +49,9 @@ class ModsDisplay::Field
78
49
  end
79
50
 
80
51
  def displayForm(element)
81
- element.children.find{|c| c.name == "displayForm"}
52
+ return element unless element # basically return nil
53
+ display = element.children.find{|c| c.name == "displayForm"}
54
+ return display.text if display
82
55
  end
83
56
 
84
57
  def displayLabel(element)
@@ -131,4 +104,33 @@ class ModsDisplay::Field
131
104
  val
132
105
  end
133
106
 
107
+ def collapse_fields(display_fields)
108
+ return_values = []
109
+ current_label = nil
110
+ prev_label = nil
111
+ buffer = []
112
+ display_fields.each_with_index do |field, index|
113
+ current_label = field.label
114
+ current_values = field.values
115
+ if display_fields.length == 1
116
+ return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
117
+ elsif index == (display_fields.length-1)
118
+ # need to deal w/ when we have a last element but we have separate labels in the buffer.
119
+ if current_label != prev_label
120
+ return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
121
+ return_values << ModsDisplay::Values.new(:label => current_label, :values => current_values)
122
+ else
123
+ buffer.concat(current_values)
124
+ return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
125
+ end
126
+ elsif prev_label and (current_label != prev_label)
127
+ return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
128
+ buffer = []
129
+ end
130
+ buffer.concat(current_values)
131
+ prev_label = current_label
132
+ end
133
+ return_values
134
+ end
135
+
134
136
  end
@@ -1,14 +1,11 @@
1
1
  class ModsDisplay::Format < ModsDisplay::Field
2
2
 
3
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?
4
+ return [] if @values.text.strip.empty?
5
+ return_fields = @values.map do |value|
6
+ ModsDisplay::Values.new(:label => displayLabel(value) || "Format", :values => [displayForm(value) || value.text])
7
+ end
8
+ collapse_fields(return_fields)
12
9
  end
13
10
 
14
11
  def to_html
@@ -1,42 +1,21 @@
1
1
  class ModsDisplay::Identifier < ModsDisplay::Field
2
-
2
+
3
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
4
+ return_fields = @values.map do |value|
5
+ ModsDisplay::Values.new(:label => displayLabel(value) || identifier_label(value), :values => [value.text])
27
6
  end
28
- return_values
7
+ collapse_fields(return_fields)
29
8
  end
30
-
9
+
31
10
  private
32
-
11
+
33
12
  def identifier_label(element)
34
13
  if element.attributes["type"].respond_to?(:value)
35
14
  return identifier_labels[element.attributes["type"].value] || element.attributes["type"].value
36
15
  end
37
16
  "Identifier"
38
17
  end
39
-
18
+
40
19
  def identifier_labels
41
20
  {"local" => "Identifier",
42
21
  "isbn" => "ISBN",
@@ -1,27 +1,27 @@
1
1
  class ModsDisplay::Imprint < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return_values = []
5
- @value.each do |val|
6
- if imprint_display_form(val)
7
- return_values << imprint_display_form(val)
4
+ return_fields = []
5
+ @values.each do |value|
6
+ if imprint_display_form(value)
7
+ return_fields << imprint_display_form(value)
8
8
  else
9
9
  edition = nil
10
10
  place = nil
11
11
  publisher = nil
12
12
  placePub = nil
13
- edition = val.edition.map do |e|
13
+ edition = value.edition.map do |e|
14
14
  e.text unless e.text.strip.empty?
15
15
  end.compact.join(" ").strip
16
- place = val.place.map do |p|
16
+ place = value.place.map do |p|
17
17
  p.text unless p.text.strip.empty?
18
- end.compact.join(" : ").strip unless val.place.text.strip.empty?
19
- publisher = val.publisher.map do |p|
18
+ end.compact.join(" : ").strip unless value.place.text.strip.empty?
19
+ publisher = value.publisher.map do |p|
20
20
  p.text unless p.text.strip.empty?
21
- end.compact.join(" : ").strip unless val.publisher.text.strip.empty?
21
+ end.compact.join(" : ").strip unless value.publisher.text.strip.empty?
22
22
  parts = ["dateIssued", "dateOther"].map do |date_field_name|
23
- if val.respond_to?(date_field_name.to_sym)
24
- parse_dates(val.send(date_field_name.to_sym))
23
+ if value.respond_to?(date_field_name.to_sym)
24
+ parse_dates(value.send(date_field_name.to_sym))
25
25
  end
26
26
  end.flatten.map do |date|
27
27
  date.strip unless date.strip.empty?
@@ -33,19 +33,19 @@ class ModsDisplay::Imprint < ModsDisplay::Field
33
33
  editionPlace = [edition, placePub].compact.join(" - ")
34
34
  editionPlace = nil if editionPlace.strip.empty?
35
35
  unless [editionPlace, parts].compact.join(", ").strip.empty?
36
- return_values << ModsDisplay::Values.new(:label => displayLabel(val) || "Imprint", :values => [[editionPlace, parts].compact.join(", ")])
36
+ return_fields << ModsDisplay::Values.new(:label => displayLabel(value) || "Imprint", :values => [[editionPlace, parts].compact.join(", ")])
37
37
  end
38
- if dates(val).length > 0
39
- return_values.concat(dates(val))
38
+ if dates(value).length > 0
39
+ return_fields.concat(dates(value))
40
40
  end
41
- if other_pub_info(val).length > 0
42
- other_pub_info(val).each do |pub_info|
43
- return_values << ModsDisplay::Values.new(:label => displayLabel(val) || pub_info_labels[pub_info.name.to_sym], :values => [pub_info.text.strip])
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])
44
44
  end
45
45
  end
46
46
  end
47
47
  end
48
- return_values
48
+ collapse_fields(return_fields)
49
49
  end
50
50
  def dates(element)
51
51
  date_field_keys.map do |date_field|
@@ -1,27 +1,15 @@
1
1
  class ModsDisplay::Language < ModsDisplay::Field
2
- def label
3
- return super unless super.nil?
4
- "Language"
5
- end
6
-
7
2
  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]
3
+ return_fields = @values.map do |value|
4
+ if value.respond_to?(:languageTerm)
5
+ value.languageTerm.map do |term|
6
+ if term.attributes["type"].respond_to?(:value) and term.attributes["type"].value == "code"
7
+ ModsDisplay::Values.new(:label => displayLabel(value) || displayLabel(term) || "Language", :values => [displayForm(value) || language_codes[term.text]].flatten)
8
+ end
9
+ end.flatten.compact
16
10
  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
11
+ end.flatten.compact
12
+ collapse_fields(return_fields)
25
13
  end
26
14
 
27
15
  private
@@ -1,47 +1,26 @@
1
1
  class ModsDisplay::Name < ModsDisplay::Field
2
2
 
3
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 = []
4
+ return_fields = @values.map do |value|
11
5
  role = nil
12
- if val.role.length > 0 and val.role.roleTerm.length > 0
13
- role = val.role.roleTerm.find do |term|
6
+ person = nil
7
+ if value.role.length > 0 and value.role.roleTerm.length > 0
8
+ role = value.role.roleTerm.find do |term|
14
9
  term.attributes["type"].respond_to?(:value) and
15
10
  term.attributes["type"].value == "text"
16
11
  end
17
12
  end
18
- if val.displayForm.length > 0
19
- people << ModsDisplay::Name::Person.new(:name => val.displayForm.text, :role => role)
13
+ if value.displayForm.length > 0
14
+ person = ModsDisplay::Name::Person.new(:name => value.displayForm.text, :role => role)
20
15
  else
21
- name_parts = val.namePart.map do |name_part|
16
+ name_parts = value.namePart.map do |name_part|
22
17
  name_part.text
23
18
  end.join(", ")
24
- people << ModsDisplay::Name::Person.new(:name => name_parts, :role => role) unless name_parts.empty?
19
+ person = ModsDisplay::Name::Person.new(:name => name_parts, :role => role) unless name_parts.empty?
25
20
  end
26
- if @value.length == 1
27
- return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten) unless people.empty?
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) unless buffer.flatten.empty?
32
- return_values << ModsDisplay::Values.new(:label => current_label, :values => people.flatten) unless people.empty?
33
- else
34
- buffer << people
35
- return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten) unless buffer.flatten.empty?
36
- end
37
- elsif prev_label and (current_label != prev_label)
38
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten) unless buffer.flatten.empty?
39
- buffer = []
40
- end
41
- buffer << people
42
- prev_label = current_label
43
- end
44
- return_values
21
+ ModsDisplay::Values.new(:label => displayLabel(value) || name_label(value), :values => [person]) if person
22
+ end.compact
23
+ collapse_fields(return_fields)
45
24
  end
46
25
 
47
26
  def to_html
@@ -1,41 +1,20 @@
1
1
  class ModsDisplay::Note < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return_values = []
5
- current_label = nil
6
- prev_label = nil
7
- buffer = []
8
- note_fields.each_with_index do |val, index|
9
- current_label = (displayLabel(val) || note_label(val))
10
- if note_fields.length == 1
11
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
12
- elsif index == (note_fields.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
4
+ return_fields = note_fields.map do |value|
5
+ ModsDisplay::Values.new(:label => displayLabel(value) || note_label(value), :values => [value.text])
27
6
  end
28
- return_values
7
+ collapse_fields(return_fields)
29
8
  end
30
9
 
31
10
 
32
11
  private
33
12
 
34
13
  def note_fields
35
- @value.select do |val|
36
- (!val.attributes["type"].respond_to?(:value) or
37
- (val.attributes["type"].respond_to?(:value) and
38
- val.attributes["type"].value.downcase != "contact"))
14
+ @values.select do |value|
15
+ (!value.attributes["type"].respond_to?(:value) or
16
+ (value.attributes["type"].respond_to?(:value) and
17
+ value.attributes["type"].value.downcase != "contact"))
39
18
  end
40
19
  end
41
20
 
@@ -1,47 +1,25 @@
1
1
  class ModsDisplay::RelatedItem < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return_values = []
5
- current_label = nil
6
- prev_label = nil
7
- buffer = []
8
- return_text = ""
9
- @value.each_with_index do |val, index|
10
- current_label = (displayLabel(val) || "Related item")
11
- unless (val.typeOfResource.length > 0 and
12
- val.typeOfResource.attributes.length > 0 and
13
- val.typeOfResource.attributes.first.has_key?("collection") and
14
- val.typeOfResource.attributes.first["collection"].value == "yes")
15
- if val.titleInfo.length > 0
16
- title = val.titleInfo.text.strip
4
+ return_fields = @values.map do |value|
5
+ unless (value.typeOfResource.length > 0 and
6
+ value.typeOfResource.attributes.length > 0 and
7
+ value.typeOfResource.attributes.first.has_key?("collection") and
8
+ value.typeOfResource.attributes.first["collection"].value == "yes")
9
+ if value.titleInfo.length > 0
10
+ title = value.titleInfo.text.strip
17
11
  return_text = title
18
12
  location = nil
19
- location = val.location.url.text if (val.location.length > 0 and
20
- val.location.url.length > 0)
13
+ location = value.location.url.text if (value.location.length > 0 and
14
+ value.location.url.length > 0)
21
15
  return_text = "<a href='#{location}'>#{title}</a>" if location and !title.empty?
22
- end
23
- unless return_text.empty?
24
- if @value.length == 1
25
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
26
- elsif index == (@value.length-1)
27
- # need to deal w/ when we have a last element but we have separate labels in the buffer.
28
- if current_label != prev_label
29
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
30
- return_values << ModsDisplay::Values.new(:label => current_label, :values => [return_text])
31
- else
32
- buffer << return_text
33
- return_values << ModsDisplay::Values.new(:label => current_label, :values => buffer.flatten)
34
- end
35
- elsif prev_label and (current_label != prev_label)
36
- return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
37
- buffer = []
16
+ unless return_text.empty?
17
+ ModsDisplay::Values.new(:label => displayLabel(value) || "Related item", :values => [return_text])
38
18
  end
39
- buffer << return_text
40
- prev_label = current_label
41
19
  end
42
20
  end
43
- end
44
- return_values
21
+ end.compact
22
+ collapse_fields(return_fields)
45
23
  end
46
24
 
47
25
  end
@@ -1,13 +1,12 @@
1
1
  class ModsDisplay::RelatedLocation < ModsDisplay::Field
2
2
 
3
3
  def fields
4
- return_values = []
5
- @value.each do |val|
6
- if val.location.length > 0 and val.titleInfo.length < 1
7
- return_values << ModsDisplay::Values.new(:label => displayLabel(val), :values => [val.location.text.strip])
4
+ return_fields = @values.map do |value|
5
+ if value.location.length > 0 and value.titleInfo.length < 1
6
+ ModsDisplay::Values.new(:label => displayLabel(value), :values => [value.location.text.strip])
8
7
  end
9
- end
10
- return_values
8
+ end.compact
9
+ collapse_fields(return_fields)
11
10
  end
12
11
 
13
12
  def displayLabel(element)
@@ -1,5 +1,5 @@
1
1
  class ModsDisplay::SubTitle < ModsDisplay::Field
2
2
  def fields
3
- ModsDisplay::Title.new(@value[1, @value.length], @config, @klass).fields
3
+ ModsDisplay::Title.new(@values[1, @values.length], @config, @klass).fields
4
4
  end
5
5
  end
@@ -2,9 +2,9 @@ class ModsDisplay::Subject < ModsDisplay::Field
2
2
 
3
3
  def fields
4
4
  return_values = []
5
- @value.each do |val|
5
+ @values.each do |value|
6
6
  return_text = []
7
- selected_subjects(val).each do |child|
7
+ selected_subjects(value).each do |child|
8
8
  if self.respond_to?(:"process_#{child.name}")
9
9
  return_text << self.send(:"process_#{child.name}", child) unless self.send(:"process_#{child.name}", child).to_s.empty?
10
10
  else
@@ -1,29 +1,28 @@
1
1
  class ModsDisplay::Title < ModsDisplay::Field
2
2
 
3
-
4
3
  def fields
5
4
  return_values = []
6
- @value.each do |val|
7
- if displayForm(val)
8
- return_values << ModsDisplay::Values.new(:label => displayLabel(val) || title_label(val), :values => [displayForm(val).text])
5
+ @values.each do |value|
6
+ if displayForm(value)
7
+ return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [displayForm(value)])
9
8
  else
10
9
  nonSort = nil
11
10
  title = nil
12
11
  subTitle = nil
13
- nonSort = val.nonSort.text.strip unless val.nonSort.text.strip.empty?
14
- title = val.title.text.strip unless val.title.text.strip.empty?
15
- subTitle = val.subTitle.text unless val.subTitle.text.strip.empty?
12
+ nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
13
+ title = value.title.text.strip unless value.title.text.strip.empty?
14
+ subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
16
15
  preSubTitle = [nonSort, title].compact.join(" ")
17
16
  preSubTitle = nil if preSubTitle.strip.empty?
18
17
  preParts = [preSubTitle, subTitle].compact.join(" : ")
19
18
  preParts = nil if preParts.strip.empty?
20
- parts = val.children.select do |child|
19
+ parts = value.children.select do |child|
21
20
  ["partName", "partNumber"].include?(child.name)
22
21
  end.map do |child|
23
22
  child.text
24
- end.compact.join(parts_delimiter(val))
23
+ end.compact.join(parts_delimiter(value))
25
24
  parts = nil if parts.strip.empty?
26
- return_values << ModsDisplay::Values.new(:label => displayLabel(val) || title_label(val), :values => [[preParts, parts].compact.join(". ")])
25
+ return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [[preParts, parts].compact.join(". ")])
27
26
  end
28
27
  end
29
28
  return_values
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -42,7 +42,7 @@ describe ModsDisplay::Imprint do
42
42
  mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint", "Date captured", "Issuance"]
43
43
  end
44
44
  it "should use the displayLabel when available" do
45
- mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "IssuanceLabel", "IssuanceLabel"]
45
+ mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "IssuanceLabel"]
46
46
  end
47
47
  end
48
48
 
@@ -13,14 +13,6 @@ describe ModsDisplay::Language do
13
13
  @multi = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm type='code'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
14
14
  @display_form = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm>zzzxxx</languageTerm><displayForm>Klingon</displayForm></language></mods>", false).language
15
15
  end
16
- describe "label" do
17
- it "should default to Language when no displayLabel is available" do
18
- mods_display_language(@language).label.should == "Language"
19
- end
20
- it "should use the displayLabel attribute when present" do
21
- mods_display_language(@display_label).label.should == "Lang"
22
- end
23
- end
24
16
  describe "fields" do
25
17
  it "should return an array with a label/values object" do
26
18
  values = mods_display_language(@display_label).fields
@@ -40,16 +32,4 @@ describe ModsDisplay::Language do
40
32
  values.first.values.should == ["German", "English"]
41
33
  end
42
34
  end
43
- describe "text" do
44
- it "should return the language code translation" do
45
- mods_display_language(@language).text.should == "English"
46
- end
47
- it "should return the code if the languages table does not have a translation" do
48
- mods_display_language(@no_lang).text.should == "zzzxxx"
49
- end
50
- it "should return a displayForm if there is one" do
51
- mods_display_language(@display_form).text.should == "Klingon"
52
- end
53
- end
54
-
55
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-01 00:00:00.000000000 Z
12
+ date: 2013-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stanford-mods
@@ -151,7 +151,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
151
  version: '0'
152
152
  segments:
153
153
  - 0
154
- hash: -3367910035276828963
154
+ hash: -3982244066691895178
155
155
  required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  none: false
157
157
  requirements:
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: -3367910035276828963
163
+ hash: -3982244066691895178
164
164
  requirements: []
165
165
  rubyforge_project:
166
166
  rubygems_version: 1.8.25