mods_display 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6fbeb6e358da70acf9959feba56cea0b735f47b
4
- data.tar.gz: b4236dd3026d7d7cb3c5a93217e64491c6fd6528
3
+ metadata.gz: ab713fa903d406d1b3e5d7b019a33fe02c15f5fd
4
+ data.tar.gz: d4ec7939d4d45cbf7ae8162554396b9316641940
5
5
  SHA512:
6
- metadata.gz: b2e555e1dd3269a8ad2fea3aa1426e042b417992cba343369dc4c8ba3a27c66c18d2ab637df006e9a9f69550a31d44237ed7535994093da65bcf3f916460dbb2
7
- data.tar.gz: 91caac5689b774665d1e027b20cb4dbdcded4f62950799c46c77a062781968588e36a8313049695cb9b6baaf54494057d65cbf1289de2191d02ec156093cc0b7
6
+ metadata.gz: abb09cdaf3bbe01eab797de7dd20e5467cc66de304d151b11478f5710b55d41b72c3adcbe8e9e07061089ad628aa7435f01309f6c7db6d4468fd3482738dbb8f
7
+ data.tar.gz: 2fc0e8df881f28edfba1a85d28f54c3d802b5d1e09b633b48d79a5be58fb6c1d53654693c73b79b530113e3e0a772c86aa0ffe3c8dfb6e100062fc58a562b2c5
@@ -371,7 +371,8 @@ module ModsDisplay::CountryCodes
371
371
  "xra" => "South Australia",
372
372
  "xs" => "South Georgia and the South Sandwich Islands",
373
373
  "xv" => "Slovenia",
374
- "xx" => "No place, unknown, or undetermined",
374
+ # Removing per METADOR-32
375
+ #"xx" => "No place, unknown, or undetermined",
375
376
  "xxc" => "Canada",
376
377
  "xxk" => "United Kingdom",
377
378
  "xxr" => "Soviet Union",
@@ -2,12 +2,12 @@ class ModsDisplay::Name < ModsDisplay::Field
2
2
  include ModsDisplay::RelatorCodes
3
3
  def fields
4
4
  return_fields = @values.map do |value|
5
- role = process_role(value)
5
+ roles = process_role(value)
6
6
  person = nil
7
7
  if value.displayForm.length > 0
8
- person = ModsDisplay::Name::Person.new(:name => value.displayForm.text, :role => role)
8
+ person = ModsDisplay::Name::Person.new(:name => value.displayForm.text, :roles => roles)
9
9
  elsif !name_parts(value).empty?
10
- person = ModsDisplay::Name::Person.new(:name => name_parts(value), :role => role)
10
+ person = ModsDisplay::Name::Person.new(:name => name_parts(value), :roles => roles)
11
11
  end
12
12
  ModsDisplay::Values.new(:label => displayLabel(value) || name_label(value), :values => [person]) if person
13
13
  end.compact
@@ -23,7 +23,7 @@ class ModsDisplay::Name < ModsDisplay::Field
23
23
  output << field.values.map do |val|
24
24
  if @config.link
25
25
  txt = link_to_value(val.name)
26
- txt << " (#{val.role})" if val.role
26
+ txt << " (#{val.roles.join(', ')})" if val.roles
27
27
  txt
28
28
  else
29
29
  val.to_s
@@ -37,17 +37,23 @@ class ModsDisplay::Name < ModsDisplay::Field
37
37
  private
38
38
 
39
39
  def name_label(element)
40
- if name_is_main_author?(element)
41
- if element.attributes.has_key?("type") && name_labels.has_key?(element.attributes["type"].value)
42
- return name_labels[element.attributes["type"].value]
43
- end
40
+ if !has_role?(element) || is_primary?(element) || has_author_or_creator_roles?(element)
44
41
  "Author/Creator"
45
42
  else
46
43
  "Contributor"
47
44
  end
48
45
  end
