Created
April 23, 2015 14:09
-
-
Save cfitz/397b25d57c85a1aabf54 to your computer and use it in GitHub Desktop.
Add lots of dates and extents to the ASPACE accession CSV importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add this plugin to plugins/local/backend/model/accession_converter.rb | |
# this plugin allows the CSV importer to have columns like date_3_label, date_3_expression, | |
# extent_2_type, extent_2_container_summary etc. | |
class AccessionConverter < Converter | |
# we alias the old configure method... | |
self.singleton_class.send(:alias_method,:old_configure, :configure) | |
def self.configure | |
config = {} | |
# lets make 10 sets of date columns | |
10.times do |ii| | |
i = ii.to_s | |
config.merge!({ "date_#{i}_label" => "date_#{i}.label", | |
"date_#{i}_expression" => "date_#{i}.expression", | |
"date_#{i}_begin" => "date_#{i}.begin", | |
"date_#{i}_end" => "date_#{i}.end", | |
"date_#{i}_type" => "date_#{i}.date_type" }) | |
config.merge!( | |
{ "date_#{i.to_s}".intern => { | |
:record_type => :date, | |
:defaults => date_defaults, | |
:on_row_complete => Proc.new { |queue, date| | |
queue.select {|obj| obj.class.record_type == 'accession'}.each do |accession| | |
accession.dates << date | |
end | |
} | |
} | |
} | |
) | |
#and 10 sets of extent columns | |
config.merge!({ | |
"extent_#{i}_type" => "extent_#{i}.extent_type", | |
"extent_#{i}_container_summary" => "extent_#{i}.container_summary", | |
"extent_#{i}_number" => "extent_#{i}.number" | |
}) | |
config.merge!({ | |
"extent_#{i}".intern => { | |
:record_type => :extent, | |
:defaults => {:portion => 'whole'}, | |
:on_row_complete => Proc.new { |queue, extent| | |
queue.select {|obj| obj.class.record_type == 'accession'}.each do |accession| | |
accession.extents << extent | |
end | |
} | |
} | |
}) | |
end | |
# and we add that to the rest of our configuration | |
config.merge(self.old_configure) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment