#!/usr/bin/env ruby # get the rails environment up and running so we have # access to the models and environment env = ENV['RAILS_ENV'] || 'production' require File.dirname(__FILE__) + '/../config/boot' require 'marc' require 'yaml' # use rails configuration to create db connection db_config = YAML::load_file "#{RAILS_ROOT}/config/database.yml" ActiveRecord::Base.establish_connection(db_config[env]) isbn_re = /([0-9]{9}[0-9X])/ count = 1 while count < 135051 #221033 count += 1 item = Item.find(:first, :conditions => ['id = ?', count]) next if ! item # clean publisher item.publisher.sub!(/\W+$/,'') if item.publisher # get additional data record = item.marc_record # get author item.author = record['100'] ? record['100']['a'] : nil # get isbn if record['020'] and record['020']['a'] match = isbn_re.match record['020']['a'] item.isbn = match[0] if match end # get call number item.callnumber = record['092'] ? record['092']['a'] : nil # get title_normal item.title_normal = record['245']['a'] non_filing = record['245'].indicator2.to_i if non_filing > 0 item.title_normal = record['245']['a'][non_filing .. -1] end item.save puts count end