49
-
50
- def name_is_main_author?(element)
46
+
47
+ def has_role?(element)
48
+ element.respond_to?(:role) and !element.role.empty?
49
+ end
50
+
51
+ def is_primary?(element)
52
+ element.attributes["usage"].respond_to?(:value) and
53
+ element.attributes["usage"].value == "primary"
54
+ end
55
+
56
+ def has_author_or_creator_roles?(element)
51
57
  begin
52
58
  ["author", "aut", "creator", "cre", ""].include?(element.role.roleTerm.text.downcase)
53
59
  rescue
@@ -108,22 +114,26 @@ class ModsDisplay::Name < ModsDisplay::Field
108
114
  term.attributes["authority"].respond_to?(:value) and
109
115
  term.attributes["authority"].value == "marcrelator" and
110
116
  relator_codes.include?(term.text.strip)
111
- term = term.clone
112
- term.content = relator_codes[term.text.strip]
113
- term
117
+ relator_codes[term.text.strip]
114
118
  end
115
- end.compact.first
119
+ end.compact
116
120
  end
117
121
  end
118
122
  end
119
123
 
120
124
  def unencoded_role_term(element)
121
- element.role.roleTerm.find do |term|
122
- term.attributes["type"].respond_to?(:value) and
123
- term.attributes["type"].value == "text"
124
- end || element.role.roleTerm.find do |term|
125
- !term.attributes["type"].respond_to?(:value)
126
- end
125
+ roles = element.role.map do |role|
126
+ role.roleTerm.find do |term|
127
+ term.attributes["type"].respond_to?(:value) and
128
+ term.attributes["type"].value == "text"
129
+ end
130
+ end.compact
131
+ roles = element.role.map do |role|
132
+ role.roleTerm.find do |term|
133
+ !term.attributes["type"].respond_to?(:value)
134
+ end
135
+ end.compact if roles.empty?
136
+ roles.map{|t| t.text.strip }
127
137
  end
128
138
 
129
139
  def unencoded_role_term?(element)
@@ -141,15 +151,15 @@ class ModsDisplay::Name < ModsDisplay::Field
141
151
  end
142
152
 
143
153
  class Person
144
- attr_accessor :name, :role
154
+ attr_accessor :name, :roles
145
155
  def initialize(data)
146
- @name = data[:name]
147
- @role = data[:role] ? data[:role].text : nil
156
+ @name = data[:name]
157
+ @roles = data[:roles] && !data[:roles].empty? ? data[:roles] : nil
148
158
  end
149
159
 
150
160
  def to_s
151
161
  text = @name.dup
152
- text << " (#{@role})" if @role
162
+ text << " (#{@roles.join(', ')})" if @roles
153
163
  text
154
164
  end
155
165
  end
@@ -47,7 +47,7 @@ class ModsDisplay::Subject < ModsDisplay::Field
47
47
  if @config.link and @config.hierarchical_link
48
48
  if val.is_a?(ModsDisplay::Name::Person)
49
49
  txt = link_to_value(val.name, buffer.join(' '))
50
- txt << " (#{val.role})" if val.role
50
+ txt << " (#{val.roles.join(', ')})" if val.roles
51
51
  sub_parts << txt
52
52
  else
53
53
  sub_parts << link_to_value(val, buffer.join(' '))
@@ -55,7 +55,7 @@ class ModsDisplay::Subject < ModsDisplay::Field
55
55
  elsif @config.link
56
56
  if val.is_a?(ModsDisplay::Name::Person)
57
57
  txt = link_to_value(val.name)
58
- txt << " (#{val.role})" if val.role
58
+ txt << " (#{val.roles.join(', ')})" if val.roles
59
59
  sub_parts << txt
60
60
  else
61
61
  sub_parts << link_to_value(val.to_s)
@@ -25,7 +25,7 @@ class ModsDisplay::Title < ModsDisplay::Field
25
25
  return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [[preParts, parts].compact.join(". ")])
26
26
  end
27
27
  end
28
- return_values
28
+ collapse_fields(return_values)
29
29
  end
30
30
 
31
31
  private
@@ -1,3 +1,3 @@
1
1
  module ModsDisplay
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -29,6 +29,7 @@ describe ModsDisplay::Imprint do
29
29
  @questionable_date = Stanford::Mods::Record.new.from_str(questionable_date, false).origin_info
