diff --git a/lib/avm/contact.rb b/lib/avm/contact.rb
index 62ecfa0..52f6867 100644
--- a/lib/avm/contact.rb
+++ b/lib/avm/contact.rb
@@ -24,5 +24,9 @@ module AVM
def to_creator_list_element
%{#{self.name}}
end
+
+ def primary?
+ @primary
+ end
end
end
diff --git a/lib/avm/creator.rb b/lib/avm/creator.rb
index 05512e8..d84344b 100644
--- a/lib/avm/creator.rb
+++ b/lib/avm/creator.rb
@@ -85,12 +85,14 @@ module AVM
IPTC_CORE_FIELDS_AND_NAMES.each do |key, element_name|
if node = refs[:iptc].at_xpath("//Iptc4xmpCore:#{element_name}")
- contacts.first[key] = node.text.strip
+ contacts.each { |contact| contact[key] = node.text.strip }
end
end
end
- @contacts = contacts.collect { |contact| Contact.new(contact) }
+ if !(@contacts = contacts.collect { |contact| Contact.new(contact) }).empty?
+ @contacts.first.primary = true
+ end
end
def primary_contact
diff --git a/spec/avm/creator_spec.rb b/spec/avm/creator_spec.rb
index 2341200..20e64d3 100644
--- a/spec/avm/creator_spec.rb
+++ b/spec/avm/creator_spec.rb
@@ -108,18 +108,7 @@ describe AVM::Creator do
its('creator.length') { should == 1 }
- context 'creator one' do
- subject { image.creator[0] }
-
- let(:name) { 'John Bintz' }
- let(:email) { 'bintz@stsci.edu' }
- let(:telephone) { '800-555-1234' }
- let(:address) { '3700 San Martin Drive' }
- let(:city) { 'Baltimore' }
- let(:state) { 'Maryland' }
- let(:zip) { '21218' }
- let(:country) { 'USA' }
-
+ def self.field_checks
its(:name) { should == name }
its(:address) { should == address }
its(:city) { should == city }
@@ -129,10 +118,54 @@ describe AVM::Creator do
its(:email) { should == email }
its(:telephone) { should == telephone }
end
- end
- context 'two creators' do
- let(:file_path) { 'spec/sample_files/creator/two_creators.xmp' }
+ let(:name) { 'John Bintz' }
+ let(:email) { 'bintz@stsci.edu' }
+ let(:telephone) { '800-555-1234' }
+ let(:address) { '3700 San Martin Drive' }
+ let(:city) { 'Baltimore' }
+ let(:state) { 'Maryland' }
+ let(:zip) { '21218' }
+ let(:country) { 'USA' }
+
+ context 'creator one' do
+ subject { image.creator[0] }
+
+ field_checks
+
+ it { should be_primary }
+ end
+
+ context 'two creators' do
+ let(:file_path) { 'spec/sample_files/creator/two_creators.xmp' }
+
+ its('creator.length') { should == 2 }
+
+ context 'first creator' do
+ subject { image.creator[0] }
+
+ field_checks
+
+ it { should be_primary }
+ end
+
+ context 'second creator' do
+ subject { image.creator[1] }
+
+ field_checks
+
+ it { should_not be_primary }
+
+ let(:name) { 'Aohn Bintz' }
+ let(:email) { 'aohn@stsci.edu' }
+ let(:telephone) { '800-555-2345' }
+ let(:address) { '3700 San Martin Drive' }
+ let(:city) { 'Baltimore' }
+ let(:state) { 'Maryland' }
+ let(:zip) { '21218' }
+ let(:country) { 'USA' }
+ end
+ end
end
end
diff --git a/spec/sample_files/creator/one_creator.xmp b/spec/sample_files/creator/one_creator.xmp
index 25e4af3..8518979 100644
--- a/spec/sample_files/creator/one_creator.xmp
+++ b/spec/sample_files/creator/one_creator.xmp
@@ -21,5 +21,3 @@
-
-
diff --git a/spec/sample_files/creator/two_creators.xmp b/spec/sample_files/creator/two_creators.xmp
new file mode 100644
index 0000000..2f12a9f
--- /dev/null
+++ b/spec/sample_files/creator/two_creators.xmp
@@ -0,0 +1,26 @@
+
+
+
+
+
+ John Bintz
+ Aohn Bintz
+
+
+
+
+
+ 3700 San Martin Drive
+ Baltimore
+ Maryland
+ 21218
+ USA
+ 800-555-1234,800-555-2345
+ bintz@stsci.edu,aohn@stsci.edu
+ http://hubblesite.org
+
+
+
+