From 864b3c2417cb61d52dc9299f1750024285504768 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 30 Mar 2011 10:09:35 -0400 Subject: [PATCH] add proposal id and better serialization --- .gitignore | 3 +- .rspec | 6 ++-- Gemfile | 2 ++ lib/avm/image.rb | 29 +++++++++++++------ lib/ruby-avm-library/version.rb | 2 +- spec/avm/image_spec.rb | 22 +++++++++----- spec/quick_fix_formatter.rb | 26 ----------------- spec/sample_files/image/both.xmp | 1 + spec/sample_files/image/light_years.xmp | 1 + spec/sample_files/image/redshift.xmp | 1 + .../image/single_value_light_years.xmp | 1 + 11 files changed, 46 insertions(+), 48 deletions(-) delete mode 100644 spec/quick_fix_formatter.rb diff --git a/.gitignore b/.gitignore index 7daf373..82e9f3e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .bundle Gemfile.lock pkg/* -.quickfix.txt +.quickfix-out + diff --git a/.rspec b/.rspec index db400bf..29d0eba 100644 --- a/.rspec +++ b/.rspec @@ -1,5 +1,5 @@ -c ---require ./spec/quick_fix_formatter.rb --format progress ---format RSpec::Core::Formatters::QuickFixFormatter ---out .quickfix.txt +--require rspec/quickfix-formatter +--format RSpec::QuickFixFormatter +--out .quickfix-out diff --git a/Gemfile b/Gemfile index efde300..94e1066 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,8 @@ source "http://rubygems.org" # Specify your gem's dependencies in ruby-avm-library.gemspec gemspec +gem 'rspec-quickfix-formatter', :git => 'git://github.com/johnbintz/rspec-quickfix-formatter.git' + group :test do gem 'autotest' end diff --git a/lib/avm/image.rb b/lib/avm/image.rb index 6cb1a4a..04ce005 100644 --- a/lib/avm/image.rb +++ b/lib/avm/image.rb @@ -61,6 +61,7 @@ module AVM 'MetadataDate', 'MetadataVersion', 'Subject.Category', + 'ProposalID' ] AVM_SINGLE_METHODS = [ @@ -90,7 +91,8 @@ module AVM :related_resources, :metadata_date, :metadata_version, - :categories + :categories, + :proposal_id ] AVM_SINGLE_MESSAGES = [ @@ -120,7 +122,8 @@ module AVM :related_resources, :string_metadata_date, :metadata_version, - :categories + :categories, + :proposal_id ] AVM_SINGLES = AVM_SINGLE_FIELDS.zip(AVM_SINGLE_METHODS) @@ -135,6 +138,9 @@ module AVM :reference_value ] + SEMICOLON_AVM_FIELDS = [ :categories, :proposal_id ] + :wa + HASH_FIELDS = [ :title, :headline, :description, :distance_notes, :spectral_notes, :reference_url, :credit, :date, :id, :image_type, :image_quality, :coordinate_frame, @@ -142,7 +148,8 @@ module AVM :spatial_scale, :spatial_rotation, :coordinate_system_projection, :spatial_quality, :spatial_notes, :fits_header, :spatial_cd_matrix, :distance, :publisher, :publisher_id, :resource_id, :resource_url, - :related_resources, :metadata_date, :metadata_version, :subject_names, :categories + :related_resources, :metadata_date, :metadata_version, :subject_names, :categories, + :proposal_id ] attr_reader :creator, :observations @@ -191,12 +198,16 @@ module AVM AVM_SINGLES_FOR_MESSAGES.each do |tag, message| if value = send(message) - case value - when Array - container_tag = (message == :related_resources) ? 'Bag' : 'Seq' - value = "" + value.collect { |v| "#{v.to_s}" }.join + "" + if SEMICOLON_AVM_FIELDS.include?(message) + value = value.join(';') else - value = value.to_s + case value + when Array + container_tag = (message == :related_resources) ? 'Bag' : 'Seq' + value = "" + value.collect { |v| "#{v.to_s}" }.join + "" + else + value = value.to_s + end end refs[:avm].add_child(%{#{value}}) @@ -280,7 +291,7 @@ module AVM AVM_SINGLES.each do |tag, field| if node = refs[:avm].at_xpath("./avm:#{tag}") - if field == :categories + if SEMICOLON_AVM_FIELDS.include?(field) options[field] = node.text.split(";").collect(&:strip) else if !(list_items = node.search('.//rdf:li')).empty? diff --git a/lib/ruby-avm-library/version.rb b/lib/ruby-avm-library/version.rb index a9a02cb..69ea793 100644 --- a/lib/ruby-avm-library/version.rb +++ b/lib/ruby-avm-library/version.rb @@ -1,7 +1,7 @@ module Ruby module Avm module Library - VERSION = "0.0.1" + VERSION = "0.0.2" end end end diff --git a/spec/avm/image_spec.rb b/spec/avm/image_spec.rb index 2a36719..7d24f13 100644 --- a/spec/avm/image_spec.rb +++ b/spec/avm/image_spec.rb @@ -44,6 +44,7 @@ describe AVM::Image do let(:related_resources) { [ 'Resource 1', 'Resource 2' ] } let(:metadata_date) { '2010-01-05' } let(:metadata_version) { '1.2' } + let(:proposal_id) { [ 'one', 'two', 'three' ] } def self.with_all_options let(:options) { { @@ -80,7 +81,8 @@ describe AVM::Image do :metadata_date => metadata_date, :metadata_version => metadata_version, :subject_names => subject_names, - :categories => categories + :categories => categories, + :proposal_id => proposal_id } } end @@ -124,6 +126,7 @@ describe AVM::Image do its(:related_resources) { should == related_resources } its(:metadata_date) { should == Time.parse(metadata_date) } its(:metadata_version) { should == metadata_version } + its(:proposal_id) { should == proposal_id } its(:subject_names) { should == subject_names } its(:categories) { should == categories } @@ -152,16 +155,16 @@ describe AVM::Image do :image_quality => avm_image_quality.new, :coordinate_frame => avm_coordinate_frame.new, :equinox => equinox, - :reference_value => reference_value, - :reference_dimension => reference_dimension, - :reference_pixel => reference_pixel, - :spatial_scale => spatial_scale, + :reference_value => reference_value.collect(&:to_f), + :reference_dimension => reference_dimension.collect(&:to_f), + :reference_pixel => reference_pixel.collect(&:to_f), + :spatial_scale => spatial_scale.collect(&:to_f), :spatial_rotation => spatial_rotation, :coordinate_system_projection => avm_coordinate_system_projection.new, :spatial_quality => avm_spatial_quality.new, :spatial_notes => spatial_notes, :fits_header => fits_header, - :spatial_cd_matrix => spatial_cd_matrix, + :spatial_cd_matrix => spatial_cd_matrix.collect(&:to_f), :distance => [ light_years, redshift ], :creator => [], :publisher => publisher, @@ -173,7 +176,8 @@ describe AVM::Image do :metadata_version => metadata_version, :subject_names => subject_names, :categories => categories, - :observations => [] + :observations => [], + :proposal_id => proposal_id } } its(:distance) { should == [ light_years, redshift ] } @@ -199,7 +203,7 @@ describe AVM::Image do :light_years, :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, :subject_names, :categories + :fits_header, :spatial_cd_matrix, :subject_names, :categories, :proposal_id ].each do |field| its(field) { should be_nil } end @@ -285,6 +289,8 @@ describe AVM::Image do xpath_text(avm, './avm:ID').should == id xpath_text(avm, './avm:Type').should == type xpath_text(avm, './avm:Image.ProductQuality').should == image_quality + xpath_text(avm, './avm:Subject.Category').should == categories.join(';') + xpath_text(avm, './avm:ProposalID').should == proposal_id.join(';') end it "should have the spatial tags" do diff --git a/spec/quick_fix_formatter.rb b/spec/quick_fix_formatter.rb deleted file mode 100644 index 60df233..0000000 --- a/spec/quick_fix_formatter.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rspec/core/formatters/base_text_formatter' - -module RSpec - module Core - module Formatters - class QuickFixFormatter < BaseTextFormatter - def dump_summary(duration, example_count, failure_count, pending_count) - end - - def dump_profile - end - - def dump_pending - end - - def dump_failures - failed_examples.each do |example| - output.puts "%s:%s:%s" % [ example.file_path, example.metadata[:line_number], example.metadata[:execution_result][:exception].message ] - end - end - end - end - end -end - - diff --git a/spec/sample_files/image/both.xmp b/spec/sample_files/image/both.xmp index 2c071a3..6da519a 100644 --- a/spec/sample_files/image/both.xmp +++ b/spec/sample_files/image/both.xmp @@ -96,6 +96,7 @@ 2010-01-05 1.2 + one;two;three diff --git a/spec/sample_files/image/light_years.xmp b/spec/sample_files/image/light_years.xmp index 1b3aebd..9314a9c 100644 --- a/spec/sample_files/image/light_years.xmp +++ b/spec/sample_files/image/light_years.xmp @@ -91,6 +91,7 @@ 2010-01-05 1.2 + one;two;three diff --git a/spec/sample_files/image/redshift.xmp b/spec/sample_files/image/redshift.xmp index cfbade3..574f9e8 100644 --- a/spec/sample_files/image/redshift.xmp +++ b/spec/sample_files/image/redshift.xmp @@ -96,6 +96,7 @@ 2010-01-05 1.2 + one;two;three diff --git a/spec/sample_files/image/single_value_light_years.xmp b/spec/sample_files/image/single_value_light_years.xmp index 85cedbf..faad9ca 100644 --- a/spec/sample_files/image/single_value_light_years.xmp +++ b/spec/sample_files/image/single_value_light_years.xmp @@ -91,6 +91,7 @@ 2010-01-05 1.2 + one;two;three