30
30
  @inferred_date = Stanford::Mods::Record.new.from_str(inferred_date, false).origin_info
31
31
  @three_imprint_dates = Stanford::Mods::Record.new.from_str(three_imprint_dates, false).origin_info
32
+ @xx_country_code = Stanford::Mods::Record.new.from_str(xx_country_code, false).origin_info
32
33
  @qualified_imprint_date = Stanford::Mods::Record.new.from_str(qualified_imprint_date, false).origin_info
33
34
  @imprint_date_range = Stanford::Mods::Record.new.from_str(imprint_date_range, false).origin_info
34
35
  @encoded_place = Stanford::Mods::Record.new.from_str(encoded_place, false).origin_info
@@ -205,6 +206,11 @@ describe ModsDisplay::Imprint do
205
206
  fields.length.should == 1
206
207
  fields.first.values.should include "Netherlands"
207
208
  end
209
+ it "should ignore 'xx' country codes" do
210
+ fields = mods_display_imprint(@xx_country_code).fields
211
+ fields.length.should == 1
212
+ fields.first.values.should == ["1994"]
213
+ end
208
214
  end
209
215
  describe "to_html" do
210
216
  it "should return the display form if one is available" do
@@ -17,7 +17,7 @@ describe ModsDisplay::Language do
17
17
  before(:all) do
18
18
  @name = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name></mods>", false).plain_name
19
19
  @blank_name = Stanford::Mods::Record.new.from_str("<mods><name><namePart/><role><roleTerm></roleTerm></role></name></mods>", false).plain_name
20
- @conf_name = Stanford::Mods::Record.new.from_str("<mods><name type='conference'><namePart>John Doe</namePart></name></mods>", false).plain_name
20
+ @primary_name = Stanford::Mods::Record.new.from_str("<mods><name usage='primary'><namePart>John Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name></mods>", false).plain_name
21
21
  @contributor = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name></mods>", false).plain_name
22
22
  @encoded_role = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='code' authority='marcrelator'>ltg</roleTerm></role></name></mods>", false).plain_name
23
23
  @mixed_role = Stanford::Mods::Record.new.from_str("<mods><name><role><roleTerm>publisher</roleTerm></role><namePart>John Doe</namePart><role><roleTerm type='text' authority='marcrelator'>engraver</roleTerm></role></name></mods>", false).plain_name
@@ -25,15 +25,17 @@ describe ModsDisplay::Language do
25
25
  @simple_toa = Stanford::Mods::Record.new.from_str("<mods><name><namePart>Unqualfieid</namePart><namePart type='termsOfAddress'>Ier, empereur</namePart><namePart type='date'>date1-date2</namePart><namePart type='given'>Given Name</namePart><namePart type='family'>Family Name</namePart></name></mods>", false).plain_name
26
26
  @display_form = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><displayForm>Mr. John Doe</displayForm></name></mods>", false).plain_name
27
27
  @collapse_label = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart></name></mods>", false).plain_name
28
- @complex_labels = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart></name><name type='conference'><namePart>John Dough</namePart></name><name><namePart>Jane Dough</namePart></name></mods>", false).plain_name
28
+ @complex_labels = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name><name><namePart>John Dough</namePart></name><name><namePart>Jane Dough</namePart></name></mods>", false).plain_name
29
+ @complex_roles = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm><roleTerm type='code'>dpt</roleTerm></role></name></mods>", false).plain_name
29
30
  @name_with_role = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm></role></name></mods>", false).plain_name
31
+ @multiple_roles = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm></role><role><roleTerm type='text'>Artist</roleTerm></role></name></mods>", false).plain_name
30
32
  end
31
33
  describe "label" do
32
- it "should default Author/Creator when none is available" do
34
+ it "should default Author/Creator when no role is available" do
33
35
  mods_display_name(@name).fields.first.label.should == "Author/Creator"
34
36
  end
