mods_display 0.0.1.beta6 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.md +28 -2
  2. data/lib/mods_display.rb +6 -0
  3. data/lib/mods_display/configuration.rb +15 -3
  4. data/lib/mods_display/configuration/base.rb +8 -0
  5. data/lib/mods_display/configuration/name.rb +5 -0
  6. data/lib/mods_display/configuration/note.rb +5 -0
  7. data/lib/mods_display/configuration/related_item.rb +5 -0
  8. data/lib/mods_display/fields/abstract.rb +3 -2
  9. data/lib/mods_display/fields/audience.rb +3 -2
  10. data/lib/mods_display/fields/cartographics.rb +1 -1
  11. data/lib/mods_display/fields/contact.rb +39 -0
  12. data/lib/mods_display/fields/contents.rb +3 -2
  13. data/lib/mods_display/fields/description.rb +2 -2
  14. data/lib/mods_display/fields/field.rb +1 -4
  15. data/lib/mods_display/fields/format.rb +1 -0
  16. data/lib/mods_display/fields/genre.rb +9 -0
  17. data/lib/mods_display/fields/identifier.rb +6 -6
  18. data/lib/mods_display/fields/imprint.rb +3 -3
  19. data/lib/mods_display/fields/name.rb +3 -3
  20. data/lib/mods_display/fields/note.rb +17 -8
  21. data/lib/mods_display/fields/related_item.rb +2 -1
  22. data/lib/mods_display/fields/resource_type.rb +7 -0
  23. data/lib/mods_display/fields/subject.rb +1 -1
  24. data/lib/mods_display/fields/title.rb +4 -4
  25. data/lib/mods_display/html.rb +5 -2
  26. data/lib/mods_display/version.rb +1 -1
  27. data/spec/configuration/base_spec.rb +10 -0
  28. data/spec/fields/abstract_spec.rb +8 -0
  29. data/spec/fields/contact_spec.rb +21 -0
  30. data/spec/fields/contents_spec.rb +1 -1
  31. data/spec/fields/description_spec.rb +1 -1
  32. data/spec/fields/genre_spec.rb +24 -0
  33. data/spec/fields/identifier_spec.rb +2 -2
  34. data/spec/fields/imprint_spec.rb +1 -1
  35. data/spec/fields/note_spec.rb +11 -5
  36. data/spec/fields/related_item_spec.rb +2 -2
  37. data/spec/fields/resource_type_spec.rb +22 -0
  38. data/spec/fields/title_spec.rb +1 -1
  39. data/spec/integration/configuration_spec.rb +7 -2
  40. metadata +22 -7
data/README.md CHANGED
@@ -24,7 +24,7 @@ Include the `ModelExtension` into your model.
24
24
  include ModsDisplay::ModelExtension
25
25
  end
26
26
 
