From a385458eaaa29844ad516ce1ae64c0f48ec4ab32 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 16 Jul 2007 19:27:36 +0000 Subject: [PATCH] lots of changes to get it working with zcc.record instead of marc.record objects git-svn-id: svn+ssh://rubyforge.org/var/svn/zcc/trunk@209 695555e7-a3f4-42c9-822d-1d0ed3746087 --- bin/zcc-new | 42 ++++++++++++++++++++++-------------------- examples/zcc.yaml | 1 + lib/zcc/cli_display.rb | 23 ++++++++++++----------- lib/zcc/marcadditions.rb | 21 ++++++++++++++------- lib/zcc/query.rb | 6 +++++- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/bin/zcc-new b/bin/zcc-new index 09e9469..fa3350b 100644 --- a/bin/zcc-new +++ b/bin/zcc-new @@ -95,39 +95,41 @@ loop { exit if search_term == ':q' # # -query = Query.new(search_term, zserver_objects[0]) -results = query.search(5) + query = Query.new(search_term, zserver_objects) + results = query.search(25) + #print "results.class: " #puts results.class #puts results.to_s taken = zcc_select_good_marc(results, 'one') # # - +final_taken = taken[0] + #SCRIPTING and EDITING if SCRIPTING print $clear_code print "\a" - say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") + say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}") say("<%= color('SCRIPTING...', :headline) %>") - final_taken.local_script(scripting) + final_taken.marc.local_script(scripting) end if EDITING print $clear_code print "\a" - say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") + say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}") say("Would you like to <%= color('edit', :headline) %> this record [yes or ANYTHING]? ") edit = STDIN.gets.chomp if edit == ('y' or 'yes') print $clear_code - say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") - final_taken.edit + say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}") + final_taken.marc.edit end end print $clear_code say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}', :headline) %>") - say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") + say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}") say("<%= color('#{'-'*20}FINAL RECORD#{'-'*20}\a', :headline) %>") print "Would you like to keep this FINAL RECORD? (ANYTHING or n)" @@ -140,9 +142,9 @@ taken = zcc_select_good_marc(results, 'one') if CSV print $clear_code print "\a" - say("#{ZCC.zcc_marc_str_bold(final_taken.to_s, 'record')}") + say("#{ZCC.zcc_marc_str_bold(final_taken.marc.to_s, 'record')}") say("<%= color('Label making time!', :headline) %>") - csv = final_taken.marc_to_csv(labels) + csv = final_taken.marc.marc_to_csv(labels) print "Final csv:\n#{csv}\n" end @@ -159,34 +161,34 @@ taken = zcc_select_good_marc(results, 'one') if FORMAT_TO_SAVE == 'marc' aFile = File.new("#{filename}\.mrc","a+") - aFile.write(final_taken.to_marc) - puts "#{final_taken['245']['a']} saved in #{filename}\.mrc" + aFile.write(final_taken.marc.to_marc) + puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc" aFile.close elsif FORMAT_TO_SAVE == 'marcxml' - puts final_taken.to_xml + puts final_taken.marc.to_xml aFile = File.new("#{filename}\.xml","a+") - aFile.write(final_taken.to_xml) - puts "#{final_taken['245']['a']} saved in #{filename}\.xml" + aFile.write(final_taken.marc.to_xml) + puts "#{final_taken.marc['245']['a']} saved in #{filename}\.xml" aFile.close elsif FORMAT_TO_SAVE == 'zebra' #puts final_taken.to_xml File.open("#{File.expand_path("~")}/.zcc/zebra/records/#{Time.now.strftime("%Y%m%d%H%M%S")}\.mrc", "w") do |f| - f.write final_taken.to_marc + f.write final_taken.marc.to_marc end Dir.chdir("#{File.expand_path("~")}/.zcc/zebra") do record_update = `zebraidx update records` puts record_update end aFile = File.new("#{filename}\.mrc","a+") - aFile.write(final_taken.to_marc) - puts "#{final_taken['245']['a']} saved in #{filename}\.mrc" + aFile.write(final_taken.marc.to_marc) + puts "#{final_taken.marc['245']['a']} saved in #{filename}\.mrc" aFile.close end if CSV csvFile = File.new("csv-#{filename}\.txt","a+") csvFile.write(csv) - puts "csv for #{final_taken['245']['a']} saved in csv-#{filename}\.txt" + puts "csv for #{final_taken.marc['245']['a']} saved in csv-#{filename}\.txt" csvFile.close end diff --git a/examples/zcc.yaml b/examples/zcc.yaml index a1b6a9f..c2de0ff 100644 --- a/examples/zcc.yaml +++ b/examples/zcc.yaml @@ -30,6 +30,7 @@ linter_on: yes #'marc' means ISO2709, marc transmission format, not human readable #'xml' currently means marcxml #'zebra' means marc IS02709 saved to the directory of the zebra database by timestamp. +# STILL TO BE IMPLEMENTED: 'koha' save directly to a koha installation using bulkmarcimport.pl # for 'zebra' a copy is also saved to the working directory. #See for more information on setting up zebra: http://zcc.rubyforge.org/zebra.html save_record_syntax: zebra diff --git a/lib/zcc/cli_display.rb b/lib/zcc/cli_display.rb index 8b9d72e..197b034 100755 --- a/lib/zcc/cli_display.rb +++ b/lib/zcc/cli_display.rb @@ -8,9 +8,9 @@ module ZCC #puts self rec_copy = results.records - puts rec_copy.class - puts rec_copy.inspect - STDIN.gets + #puts rec_copy.class + #puts rec_copy.inspect + #STDIN.gets #rec_copy = rec_copy.sort_by {|rec| rec['245']['a']} clear = %x{clear} #print clear @@ -75,7 +75,7 @@ module ZCC for x in index_range menu.hidden("#{x}".intern, help_num) do |cmd, details| print "\a" - say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].to_s, 'record')}") + say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].marc.to_s, 'record')}") ask("<%= color('Hit ENTER to continue...', :headline) %> ") end end @@ -126,10 +126,10 @@ module ZCC end comparison.each do |compare| menu.hidden(compare, help_c) do |cmd, details| - say("<%= color('comparison:', :headline) %> ") + say("<%= color('comparison:', :headline) %>") cmd = cmd[1,99] compare_nums = cmd.split('-') - rec_copy[compare_nums[0].to_i].compare_marc(rec_copy[compare_nums[1].to_i]) + compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i]) ask("<%= color('Hit ENTER to continue...', :headline) %> ") #STDIN.gets next @@ -139,12 +139,12 @@ module ZCC # lint menu.choice('l#', help_l) do |cmd, d| say_help(help_l) - ask("Which record do you want to lint? ") + #ask("Which record do you want to lint? ") end menu.hidden(:lint) {|cmd, d| say(help_l)} for x in (0..recs_length - 1) menu.hidden("l#{x}") do |cmd, d| - rec_copy[cmd[1,99].to_i].linter + rec_copy[cmd[1,99].to_i].marc.linter ask("<%= color('Hit ENTER to continue...', :headline) %> ") end end @@ -186,11 +186,12 @@ module ZCC end def display_menu(rec_copy, index) - puts rec_copy.class - puts rec_copy[index].class - STDIN.gets + #puts rec_copy.class + #puts rec_copy[index].class + #STDIN.gets field_width = $term_width - 8 say("<%= color(\"#{index}\", :index) %> ") + puts rec_copy[index].zserver.to_s ['245', '260', '300'].each do |field| string = rec_copy[index].marc[field].to_s string.rstrip! diff --git a/lib/zcc/marcadditions.rb b/lib/zcc/marcadditions.rb index 763c2ca..408e0e3 100755 --- a/lib/zcc/marcadditions.rb +++ b/lib/zcc/marcadditions.rb @@ -171,12 +171,21 @@ module MARC record end - #++ compare() is a method to print out a comparison of two MARC records tag by tag (not by subfields). + + end +end + +module ZCC + #++ compare() is a method to print out a comparison of two MARC records tag by tag (not by subfields). # A match between lines is denoted with a 'm'. If there are differences between the records, # the object that recieves the compare call is denoted with a '+' and the object passed in # parens is denoted with '-'. - def compare_marc(rec2) - orig = self.dup + def compare_marc(orig, rec2) + puts "+ = #{orig.zserver.to_s}" + puts "- = #{rec2.zserver.to_s}" + orig = orig.marc + rec2 = rec2.marc + for ft in ('000'..'999') fields_original = orig.find_all {|f| f.tag == ft} fields_record2 = rec2.find_all {|f| f.tag == ft} @@ -196,10 +205,8 @@ module MARC fields_rec2.each {|f| puts "- #{f}"} if fields_rec2 end end - end -end - -module ZCC + + def ZCC.lccn_conversion lccn split_lccn = lccn.split('-') year_len = split_lccn[0].length diff --git a/lib/zcc/query.rb b/lib/zcc/query.rb index 00d3040..d710410 100644 --- a/lib/zcc/query.rb +++ b/lib/zcc/query.rb @@ -8,6 +8,8 @@ module ZCC #puts "term: " + self.term @zservers = [] @zservers << zservers #=>array of Zserver objects + self.zservers.compact! + self.zservers.flatten! #puts self.inspect #puts self.zservers[0].to_s end @@ -42,14 +44,16 @@ module ZCC def zoom(show = 10) result_set = ResultSet.new(self) + puts zservers.inspect self.zservers.each do |server| - #zservers are made up of... + puts server.to_s conn = ZOOM::Connection.new conn.connect(server.host, server.port) #do |conn conn.set_option('charset', 'UTF-8') conn.preferred_record_syntax = 'MARC21' conn.database_name = server.database + rset = conn.search(self.zsearch) rset_recs = rset[0, show] #puts "rset_recs in query.search: " -- 2.11.4.GIT