diff --git a/lib/avm/image.rb b/lib/avm/image.rb
index 281ee8d..188660f 100644
--- a/lib/avm/image.rb
+++ b/lib/avm/image.rb
@@ -11,16 +11,31 @@ module AVM
class Image
DUBLIN_CORE_FIELDS = [ :title, :description ]
- PHOTOSHOP_SINGLES = {
- 'Headline' => :headline,
- 'DateCreated' => :date
- }
+ PHOTOSHOP_SINGLE_FIELDS = [
+ 'Headline',
+ 'DateCreated',
+ 'Credit'
+ ]
+
+ PHOTOSHOP_SINGLE_METHODS = [
+ :headline,
+ :date,
+ :credit
+ ]
+
+ PHOTOSHOP_SINGLES_MESSAGES = [
+ :headline,
+ :string_date,
+ :credit
+ ]
+
+ PHOTOSHOP_SINGLES_FOR_METHODS = PHOTOSHOP_SINGLE_FIELDS.zip(PHOTOSHOP_SINGLE_METHODS)
+ PHOTOSHOP_SINGLES_FOR_MESSAGES = PHOTOSHOP_SINGLE_FIELDS.zip(PHOTOSHOP_SINGLES_MESSAGES)
AVM_SINGLE_FIELDS = [
'Distance.Notes',
'Spectral.Notes',
'ReferenceURL',
- 'Credit',
'ID',
'Type',
'Image.ProductQuality',
@@ -36,14 +51,20 @@ module AVM
'Spatial.ReferenceDimension',
'Spatial.ReferenceValue',
'Spatial.Equinox',
- 'Spatial.CoordinateFrame'
+ 'Spatial.CoordinateFrame',
+ 'Publisher',
+ 'PublisherID',
+ 'ResourceID',
+ 'ResourceURL',
+ 'RelatedResources',
+ 'MetadataDate',
+ 'MetadataVersion',
]
AVM_SINGLE_METHODS = [
:distance_notes,
:spectral_notes,
:reference_url,
- :credit,
:id,
:type,
:quality,
@@ -59,14 +80,20 @@ module AVM
:reference_dimension,
:reference_value,
:equinox,
- :coordinate_frame
+ :coordinate_frame,
+ :publisher,
+ :publisher_id,
+ :resource_id,
+ :resource_url,
+ :related_resources,
+ :metadata_date,
+ :metadata_version,
]
AVM_SINGLE_MESSAGES = [
:distance_notes,
:spectral_notes,
:reference_url,
- :credit,
:id,
:image_type,
:image_quality,
@@ -82,7 +109,14 @@ module AVM
:reference_dimension,
:reference_value,
:equinox,
- :coordinate_frame
+ :coordinate_frame,
+ :publisher,
+ :publisher_id,
+ :resource_id,
+ :resource_url,
+ :related_resources,
+ :string_metadata_date,
+ :metadata_version,
]
AVM_SINGLES = AVM_SINGLE_FIELDS.zip(AVM_SINGLE_METHODS)
@@ -102,7 +136,9 @@ module AVM
:id, :image_type, :image_quality, :coordinate_frame,
:equinox, :reference_value, :reference_dimension, :reference_pixel,
:spatial_scale, :spatial_rotation, :coordinate_system_projection, :spatial_quality,
- :spatial_notes, :fits_header, :spatial_cd_matrix, :distance
+ :spatial_notes, :fits_header, :spatial_cd_matrix, :distance,
+ :publisher, :publisher_id, :resource_id, :resource_url,
+ :related_resources, :metadata_date, :metadata_version
]
attr_reader :creator, :observations
@@ -142,14 +178,16 @@ module AVM
refs[:dublin_core].add_child(%{#{alt_li_tag(send(field))}})
end
- refs[:photoshop].add_child(%{#{headline}})
- refs[:photoshop].add_child(%{#{string_date}})
+ PHOTOSHOP_SINGLES_FOR_MESSAGES.each do |tag, message|
+ refs[:photoshop].add_child(%{#{send(message)}})
+ end
AVM_SINGLES_FOR_MESSAGES.each do |tag, message|
if value = send(message)
case value
when Array
- value = '' + value.collect { |v| "#{v.to_s}" }.join + ''
+ container_tag = (message == :related_resources) ? 'Bag' : 'Seq'
+ value = "" + value.collect { |v| "#{v.to_s}" }.join + ""
else
value = value.to_s
end
@@ -198,12 +236,19 @@ module AVM
end
def date
- (Time.parse(@options[:date]) rescue nil)
+ date_or_nil(:date)
+ end
+
+ def metadata_date
+ date_or_nil(:metadata_date)
end
def string_date
- return nil if !date
- date.strftime('%Y-%m-%d')
+ string_date_or_nil(:date)
+ end
+
+ def string_metadata_date
+ string_date_or_nil(:metadata_date)
end
def distance
@@ -232,7 +277,7 @@ module AVM
end
end
- PHOTOSHOP_SINGLES.each do |tag, field|
+ PHOTOSHOP_SINGLES_FOR_METHODS.each do |tag, field|
if node = refs[:photoshop].at_xpath("./photoshop:#{tag}")
options[field] = node.text
end
@@ -270,6 +315,16 @@ module AVM
end
private
+ def date_or_nil(field)
+ (Time.parse(@options[field]) rescue nil)
+ end
+
+ def string_date_or_nil(field)
+ return nil if !send(field)
+ send(field).strftime('%Y-%m-%d')
+ end
+
+
def alt_li_tag(text)
%{#{text}}
end
diff --git a/spec/avm/image_spec.rb b/spec/avm/image_spec.rb
index d1a66d9..b3cdd09 100644
--- a/spec/avm/image_spec.rb
+++ b/spec/avm/image_spec.rb
@@ -34,6 +34,14 @@ describe AVM::Image do
let(:fits_header) { 'FITS header' }
let(:spatial_cd_matrix) { [ 1, 2, 3, 4 ] }
+ let(:publisher) { 'Publisher' }
+ let(:publisher_id) { 'Publisher ID' }
+ let(:resource_id) { 'Resource ID' }
+ let(:resource_url) { 'Resource URL' }
+ let(:related_resources) { [ 'Resource 1', 'Resource 2' ] }
+ let(:metadata_date) { '2010-01-05' }
+ let(:metadata_version) { '1.2' }
+
def self.with_all_options
let(:options) { {
:title => title,
@@ -61,6 +69,13 @@ describe AVM::Image do
:spatial_notes => spatial_notes,
:fits_header => fits_header,
:spatial_cd_matrix => spatial_cd_matrix,
+ :publisher => publisher,
+ :publisher_id => publisher_id,
+ :resource_id => resource_id,
+ :resource_url => resource_url,
+ :related_resources => related_resources,
+ :metadata_date => metadata_date,
+ :metadata_version => metadata_version,
} }
end
@@ -96,6 +111,14 @@ describe AVM::Image do
its(:spatial_notes) { should == spatial_notes }
its(:fits_header) { should == fits_header }
its(:spatial_cd_matrix) { should == spatial_cd_matrix }
+
+ its(:publisher) { should == publisher }
+ its(:publisher_id) { should == publisher_id }
+ its(:resource_id) { should == resource_id }
+ its(:resource_url) { should == resource_url }
+ its(:related_resources) { should == related_resources }
+ its(:metadata_date) { should == Time.parse(metadata_date) }
+ its(:metadata_version) { should == metadata_version }
end
describe '#initialize' do
@@ -130,7 +153,14 @@ describe AVM::Image do
:fits_header => fits_header,
:spatial_cd_matrix => spatial_cd_matrix,
:distance => [ light_years, redshift ],
- :creator => []
+ :creator => [],
+ :publisher => publisher,
+ :publisher_id => publisher_id,
+ :resource_id => resource_id,
+ :resource_url => resource_url,
+ :related_resources => related_resources,
+ :metadata_date => Time.parse(metadata_date),
+ :metadata_version => metadata_version,
} }
its(:distance) { should == [ light_years, redshift ] }
@@ -217,8 +247,8 @@ describe AVM::Image do
which.at_xpath(xpath).text
end
- def xpath_list(which, xpath)
- which.at_xpath(xpath).search('.//rdf:li').collect(&:text)
+ def xpath_list(which, xpath, search = './/rdf:li')
+ which.at_xpath(xpath).search(search).collect(&:text)
end
it "should have the image info tags" do
@@ -229,7 +259,7 @@ describe AVM::Image do
xpath_text(avm, './avm:Distance.Notes').should == distance_notes
xpath_text(avm, './avm:Spectral.Notes').should == spectral_notes
xpath_text(avm, './avm:ReferenceURL').should == reference_url
- xpath_text(avm, './avm:Credit').should == credit
+ xpath_text(photoshop, './photoshop:Credit').should == credit
xpath_text(photoshop, './photoshop:DateCreated').should == date
xpath_text(avm, './avm:ID').should == id
xpath_text(avm, './avm:Type').should == type
@@ -250,6 +280,16 @@ describe AVM::Image do
xpath_list(avm, './avm:Spatial.CDMatrix').should == spatial_cd_matrix.collect(&:to_s)
end
+ it "should have the publisher tags" do
+ xpath_text(avm, './avm:Publisher').should == publisher
+ xpath_text(avm, './avm:PublisherID').should == publisher_id
+ xpath_text(avm, './avm:ResourceID').should == resource_id
+ xpath_text(avm, './avm:ResourceURL').should == resource_url
+ xpath_list(avm, './avm:RelatedResources', './rdf:Bag/rdf:li').should == related_resources
+ xpath_text(avm, './avm:MetadataDate').should == metadata_date
+ xpath_text(avm, './avm:MetadataVersion').should == metadata_version
+ end
+
context "distance" do
context "no distances" do
let(:redshift) { nil }
diff --git a/spec/sample_files/image/both.xmp b/spec/sample_files/image/both.xmp
index 228fce5..82b84b1 100644
--- a/spec/sample_files/image/both.xmp
+++ b/spec/sample_files/image/both.xmp
@@ -12,7 +12,6 @@
Description
-
@@ -22,6 +21,7 @@
Headline
+ Credit
2010-01-01
Spectral Notes
Distance Notes
Reference URL
- Credit
ID
Observation
Good
@@ -78,6 +77,18 @@
4
+ Publisher
+ Publisher ID
+ Resource ID
+ Resource URL
+
+
+ Resource 1
+ Resource 2
+
+
+ 2010-01-05
+ 1.2
diff --git a/spec/sample_files/image/light_years.xmp b/spec/sample_files/image/light_years.xmp
index a2c0e51..b101a54 100644
--- a/spec/sample_files/image/light_years.xmp
+++ b/spec/sample_files/image/light_years.xmp
@@ -21,6 +21,7 @@
Headline
+ Credit
2010-01-01
Spectral Notes
Distance Notes
Reference URL
- Credit
ID
Observation
Good
@@ -72,6 +72,18 @@
4
+ Publisher
+ Publisher ID
+ Resource ID
+ Resource URL
+
+
+ Resource 1
+ Resource 2
+
+
+ 2010-01-05
+ 1.2
diff --git a/spec/sample_files/image/redshift.xmp b/spec/sample_files/image/redshift.xmp
index 5106eea..9ead1f9 100644
--- a/spec/sample_files/image/redshift.xmp
+++ b/spec/sample_files/image/redshift.xmp
@@ -22,6 +22,7 @@
Headline
+ Credit
2010-01-01
Spectral Notes
Distance Notes
Reference URL
- Credit
ID
Observation
Good
@@ -78,6 +78,18 @@
4
+ Publisher
+ Publisher ID
+ Resource ID
+ Resource URL
+
+
+ Resource 1
+ Resource 2
+
+
+ 2010-01-05
+ 1.2
diff --git a/spec/sample_files/image/single_value_light_years.xmp b/spec/sample_files/image/single_value_light_years.xmp
index ec32efe..c2f4e5d 100644
--- a/spec/sample_files/image/single_value_light_years.xmp
+++ b/spec/sample_files/image/single_value_light_years.xmp
@@ -21,6 +21,7 @@
Headline
+ Credit
2010-01-01
Spectral Notes
Distance Notes
Reference URL
- Credit
ID
Observation
Good
@@ -72,6 +72,18 @@
4
+ Publisher
+ Publisher ID
+ Resource ID
+ Resource URL
+
+
+ Resource 1
+ Resource 2
+
+
+ 2010-01-05
+ 1.2