From d3113968a9b56b5aab9bae7919648ce0245fc293 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 11 Mar 2011 13:59:34 -0500 Subject: [PATCH] starting work on image fields --- lib/avm/image.rb | 19 ++++++++++++++++++- spec/avm/image_spec.rb | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/lib/avm/image.rb b/lib/avm/image.rb index 4fbc93d..57570cd 100644 --- a/lib/avm/image.rb +++ b/lib/avm/image.rb @@ -5,8 +5,9 @@ module AVM class Image attr_reader :creator - def initialize + def initialize(options = {}) @creator = AVM::Creator.new(self) + @options = options end def to_xml @@ -17,6 +18,18 @@ module AVM document.doc end + def id + @options[:id] + end + + def image_type + @options[:type] + end + + def date + Time.parse(@options[:date]) + end + def self.from_xml(string) document = AVM::XMP.from_string(string) @@ -24,6 +37,10 @@ module AVM image.creator.from_xml(self, document) image end + + def method_missing(method) + @options[method] + end end end diff --git a/spec/avm/image_spec.rb b/spec/avm/image_spec.rb index a043fa5..d0d94cf 100644 --- a/spec/avm/image_spec.rb +++ b/spec/avm/image_spec.rb @@ -2,14 +2,49 @@ require 'spec_helper' require 'avm/image' describe AVM::Image do - let(:image) { self.class.describes.new } + let(:image) { self.class.describes.new(options) } + let(:options) { {} } subject { image } describe '#initialize' do 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(: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 describe '#to_xml' do