starting work on image fields

This commit is contained in:
John Bintz 2011-03-11 13:59:34 -05:00
parent b11d2813cd
commit d3113968a9
2 changed files with 54 additions and 2 deletions

View File

@ -5,8 +5,9 @@ module AVM
class Image class Image
attr_reader :creator attr_reader :creator
def initialize def initialize(options = {})
@creator = AVM::Creator.new(self) @creator = AVM::Creator.new(self)
@options = options
end end
def to_xml def to_xml
@ -17,6 +18,18 @@ module AVM
document.doc document.doc
end end
def id
@options[:id]
end
def image_type
@options[:type]
end
def date
Time.parse(@options[:date])
end
def self.from_xml(string) def self.from_xml(string)
document = AVM::XMP.from_string(string) document = AVM::XMP.from_string(string)
@ -24,6 +37,10 @@ module AVM
image.creator.from_xml(self, document) image.creator.from_xml(self, document)
image image
end end
def method_missing(method)
@options[method]
end
end end
end end

View File

@ -2,14 +2,49 @@ require 'spec_helper'
require 'avm/image' require 'avm/image'
describe AVM::Image do describe AVM::Image do
let(:image) { self.class.describes.new } let(:image) { self.class.describes.new(options) }
let(:options) { {} }
subject { image } subject { image }
describe '#initialize' do describe '#initialize' do
it { should be_a_kind_of(AVM::Image) } it { should be_a_kind_of(AVM::Image) }
let(:options) { {
:title => title,
:headline => headline,
:description => description,
:distance_notes => distance_notes,
:reference_url => reference_url,
:credit => credit,
:date => date,
:id => id,
:type => type,
:image_quality => image_quality
} }
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' }
its(:creator) { should be_a_kind_of(AVM::Creator) } its(:creator) { should be_a_kind_of(AVM::Creator) }
its(:title) { should == title }
its(:headline) { should == headline }
its(:description) { should == description }
its(:distance_notes) { should == distance_notes }
its(:reference_url) { should == reference_url }
its(:credit) { should == credit }
its(:date) { should == Time.parse(date) }
its(:id) { should == id }
its(:image_type) { should == type }
its(:image_quality) { should == image_quality }
end end
describe '#to_xml' do describe '#to_xml' do