basic image tags
This commit is contained in:
parent
179d017f37
commit
3aede05d1b
|
@ -15,6 +15,24 @@ module AVM
|
|||
|
||||
creator.add_to_document(document)
|
||||
|
||||
document.get_refs do |refs|
|
||||
[ :title, :description ].each do |field|
|
||||
refs[:dublin_core].add_child(%{<dc:#{field}>#{alt_li_tag(send(field))}</dc:#{field}>})
|
||||
end
|
||||
|
||||
refs[:photoshop].add_child(%{<photoshop:Headline>#{headline}</photoshop:Headline>})
|
||||
|
||||
{
|
||||
'Distance.Notes' => distance_notes,
|
||||
'ReferenceURL' => reference_url,
|
||||
'Credit' => credit,
|
||||
'Date' => string_date,
|
||||
'ID' => id,
|
||||
}.each do |tag, value|
|
||||
refs[:avm].add_child(%{<avm:#{tag}>#{value}</avm:#{tag}>}) if value
|
||||
end
|
||||
end
|
||||
|
||||
document.doc
|
||||
end
|
||||
|
||||
|
@ -27,7 +45,12 @@ module AVM
|
|||
end
|
||||
|
||||
def date
|
||||
Time.parse(@options[:date])
|
||||
(Time.parse(@options[:date]) rescue nil)
|
||||
end
|
||||
|
||||
def string_date
|
||||
return nil if !date
|
||||
date.strftime('%Y-%m-%d')
|
||||
end
|
||||
|
||||
def distance
|
||||
|
@ -45,6 +68,11 @@ module AVM
|
|||
def method_missing(method)
|
||||
@options[method]
|
||||
end
|
||||
|
||||
private
|
||||
def alt_li_tag(text)
|
||||
%{<rdf:Alt><rdf:li xml:lang="x-default">#{text}</rdf:li></rdf:Alt>}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,6 +2,12 @@ require 'nokogiri'
|
|||
|
||||
module AVM
|
||||
class XMP
|
||||
PREFIXES = {
|
||||
'dc' => 'Dublin Core',
|
||||
'Iptc4xmpCore' => 'IPTC',
|
||||
'Photoshop' => 'Photoshop'
|
||||
}
|
||||
|
||||
attr_reader :doc
|
||||
|
||||
def initialize(doc = nil)
|
||||
|
@ -11,7 +17,7 @@ module AVM
|
|||
end
|
||||
|
||||
def get_refs
|
||||
yield Hash[[ :dublin_core, :iptc ].collect { |key| [ key, send(key) ] }]
|
||||
yield Hash[[ :dublin_core, :iptc, :photoshop, :avm ].collect { |key| [ key, send(key) ] }]
|
||||
end
|
||||
|
||||
def self.from_string(string)
|
||||
|
@ -36,12 +42,7 @@ module AVM
|
|||
doc.search('//rdf:Description').each do |description|
|
||||
if first_child = description.first_element_child
|
||||
if first_child.namespace
|
||||
case first_child.namespace.prefix
|
||||
when 'dc'
|
||||
description['about'] = 'Dublin Core'
|
||||
when 'Iptc4xmpCore'
|
||||
description['about'] = 'IPTC'
|
||||
end
|
||||
description['about'] = PREFIXES[first_child.namespace.prefix]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -55,6 +56,14 @@ module AVM
|
|||
at_rdf_description "IPTC"
|
||||
end
|
||||
|
||||
def avm
|
||||
at_rdf_description "AVM"
|
||||
end
|
||||
|
||||
def photoshop
|
||||
at_rdf_description "Photoshop"
|
||||
end
|
||||
|
||||
def at_rdf_description(about)
|
||||
@doc.at_xpath(%{//rdf:Description[@about="#{about}"]})
|
||||
end
|
||||
|
@ -63,12 +72,10 @@ module AVM
|
|||
Nokogiri::XML(<<-XML)
|
||||
<x:xmpmeta xmlns:x="adobe:ns:meta/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<rdf:RDF>
|
||||
<rdf:Description about="Dublin Core">
|
||||
|
||||
</rdf:Description>
|
||||
<rdf:Description about="IPTC">
|
||||
|
||||
</rdf:Description>
|
||||
<rdf:Description about="Dublin Core" />
|
||||
<rdf:Description about="IPTC" />
|
||||
<rdf:Description about="Photoshop" />
|
||||
<rdf:Description about="AVM" />
|
||||
</rdf:RDF>
|
||||
</x:xmpmeta>
|
||||
XML
|
||||
|
|
|
@ -7,9 +7,20 @@ describe AVM::Image do
|
|||
|
||||
subject { image }
|
||||
|
||||
describe '#initialize' do
|
||||
it { should be_a_kind_of(AVM::Image) }
|
||||
let(:title) { 'My title' }
|
||||
let(:headline) { 'Headline' }
|
||||
let(:description) { 'Description' }
|
||||
let(:distance_notes) { 'Distance Notes' }
|
||||
let(:reference_url) { 'Reference URL' }
|
||||
let(:credit) { 'Credit' }
|
||||
let(:date) { '2010-01-01' }
|
||||
let(:id) { 'ID' }
|
||||
let(:type) { 'Obvservation' }
|
||||
let(:image_quality) { 'Good' }
|
||||
let(:redshift) { 'Redshift' }
|
||||
let(:light_years) { 'Light years' }
|
||||
|
||||
def self.with_all_options
|
||||
let(:options) { {
|
||||
:title => title,
|
||||
:headline => headline,
|
||||
|
@ -24,19 +35,12 @@ describe AVM::Image do
|
|||
:redshift => redshift,
|
||||
:light_years => light_years
|
||||
} }
|
||||
end
|
||||
|
||||
let(:title) { 'My title' }
|
||||
let(:headline) { 'Headline' }
|
||||
let(:description) { 'Description' }
|
||||
let(:distance_notes) { 'Distance Notes' }
|
||||
let(:reference_url) { 'Reference URL' }
|
||||
let(:credit) { 'Credit' }
|
||||
let(:date) { '2010-01-01' }
|
||||
let(:id) { 'ID' }
|
||||
let(:type) { 'Obvservation' }
|
||||
let(:image_quality) { 'Good' }
|
||||
let(:redshift) { 'Redshift' }
|
||||
let(:light_years) { 'Light years' }
|
||||
describe '#initialize' do
|
||||
with_all_options
|
||||
|
||||
it { should be_a_kind_of(AVM::Image) }
|
||||
|
||||
its(:creator) { should be_a_kind_of(AVM::Creator) }
|
||||
its(:title) { should == title }
|
||||
|
@ -58,9 +62,50 @@ describe AVM::Image do
|
|||
describe '#to_xml' do
|
||||
let(:xml) { image.to_xml }
|
||||
|
||||
let(:dublin_core) { xml.at_xpath('//rdf:Description[@about="Dublin Core"]') }
|
||||
let(:photoshop) { xml.at_xpath('//rdf:Description[@about="Photoshop"]') }
|
||||
let(:avm) { xml.at_xpath('//rdf:Description[@about="AVM"]') }
|
||||
|
||||
context 'nothing in it' do
|
||||
subject { xml.at_xpath('//rdf:RDF').should_not be_nil }
|
||||
subject { xml.search('//rdf:RDF/rdf:Description').should be_empty }
|
||||
it "should have basic tags" do
|
||||
xml.at_xpath('//rdf:RDF').should_not be_nil
|
||||
xml.search('//rdf:RDF/rdf:Description').should_not be_empty
|
||||
avm.at_xpath('./avm:Date').should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'with basics' do
|
||||
with_all_options
|
||||
|
||||
it "should have the image info tags" do
|
||||
dublin_core.at_xpath('./dc:title/rdf:Alt/rdf:li').text.should == title
|
||||
photoshop.at_xpath('./photoshop:Headline').text.should == headline
|
||||
dublin_core.at_xpath('./dc:description/rdf:Alt/rdf:li').text.should == description
|
||||
|
||||
avm.at_xpath('./avm:Distance.Notes').text.should == distance_notes
|
||||
avm.at_xpath('./avm:ReferenceURL').text.should == reference_url
|
||||
avm.at_xpath('./avm:Credit').text.should == credit
|
||||
avm.at_xpath('./avm:Date').text.should == date
|
||||
avm.at_xpath('./avm:ID').text.should == id
|
||||
end
|
||||
|
||||
context "distance" do
|
||||
context "no distances" do
|
||||
|
||||
end
|
||||
|
||||
context "redshift only" do
|
||||
|
||||
end
|
||||
|
||||
context "light years only" do
|
||||
|
||||
end
|
||||
|
||||
context "redshift and light years" do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,11 +11,14 @@ describe AVM::XMP do
|
|||
xmp.get_refs do |refs|
|
||||
refs[:dublin_core] << "<rdf:addedToDublinCore />"
|
||||
refs[:iptc] << "<rdf:addedToIPTC />"
|
||||
refs[:photoshop] << '<rdf:addedToPhotoshop />'
|
||||
end
|
||||
}
|
||||
|
||||
specify { xmp.doc.at_xpath('//rdf:Description[@about="Dublin Core"]//rdf:addedToDublinCore').should_not be_nil }
|
||||
specify { xmp.doc.at_xpath('//rdf:Description[@about="IPTC"]//rdf:addedToIPTC').should_not be_nil }
|
||||
it "should have gotten the refs correctly" do
|
||||
xmp.doc.at_xpath('//rdf:Description[@about="Dublin Core"]//rdf:addedToDublinCore').should_not be_nil
|
||||
xmp.doc.at_xpath('//rdf:Description[@about="IPTC"]//rdf:addedToIPTC').should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '.from_string' do
|
||||
|
|
Loading…
Reference in New Issue