35
- it "should derive the name from the type attribute if one is available" do
36
- mods_display_name(@conf_name).fields.first.label.should == "Meeting"
37
+ it "should label 'Author/Creator' for primary authors" do
38
+ mods_display_name(@primary_name).fields.first.label.should == "Author/Creator"
37
39
  end
38
40
  it "should apply contributor labeling to all non blank/author/creator roles" do
39
41
  mods_display_name(@contributor).fields.first.label.should == "Contributor"
@@ -48,25 +50,6 @@ describe ModsDisplay::Language do
48
50
  fields.first.values.first.should be_a(ModsDisplay::Name::Person)
49
51
  fields.first.values.first.name.should == "Mr. John Doe"
50
52
  end
51
- it "should get the role when present" do
52
- fields = mods_display_name(@name_with_role).fields
53
- fields.length.should == 1
54
- fields.first.values.length.should == 1
55
- fields.first.values.first.should be_a(ModsDisplay::Name::Person)
56
- fields.first.values.first.role.should == "Depicted"
57
- end
58
- it "should decode encoded roleTerms when no text (or non-typed) roleTerm is available" do
59
- fields = mods_display_name(@encoded_role).fields
60
- fields.length.should == 1
61
- fields.first.values.length.should == 1
62
- fields.first.values.first.to_s.should == "John Doe (Lithographer)"
63
- end
64
- it "should get the type='text' role before an untyped role" do
65
- fields = mods_display_name(@mixed_role).fields
66
- fields.length.should == 1
67
- fields.first.values.length.should == 1
68
- fields.first.values.first.role.should == "engraver"
69
- end
70
53
  it "should not add blank names" do
71
54
  mods_display_name(@blank_name).fields.should == []
72
55
  end
@@ -97,18 +80,58 @@ describe ModsDisplay::Language do
97
80
 
98
81
  fields.length.should == 3
99
82
  fields.first.label.should == "Author/Creator"
100
- fields.first.values.length.should == 2
101
- fields.first.values.each do |val|
102
- ["John Doe", "Jane Doe"].should include val.to_s
103
- end
104
-
105
- fields[1].label.should == "Meeting"
83
+ fields.first.values.length.should == 1
84
+ fields.first.values.first.to_s.should == "John Doe"
85
+
86
+ fields[1].label.should == "Contributor"
106
87
  fields[1].values.length.should == 1
107
- fields[1].values.first.to_s.should == "John Dough"
88
+ fields[1].values.first.name.should == "Jane Doe"
89
+ fields[1].values.first.roles.should == ["lithographer"]
108
90
 
109
91
  fields.last.label.should == "Author/Creator"
110
- fields.last.values.length.should == 1
111
- fields.last.values.first.to_s.should == "Jane Dough"
92
+ fields.last.values.length.should == 2
93
+ fields.last.values.each do |val|
94
+ ["Jane Dough", "John Dough"].should include val.to_s
95
+ end
96
+ end
97
+ describe "roles" do
98
+ it "should get the role when present" do
99
+ fields = mods_display_name(@name_with_role).fields
100
+ fields.length.should == 1
101
+ fields.first.values.length.should == 1
102
+ fields.first.values.first.should be_a(ModsDisplay::Name::Person)
103
+ fields.first.values.first.roles.should == ["Depicted"]
104
+ end
105
+ it "should decode encoded roleTerms when no text (or non-typed) roleTerm is available" do
106
+ fields = mods_display_name(@encoded_role).fields
107
+ fields.length.should == 1
108
+ fields.first.values.length.should == 1
109
+ fields.first.values.first.to_s.should == "John Doe (Lithographer)"
110
+ end
111
+ it "should get the type='text' role before an untyped role" do
112
+ fields = mods_display_name(@mixed_role).fields
113
+ fields.length.should == 1
114
+ fields.first.values.length.should == 1
115
+ fields.first.values.first.roles.should == ["engraver"]
116
+ end
117
+ it "should be handled correctly when there are more than one" do
118
+ fields = mods_display_name(@multiple_roles).fields
119
+ fields.length.should == 1
120
+ fields.first.values.length.should == 1
121
+ fields.first.values.first.roles.should == ["Depicted", "Artist"]
122
+ end
123
+ it "should handle code and text roleTerms together correctly" do
124
+ fields = mods_display_name(@complex_roles).fields
125
+ fields.length.should == 1
126
+ fields.first.values.length.should == 1
127
+ fields.first.values.first.roles.should == ["Depicted"]
128
+ end
129
+ it "should comma seperate multiple roles" do
130
+ fields = mods_display_name(@multiple_roles).fields
131
+ fields.length.should == 1
132
+ fields.first.values.length.should == 1
133
+ fields.first.values.first.to_s.should == "John Doe (Depicted, Artist)"
134
+ end
112
135
  end