27
- Configure the source of the MODS xml string
27
+ Configure the source of the MODS XML in your model. You can pass a string of XML to the mods_xml_source method, however it will also accept a block where you can call methods on self (so if the MODS XML string is held in MyClass#mods):
28
28
 
29
29
  class MyClass
30
30
  ....
@@ -56,6 +56,7 @@ In the class that you include the `ModsDisplay::ControllerExtension` you can con
56
56
 
57
57
  * label_class
58
58
  * value_class
59
+ * ignore!
59
60
  * delimiter
60
61
  * link
61
62
 
@@ -74,6 +75,20 @@ Both label_ and value_class accept strings to put in as a class.
74
75
  end
75
76
  end
76
77
 
78
+ ### Ignore!
79
+
80
+ In certain cases an application may need to explicitly remove a portion of the MODS metadata from the display (Contact being a prime example). You can accomplish this by using the ignore! option.
81
+
82
+ class MyController
83
+ include ModsDisplay::ControllerExtension
84
+
85
+ configure_mods_display do
86
+ contact do
87
+ ignore!
88
+ end
89
+ end
90
+ end
91
+
77
92
  ### Delimiter
78
93
 
79
94
  The delimiter configuration option accepts a string which will be used to delimit multiple multiple values within a single label.
@@ -84,7 +99,7 @@ The delimiter configuration option accepts a string which will be used to delimi
84
99
  end
85
100
  end
86
101
 
87
- Note: The default is a comma and a space (", ")
102
+ Note: Different MODS elements will have different default delimiters (mainly varying between a comma+space or a HTML line-break).
88
103
 
89
104
  ### Link
90
105
 
@@ -126,6 +141,17 @@ Once installed, the class that included the `ControllerExtension` (`MyController
126
141
 
127
142
  render_mods_display(@model) # where @model.is_a?(MyClass)
128
143
 
144
+ The basic render call will return the top-level ModsDisplay::HTML class object. Any String method (e.g. #html_safe) you call on this top-level object will be sent down to the #to_html method which will return the HTML for all the metadata in the MODS document.
145
+
146
+ render_mods_display(@model).to_html
147
+
148
+ You can abstract the main title by calling #title on the top-level HTML method
149
+
150
+ render_mods_display(@model).title
151
+
152
+ When getting JUST the main title out of the metadata, it will be useful to get the rest of the metadata without the main title. You can accomplish this by calling #body on the top-level HTML object.
153
+
154
+ render_mods_display(@model).body
129
155
 
130
156
  ## Contributing
131
157
 
@@ -4,15 +4,20 @@ require "mods_display/html"
4
4
  require "mods_display/model_extension"
5
5
  require "mods_display/configuration"
6
6
  require "mods_display/configuration/base"
7
+ require "mods_display/configuration/name"
8
+ require "mods_display/configuration/note"
9
+ require "mods_display/configuration/related_item"
7
10
  require "mods_display/configuration/subject"
8
11
  require "mods_display/fields/field"
9
12
  require "mods_display/fields/abstract"
10
13
  require "mods_display/fields/audience"
11
14
  require "mods_display/fields/collection"
15
+ require "mods_display/fields/contact"
12
16
  require "mods_display/fields/contents"
13
17
  require "mods_display/fields/cartographics"
14
18
  require "mods_display/fields/description"
15
19
  require "mods_display/fields/format"
20
+ require "mods_display/fields/genre"
16
21
  require "mods_display/fields/identifier"
17
22
  require "mods_display/fields/imprint"
18
23
  require "mods_display/fields/language"
@@ -21,6 +26,7 @@ require "mods_display/fields/name"
21
26
  require "mods_display/fields/note"
22
27
  require "mods_display/fields/related_item"
23
28
  require "mods_display/fields/related_location"
29
+ require "mods_display/fields/resource_type"
24
30
  require "mods_display/fields/subject"
25
31
  require "mods_display/fields/sub_title"
26
32
  require "mods_display/fields/title"
@@ -14,7 +14,15 @@ class ModsDisplay::Configuration
14
14
  end
15
15
 
16
16
  def name &name
17
- @name ||= ModsDisplay::Configuration::Base.new(&name || Proc.new{})
17
+ @name ||= ModsDisplay::Configuration::Name.new(&name || Proc.new{})
18
+ end
19
+
20
+ def type_of_resource &type_of_resource
21
+ @type_of_resource ||= ModsDisplay::Configuration::Base.new(&type_of_resource || Proc.new{})
22
+ end
23
+
24
+ def genre &genre
25
+ @genre ||= ModsDisplay::Configuration::Base.new(&genre || Proc.new{})
18
26
  end
19
27
 
20
28
  def format &format
@@ -50,7 +58,11 @@ class ModsDisplay::Configuration
50
58
  end
51
59
 
52
60
  def note &note
53
- @note ||= ModsDisplay::Configuration::Base.new(&note || Proc.new{})
61
+ @note ||= ModsDisplay::Configuration::Note.new(&note || Proc.new{})
62
+ end
63
+
64
+ def contact &contact
65
+ @contact ||= ModsDisplay::Configuration::Base.new(&contact || Proc.new{})
54
66
  end
55
67
 
56
68
  def collection &collection
@@ -62,7 +74,7 @@ class ModsDisplay::Configuration
62
74
  end
63
75
 
64
76
  def related_item &related_item
65
- @related_item ||= ModsDisplay::Configuration::Base.new(&related_item || Proc.new{})
77
+ @related_item ||= ModsDisplay::Configuration::RelatedItem.new(&related_item || Proc.new{})
66
78
  end
67
79
 
68
80
  def subject &subject
@@ -20,4 +20,12 @@ class ModsDisplay::Configuration::Base
20
20
  @link ||= [method_name, args]
21
21
  end
22
22
 
23
+ def ignore!
24
+ @ignore = true
25
+ end
26
+
27
+ def ignore?
28
+ @ignore || false
29
+ end
30
+
23
31
  end
@@ -0,0 +1,5 @@
1
+ class ModsDisplay::Configuration::Name < ModsDisplay::Configuration::Base
2
+ def delimiter delimiter="<br/>"
3
+ @delimiter ||= delimiter
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ModsDisplay::Configuration::Note < ModsDisplay::Configuration::Base
2
+ def delimiter delimiter="<br/>"
3
+ @delimiter ||= delimiter
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ModsDisplay::Configuration::RelatedItem < ModsDisplay::Configuration::Base
2
+ def delimiter delimiter="<br/>"
3
+ @delimiter ||= delimiter
4
+ end
5
+ end
@@ -1,7 +1,8 @@
1
1
  class ModsDisplay::Abstract < ModsDisplay::Field
2
2
 
3
- def label
4
- super || "Abstract"
3
+ private
4
+ def displayLabel(element)
5
+ super(element) || "Abstract"
5
6
  end
6
7
 
7
8
  end
@@ -1,7 +1,8 @@
1
1
  class ModsDisplay::Audience < ModsDisplay::Field
2
2
 
3
- def label
4
- super || "Target audience"
3
+ private
4
+ def displayLabel(element)
5
+ super(element) || "Target audience"
5
6
  end
6
7
 
7
8
  end
@@ -10,7 +10,7 @@ class ModsDisplay::Cartographics < ModsDisplay::Field
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_values << ModsDisplay::Values.new({:label => (displayLabel(field) || label || "Map data"),
14
14
  :values => [[scale, post_scale].compact.join(" ; ")]})
15
15
  end
16
16
  end
@@ -0,0 +1,39 @@
1
+ class ModsDisplay::Contact < ModsDisplay::Field
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
26
+ end
27
+ return_values
28
+ end
29
+
30
+
31
+ private
32
+ def contact_fields
33
+ @value.select do |val|
34
+ val.attributes["type"].respond_to?(:value) and
35
+ val.attributes["type"].value.downcase == "contact"
36
+ end
37
+ end
38
+
39
+ end
@@ -1,7 +1,8 @@
1
1
  class ModsDisplay::Contents < ModsDisplay::Field
2
2
 
3
- def label
4
- super || "Table of Contents"
3
+ private
4
+ def displayLabel(element)
5
+ super(element) || "Table of contents"
5
6
  end
6
7
 
7
8
  end
@@ -29,7 +29,7 @@ class ModsDisplay::Description < ModsDisplay::Field
29
29
  end
30
30
 
31
31
  def description_label(element)
32
- label || displayLabel(element) || labels[element.name.to_sym] || "Physical Description"
32
+ label || displayLabel(element) || labels[element.name.to_sym] || "Physical description"
33
33
  end
34
34
 
35
35
  private
@@ -43,7 +43,7 @@ class ModsDisplay::Description < ModsDisplay::Field
43
43
  def labels
44
44
  {:form => "Form",
45
45
  :extent => "Extent",
46
- :digitalOrigin => "Digital Origin",
46
+ :digitalOrigin => "Digital origin",
47
47
  :note => "Note"
48
48
  }
49
49
  end
@@ -33,9 +33,6 @@ class ModsDisplay::Field
33
33
  prev_label = current_label
34
34
  end
35
35
  return_values
36
- @value.map do |val|
37
- ModsDisplay::Values.new(:label => displayLabel(val) || label, :values => [text || val.text].flatten)
38
- end
39
36
  end
40
37
 
41
38
  def label
@@ -51,7 +48,7 @@ class ModsDisplay::Field
51
48
  end
52
49
 
53
50
  def to_html
54
- return nil if fields.empty?
51
+ return nil if fields.empty? or @config.ignore?
55
52
  output = ""
56
53
  fields.each do |field|
57
54
  if field.values.any?{|f| !f.empty? }
@@ -12,6 +12,7 @@ class ModsDisplay::Format < ModsDisplay::Field
12
12
  end
13
13
 
14
14
  def to_html
15
+ return nil if @config.ignore?
15
16
  output = ""
16
17
  fields.each do |field|
17
18
  output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
@@ -0,0 +1,9 @@
1
+ class ModsDisplay::Genre < ModsDisplay::Field
2
+
3
+
4
+ private
5
+
6
+ def displayLabel(element)
7
+ super(element) || "Genre"
8
+ end
9
+ end
@@ -46,15 +46,15 @@ class ModsDisplay::Identifier < ModsDisplay::Field
46
46
  "hdl" => "Handle",
47
47
  "isrc" => "ISRC",
48
48
  "ismn" => "ISMN",
49
- "issue number" => "Issue Number",
49
+ "issue number" => "Issue number",
50
50
  "lccn" => "LCCN",
51
- "matrix number" => "Matrix Number",
52
- "music publisher" => "Music Publisher",
53
- "music plate" => "Music Plate",
51
+ "matrix number" => "Matrix number",
52
+ "music publisher" => "Music publisher",
53
+ "music plate" => "Music plate",
54
54
  "sici" => "SICI",
55
55
  "upc" => "UPC",
56
- "videorecording identifier" => "Videorecording Identifier",
57
- "stock number" => "Stock Number"}
56
+ "videorecording identifier" => "Videorecording identifier",
57
+ "stock number" => "Stock number"}
58
58
  end
59
59
 
60
60
  end
@@ -56,9 +56,9 @@ class ModsDisplay::Imprint < ModsDisplay::Field
56
56
  end
57
57
 
58
58
  def pub_info_labels
59
- {:dateValid => "Date Valid",
60
- :dateModified => "Date Modified",
61
- :copyrightDate => "Copyright Date",
59
+ {:dateValid => "Date valid",
60
+ :dateModified => "Date modified",
61
+ :copyrightDate => "Copyright date",
62
62
  :edition => "Edition",
63
63
  :issuance => "Issuance",
64
64
  :frequency => "Frequency"
@@ -45,7 +45,7 @@ class ModsDisplay::Name < ModsDisplay::Field
45
45
  end
46
46
 
47
47
  def to_html
48
- return nil if fields.empty?
48
+ return nil if fields.empty? or @config.ignore?
49
49
  output = ""
50
50
  fields.each do |field|
51
51
  output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
@@ -87,9 +87,9 @@ class ModsDisplay::Name < ModsDisplay::Field
87
87
 
88
88
  def name_labels
89
89
  {"personal" => "Author/Creator",
90
- "corporate" => "Corporate Author",
90
+ "corporate" => "Corporate author",
91
91
  "conference" => "Meeting",
92
- "family" => "Family Author"}
92
+ "family" => "Family author"}
93
93
  end
94
94
 
95
95
  class Person
@@ -5,11 +5,11 @@ class ModsDisplay::Note < ModsDisplay::Field
5
5
  current_label = nil
6
6
  prev_label = nil
7
7
  buffer = []
8
- @value.each_with_index do |val, index|
8
+ note_fields.each_with_index do |val, index|
9
9
  current_label = (displayLabel(val) || note_label(val))
10
- if @value.length == 1
10
+ if note_fields.length == 1
11
11
  return_values << ModsDisplay::Values.new(:label => current_label, :values => [val.text])
12
- elsif index == (@value.length-1)
12
+ elsif index == (note_fields.length-1)
13
13
  # need to deal w/ when we have a last element but we have separate labels in the buffer.
14
14
  if current_label != prev_label
15
15
  return_values << ModsDisplay::Values.new(:label => prev_label, :values => buffer.flatten)
@@ -30,17 +30,26 @@ class ModsDisplay::Note < ModsDisplay::Field
30
30
 
31
31
 
32
32
  private
33
-
33
+
34
+ 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"))
39
+ end
40
+ end
41
+
34
42
  def note_label(element)
35
43
  if element.attributes["type"].respond_to?(:value)
36
- return note_labels[element.attributes["type"].value] || element.attributes["type"].value
44
+ return note_labels[element.attributes["type"].value] || element.attributes["type"].value.capitalize
37
45
  end
38
46
  "Note"
39
47
  end
40
-
48
+
41
49
  def note_labels
42
- {"statement of responsibility" => "Statement of Responsibility",
43
- "date/sequential designation" => "Date/Sequential Designation",
50
+ {"statement of responsibility" => "Statement of responsibility",
51
+ "date/sequential designation" => "Date/Sequential designation",
52
+ "publications" => "Publications",
44
53
  "references" => "References",
45
54
  "bibliography" => "Bibliography",
46
55
  "preferred citation" => "Preferred citation"}
@@ -5,8 +5,9 @@ class ModsDisplay::RelatedItem < ModsDisplay::Field
5
5
  current_label = nil
6
6
  prev_label = nil
7
7
  buffer = []
8
+ return_text = ""
8
9
  @value.each_with_index do |val, index|
9
- current_label = (displayLabel(val) || "Related Item")
10
+ current_label = (displayLabel(val) || "Related item")
10
11
  unless (val.typeOfResource.length > 0 and
11
12
  val.typeOfResource.attributes.length > 0 and
12
13
  val.typeOfResource.attributes.first.has_key?("collection") and
@@ -0,0 +1,7 @@
1
+ class ModsDisplay::ResourceType < ModsDisplay::Field
2
+
3
+ private
4
+ def displayLabel(element)
5
+ super(element) || "Type of resource"
6
+ end
7
+ end
@@ -25,7 +25,7 @@ class ModsDisplay::Subject < ModsDisplay::Field
25
25
 
26
26
  # Would really like to clean this up, but it works and is tested for now.
27
27
  def to_html
28
- return nil if fields.empty?
28
+ return nil if fields.empty? or @config.ignore?
29
29
  output = ""
30
30
  fields.each do |field|
31
31
  output << "<dt#{label_class} title='#{field.label}'>#{field.label}:</dt>"
@@ -40,10 +40,10 @@ class ModsDisplay::Title < ModsDisplay::Field
40
40
  end
41
41
 
42
42
  def title_labels
43
- {"abbreviated" => "Abbreviated Title",
44
- "translated" => "Translated Title",
45
- "alternative" => "Alternative Title",
46
- "uniform" => "Uniform Title"}
43
+ {"abbreviated" => "Abbreviated title",
44
+ "translated" => "Translated title",
45
+ "alternative" => "Alternative title",
46
+ "uniform" => "Uniform title"}
47
47
  end
48
48
 
49
49
  end
@@ -64,14 +64,15 @@ class ModsDisplay::HTML
64
64
  end
65
65
 
66
66
  def mods_display_fields
67
- [:title, :name, :format, :imprint, :language, :description, :cartographics, :abstract, :contents, :audience, :note, :collection, :relatedLocation, :relatedItem, :subject, :identifier, :location]
67
+ [:title, :name, :language, :imprint, :resourceType, :genre, :description, :cartographics, :abstract, :contents, :audience, :note, :contact, :collection, :relatedLocation, :relatedItem, :subject, :identifier, :location]
68
68
  end
69
69
 
70
70
  def mods_display_field_mapping
71
71
  {:title => :title_info,
72
72
  :subTitle => :title_info,
73
73
  :name => :plain_name,
74
- :format => :typeOfResource,
74
+ :resourceType => :typeOfResource,
75
+ :genre => :genre,
75
76
  :imprint => :origin_info,
76
77
  :language => :language,
77
78
  :description => :physical_description,
@@ -80,6 +81,7 @@ class ModsDisplay::HTML
80
81
  :contents => :tableOfContents,
81
82
  :audience => :targetAudience,
82
83
  :note => :note,
84
+ :contact => :note,
83
85
  :collection => :related_item,
84
86
  :relatedLocation => :related_item,
85
87
  :relatedItem => :related_item,
@@ -90,6 +92,7 @@ class ModsDisplay::HTML
90
92
 
91
93
  def field_key_translation
92
94
  {:subTitle => :sub_title,
95
+ :resourceType => :resource_type,
93
96
  :relatedLocation => :related_location,
94
97
  :relatedItem => :related_item
95
98
  }
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = "0.0.1.beta6"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -26,4 +26,14 @@ describe ModsDisplay::Configuration::Base do
26
26
  ModsDisplay::Configuration::Base.new.delimiter.should == ", "
27
27
  end
28
28
  end
29
+ describe "ignore" do
30
+ it "should be set to true if the #ignore! method is called" do
31
+ ModsDisplay::Configuration::Base.new do
32
+ ignore!
33
+ end.ignore?.should be_true
34
+ end
35
+ it "should be false by default" do
36
+ ModsDisplay::Configuration::Base.new.ignore?.should be_false
37
+ end
38
+ end
29
39
  end
@@ -9,6 +9,14 @@ describe ModsDisplay::Abstract do
9
9
  @link = Stanford::Mods::Record.new.from_str("<mods><abstract>A link to the library (http://library.stanford.edu) should appear here</abstract></mods>", false).abstract
10
10
  @email = Stanford::Mods::Record.new.from_str("<mods><abstract>A link to an email address jdoe@example.com should appear here</abstract></mods>", false).abstract
11
11
  end
12
+
13
+ describe "labels" do
14
+ it "should get a default 'Abstract' label" do
15
+ fields = mods_display_abstract(@link).fields
16
+ fields.length.should == 1
17
+ fields.first.label.should == "Abstract"
18
+ end
19
+ end
12
20
 
13
21
  describe "links" do
14
22
  it "should turn URLs into links" do
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ def mods_display_contact(mods_record)
4
+ ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
5
+ end
6
+
7
+ describe ModsDisplay::Contact do
8
+ before(:all) do
9
+ @contact_note = Stanford::Mods::Record.new.from_str("<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false).note
10
+ end
11
+ it "should only get contact fields" do
12
+ fields = mods_display_contact(@contact_note).fields
13
+ fields.length.should == 1
14
+ fields.first.values.should include("jdoe@example.com")
15
+ end
16
+ it "should not get any non-contact fields" do
17
+ fields = mods_display_contact(@contact_note).fields
18
+ fields.length.should == 1
19
+ fields.first.values.should_not include("Note Field")
20
+ end
21
+ end
@@ -11,7 +11,7 @@ describe ModsDisplay::Contents do
11
11
  end
12
12
  describe "label" do
13
13
  it "should have a default label" do
14
- mods_display_contents(@contents).label.should == "Table of Contents"
14
+ mods_display_contents(@contents).label.should == "Table of contents"
15
15
  end
16
16
  it "should use the displayLabel attribute when one is available" do
17
17
  mods_display_contents(@display_label).label.should == "Special Label"
@@ -12,7 +12,7 @@ describe ModsDisplay::Description do
12
12
  @mixed = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><form>Form Note</form><extent>Extent Note</extent></physicalDescription></mods>", false).physical_description
13
13
  end
14
14
  describe "labels" do
15
- it "should use the dislayLabel if one is provided" do
15
+ it "should use the displayLabel if one is provided" do
16
16
  mods_display_description(@display_label).fields.first.label.should == "SpecialLabel"
17
17
  end
18
18
  it "should get the default label for a child element" do
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ def mods_display_genre(mods_record)
4
+ ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
5
+ end
6
+
7
+ describe ModsDisplay::Abstract do
8
+ before(:all) do
9
+ @genre = Stanford::Mods::Record.new.from_str("<mods><genre>Map Data</abstract></genre>", false).genre
10
+ @display_label = Stanford::Mods::Record.new.from_str("<mods><genre displayLabel='Special label'>Catographic</genre></mods>", false).genre
11
+ end
12
+ describe "labels" do
13
+ it "should return a default 'Genre' label" do
14
+ fields = mods_display_genre(@genre).fields
15
+ fields.length.should == 1
16
+ fields.first.label.should == "Genre"
17
+ end
18
+ it "should use a display label when one is available" do
19
+ fields = mods_display_genre(@display_label).fields
20
+ fields.length.should == 1
21
+ fields.first.label.should == "Special label"
22
+ end
23
+ end
24
+ end
@@ -20,7 +20,7 @@ describe ModsDisplay::Note do
20
20
  mods_display_id(@display_label).fields.first.label.should == "Special Label"
21
21
  end
22
22
  it "should use get a label from a list of translations" do
23
- mods_display_id(@issue_label).fields.first.label.should == "Issue Number"
23
+ mods_display_id(@issue_label).fields.first.label.should == "Issue number"
24
24
  end
25
25
  it "should use use the raw type attribute if one is present" do
26
26
  mods_display_id(@type_label).fields.first.label.should == "Some other Type"
@@ -36,7 +36,7 @@ describe ModsDisplay::Note do
36
36
  fields.first.values.length.should == 2
37
37
  fields.first.values.should == ["12345", "54321"]
38
38
 
39
- fields[1].label.should == "Issue Number"
39
+ fields[1].label.should == "Issue number"
40
40
  fields[1].values.length.should == 1
41
41
  fields[1].values.should == ["12345"]
42
42
 
@@ -25,7 +25,7 @@ describe ModsDisplay::Imprint do
25
25
  end
26
26
  it "should get the label from non-imprint origin info fields" do
27
27
  fields = mods_display_imprint(@edition_and_date).fields
28
- fields.first.label.should == "Date Valid"
28
+ fields.first.label.should == "Date valid"
29
29
  fields.last.label.should == "Edition"
30
30
  end
31
31
  it "should get multiple labels when we have mixed content" do
@@ -9,7 +9,8 @@ describe ModsDisplay::Note do
9
9
  @note = Stanford::Mods::Record.new.from_str("<mods><note>Note Field</note></mods>", false).note
10
10
  @display_label = Stanford::Mods::Record.new.from_str("<mods><note displayLabel='Special Label'>Note Field</note></mods>", false).note
11
11
  @sor_label = Stanford::Mods::Record.new.from_str("<mods><note type='statement of responsibility'>Note Field</note></mods>", false).note
12
- @type_label = Stanford::Mods::Record.new.from_str("<mods><note type='Some other Type'>Note Field</note></mods>", false).note
12
+ @contact_note = Stanford::Mods::Record.new.from_str("<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false).note
13
+ @type_label = Stanford::Mods::Record.new.from_str("<mods><note type='some other Type'>Note Field</note></mods>", false).note
13
14
  @complex_label = Stanford::Mods::Record.new.from_str("<mods><note>Note Field</note><note>2nd Note Field</note><note type='statement of responsibility'>SoR</note><note>Another Note</note></mods>", false).note
14
15
  end
15
16
  describe "label" do
@@ -20,10 +21,10 @@ describe ModsDisplay::Note do
20
21
  mods_display_note(@display_label).fields.first.label.should == "Special Label"
21
22
  end
22
23
  it "should use get a label from a list of translations" do
23
- mods_display_note(@sor_label).fields.first.label.should == "Statement of Responsibility"
24
+ mods_display_note(@sor_label).fields.first.label.should == "Statement of responsibility"
24
25
  end
25
- it "should use use the raw type attribute if one is present" do
26
- mods_display_note(@type_label).fields.first.label.should == "Some other Type"
26
+ it "should use use the capitalized type attribute if one is present" do
27
+ mods_display_note(@type_label).fields.first.label.should == "Some other type"
27
28
  end
28
29
  end
29
30
 
@@ -40,7 +41,7 @@ describe ModsDisplay::Note do
40
41
  fields.first.values.length == 2
41
42
  fields.first.values.should == ["Note Field", "2nd Note Field"]
42
43
 
43
- fields[1].label == "Statement of Responsibility"
44
+ fields[1].label == "Statement of responsibility"
44
45
  fields[1].values.length == 1
45
46
  fields[1].values.should == ["SoR"]
46
47
 
@@ -48,6 +49,11 @@ describe ModsDisplay::Note do
48
49
  fields.last.values.length == 1
49
50
  fields.last.values.should == ["Another Note"]
50
51
  end
52
+ it "should not include any contact fields" do
53
+ fields = mods_display_note(@contact_note).fields
54
+ fields.length.should == 1
55
+ fields.first.values.should == ["Note Field"]
56
+ end
51
57
  end
52
58
 
53
59
  end
@@ -15,7 +15,7 @@ describe ModsDisplay::RelatedItem do
15
15
  end
16
16
  describe "label" do
17
17
  it "should default to Related Item" do
18
- mods_display_item(@item).fields.first.label.should == "Related Item"
18
+ mods_display_item(@item).fields.first.label.should == "Related item"
19
19
  end
20
20
  it "should get the displayLabel if available" do
21
21
  mods_display_item(@display_label).fields.first.label.should == "Special Item"
@@ -41,7 +41,7 @@ describe ModsDisplay::RelatedItem do
41
41
  it "should collapse labels down into the same record" do
42
42
  fields = mods_display_item(@multi_items).fields
43
43
  fields.length.should == 1
44
- fields.first.label.should == "Related Item"
44
+ fields.first.label.should == "Related item"
45
45
  fields.first.values.length.should == 2
46
46
  fields.first.values.first.should =~ /<a href=.*>Library<\/a>/ or
47
47
  fields.first.values.last.should =~ /<a href=.*>SDR<\/a>/
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ def mods_display_resource_type(mods_record)
4
+ ModsDisplay::ResourceType.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
5
+ end
6
+
7
+ describe ModsDisplay::ResourceType do
8
+ before(:all) do
9
+ @type = Stanford::Mods::Record.new.from_str("<mods><typeOfResource>Resource Type</typeOfResource></mods>", false).typeOfResource
10
+ @display_label = Stanford::Mods::Record.new.from_str("<mods><typeOfResource displayLabel='Special label'>Resource Type</typeOfResource></mods>", false).typeOfResource
11
+ end
12
+ it "should default to a label of 'Type of resource'" do
13
+ fields = mods_display_resource_type(@type).fields
14
+ fields.length.should == 1
15
+ fields.first.label.should == "Type of resource"
16
+ end
17
+ it "should use the displayLabel attribute when present" do
18
+ fields = mods_display_resource_type(@display_label).fields
19
+ fields.length.should == 1
20
+ fields.first.label.should == "Special label"
21
+ end
22
+ end
@@ -17,7 +17,7 @@ describe ModsDisplay::Title do
17
17
  mods_display_title(@title).fields.first.label.should == "Title"
18
18
  end
19
19
  it "should return an appropriate label from the type attribute" do
20
- mods_display_title(@alt_title).fields.first.label.should == "Alternative Title"
20
+ mods_display_title(@alt_title).fields.first.label.should == "Alternative title"
21
21
  end
22
22
  it "should return the label held in the displayLabel attribute of the titleInfo element when available" do
23
23
  mods_display_title(@display_label).fields.first.label.should == "MyTitle"
@@ -9,6 +9,9 @@ class TestConfigController
9
9
  value_class 'value-class'
10
10
  link :link_to_title, "%value%"
11
11
  end
12
+ contact do
13
+ ignore!
14
+ end
12
15
  end
13
16
 
14
17
  def link_to_title(title)
@@ -18,7 +21,7 @@ end
18
21
 
19
22
  describe "Configuration" do
20
23
  before(:all) do
21
- xml = "<mods><titleInfo><title>The Title of this Item</title></titleInfo></mods>"
24
+ xml = "<mods><titleInfo><title>The Title of this Item</title></titleInfo><note type='contact'>jdoe@example.com</note></mods>"
22
25
  model = TestModel.new
23
26
  model.modsxml = xml
24
27
  controller = TestConfigController.new
@@ -33,5 +36,7 @@ describe "Configuration" do
33
36
  it "should apply the link" do
34
37
  @html.scan(/<a href='\/path\/to\/title\?The Title of this Item'>The Title of this Item<\a>/)
35
38
  end
36
-
39
+ it "should ignore fields if requested" do
40
+ @html.scan(/jdoe@example\.com/).length.should == 0
41
+ end
37
42
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta6
5
- prerelease: 6
4
+ version: 0.0.1
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jessie Keck
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-14 00:00:00.000000000 Z
12
+ date: 2013-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stanford-mods
@@ -75,16 +75,21 @@ files:
75
75
  - lib/mods_display.rb
76
76
  - lib/mods_display/configuration.rb
77
77
  - lib/mods_display/configuration/base.rb
78
+ - lib/mods_display/configuration/name.rb
79
+ - lib/mods_display/configuration/note.rb
80
+ - lib/mods_display/configuration/related_item.rb
78
81
  - lib/mods_display/configuration/subject.rb
79
82
  - lib/mods_display/controller_extension.rb
80
83
  - lib/mods_display/fields/abstract.rb
81
84
  - lib/mods_display/fields/audience.rb
82
85
  - lib/mods_display/fields/cartographics.rb
83
86
  - lib/mods_display/fields/collection.rb
87
+ - lib/mods_display/fields/contact.rb
84
88
  - lib/mods_display/fields/contents.rb
85
89
  - lib/mods_display/fields/description.rb
86
90
  - lib/mods_display/fields/field.rb
87
91
  - lib/mods_display/fields/format.rb
92
+ - lib/mods_display/fields/genre.rb
88
93
  - lib/mods_display/fields/identifier.rb
89
94
  - lib/mods_display/fields/imprint.rb
90
95
  - lib/mods_display/fields/language.rb
@@ -93,6 +98,7 @@ files:
93
98
  - lib/mods_display/fields/note.rb
94
99
  - lib/mods_display/fields/related_item.rb
95
100
  - lib/mods_display/fields/related_location.rb
101
+ - lib/mods_display/fields/resource_type.rb
96
102
  - lib/mods_display/fields/sub_title.rb
97
103
  - lib/mods_display/fields/subject.rb
98
104
  - lib/mods_display/fields/title.rb
@@ -106,9 +112,11 @@ files:
106
112
  - spec/fields/audience_spec.rb
107
113
  - spec/fields/cartographics_spec.rb
108
114
  - spec/fields/collection_spec.rb
115
+ - spec/fields/contact_spec.rb
109
116
  - spec/fields/contents_spec.rb
110
117
  - spec/fields/description_spec.rb
111
118
  - spec/fields/format_spec.rb
119
+ - spec/fields/genre_spec.rb
112
120
  - spec/fields/identifier_spec.rb
113
121
  - spec/fields/imprint_spec.rb
114
122
  - spec/fields/language_spec.rb
@@ -117,6 +125,7 @@ files:
117
125
  - spec/fields/note_spec.rb
118
126
  - spec/fields/related_item_spec.rb
119
127
  - spec/fields/related_location_spec.rb
128
+ - spec/fields/resource_type_spec.rb
120
129
  - spec/fields/sub_title_spec.rb
121
130
  - spec/fields/subject_spec.rb
122
131
  - spec/fields/title_spec.rb
@@ -142,16 +151,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
151
  version: '0'
143
152
  segments:
144
153
  - 0
145
- hash: -2853420712234504554
154
+ hash: -2016190750318240142
146
155
  required_rubygems_version: !ruby/object:Gem::Requirement
147
156
  none: false
148
157
  requirements:
149
- - - ! '>'
158
+ - - ! '>='
150
159
  - !ruby/object:Gem::Version
151
- version: 1.3.1
160
+ version: '0'
161
+ segments:
162
+ - 0
163
+ hash: -2016190750318240142
152
164
  requirements: []
153
165
  rubyforge_project:
154
- rubygems_version: 1.8.24
166
+ rubygems_version: 1.8.25
155
167
  signing_key:
156
168
  specification_version: 3
157
169
  summary: The MODS Display gem allows implementers to configure a customized display
@@ -163,9 +175,11 @@ test_files:
163
175
  - spec/fields/audience_spec.rb
164
176
  - spec/fields/cartographics_spec.rb
165
177
  - spec/fields/collection_spec.rb
178
+ - spec/fields/contact_spec.rb
166
179
  - spec/fields/contents_spec.rb
167
180
  - spec/fields/description_spec.rb
168
181
  - spec/fields/format_spec.rb
182
+ - spec/fields/genre_spec.rb
169
183
  - spec/fields/identifier_spec.rb
170
184
  - spec/fields/imprint_spec.rb
171
185
  - spec/fields/language_spec.rb
@@ -174,6 +188,7 @@ test_files:
174
188
  - spec/fields/note_spec.rb
175
189
  - spec/fields/related_item_spec.rb
176
190
  - spec/fields/related_location_spec.rb
191
+ - spec/fields/resource_type_spec.rb
177
192
  - spec/fields/sub_title_spec.rb
178
193
  - spec/fields/subject_spec.rb
179
194
  - spec/fields/title_spec.rb