113
136
  end
114
137
 
@@ -64,7 +64,7 @@ describe ModsDisplay::Subject do
64
64
  fields.length.should == 1
65
65
  fields.first.values.first.first.should be_a(ModsDisplay::Name::Person)
66
66
  fields.first.values.first.first.name.should == "John Doe"
67
- fields.first.values.first.first.role.should == "Depicted"
67
+ fields.first.values.first.first.roles.should == ["Depicted"]
68
68
  end
69
69
  it "should link the name (and not the role) correctly" do
70
70
  html = mods_display_subject(@name_subject).to_html
@@ -11,6 +11,7 @@ describe ModsDisplay::Title do
11
11
  @reverse_title_parts = Stanford::Mods::Record.new.from_str("<mods><titleInfo><nonSort>The</nonSort><title>Title</title><subTitle>For</subTitle><partNumber>Part 62</partNumber><partName>Something</partName></titleInfo></mods>", false).title_info
12
12
  @display_label = Stanford::Mods::Record.new.from_str("<mods><titleInfo displayLabel='MyTitle'><title>Title</title></titleInfo></mods>", false).title_info
13
13
  @display_form = Stanford::Mods::Record.new.from_str("<mods><titleInfo><title>Title</title><displayForm>The Title of This Item</displayForm></titleInfo></mods>", false).title_info
14
+ @multi_label = Stanford::Mods::Record.new.from_str("<mods><titleInfo><title>Main Title</title></titleInfo><titleInfo type='alternative'><title>Alt Title</title></titleInfo><titleInfo type='uniform'><title>Uniform Title</title></titleInfo><titleInfo type='alternative'><title>Another Alt Title</title></titleInfo><titleInfo type='alternative'><title>Yet Another Alt Title</title></titleInfo></mods>", false).title_info
14
15
  @alt_title = Stanford::Mods::Record.new.from_str("<mods><titleInfo type='alternative'><title>Title</title></titleInfo></mods>", false).title_info
15
16
  end
16
17
  describe "labels" do
@@ -23,6 +24,15 @@ describe ModsDisplay::Title do
23
24
  it "should return the label held in the displayLabel attribute of the titleInfo element when available" do
24
25
  mods_display_title(@display_label).fields.first.label.should == "MyTitle"
25
26
  end
27
+ it "should collapse adjacent identical labels" do
28
+ fields = mods_display_title(@multi_label).fields
29
+ fields.length.should == 4
30
+ fields[0].label.should == "Title"
31
+ fields[1].label.should == "Alternative title"
32
+ fields[2].label.should == "Uniform title"
33
+ fields[3].label.should == "Alternative title"
34
+ fields[3].values.should == ["Another Alt Title", "Yet Another Alt Title"]
35
+ end
26
36
  end
27
37
  describe "fields" do
28
38
  it "should return an array of label/value objects" do
@@ -224,6 +224,18 @@ module ImprintFixtures
224
224
  </mods>
225
225
  MODS
226
226
  end
227
+ def xx_country_code
228
+ <<-MODS
229
+ <mods>
230
+ <originInfo>
231
+ <place>
232
+ <placeTerm type="code" authority="marccountry">xx</placeTerm>
233
+ </place>
234
+ <dateIssued>1994</dateIssued>
235
+ </originInfo>
236
+ </mods>
237
+ MODS
238
+ end
227
239
  def encoded_dates
228
240
  <<-MODS
229
241
  <mods>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mods_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jessie Keck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2013-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stanford-mods