lib/zcc/pickers.rb in zcc-0.0.2 vs lib/zcc/pickers.rb in zcc-0.0.3

- old
+ new

@@ -1,66 +1,139 @@ -module Pickers - def select_good_marc(take_how_many) +module ZCC + def ZCC.display_menu(rec_copy, index) + field_width = $term_width - 8 + say("<%= color(\"#{index}\", :index) %> ") + ['245', '260', '300'].each do |field| + string = rec_copy[index][field].to_s + string.rstrip! + string.lstrip! + if string.length < field_width + say("\t#{ZCC.zcc_marc_str_bold(string, field)}") + else + better_string = ZCC.wrap_field(string, field_width) + #puts better_string + say("\t#{ZCC.zcc_marc_str_bold(better_string, field)}") + + end + end + end + + #currently this goes word by word. how difficult to go field by subfield? + def ZCC.wrap_field(s, width) + lines = [] + line = "" + smaller_width = width - 7 + s.split(/\s+/).each do |word| + if (line.size + word.size) >= (width - 3) + lines << line + line = word + width = smaller_width + elsif line.empty? + line = word + else + line << " " << word + end + end + lines << line if line + return lines.join "\n\t\t" + end + + + def ZCC.zcc_marc_str_bold(string, field) + #puts field + string.gsub!("'", "\'") + #string.gsub!("(", "\(") + #string.gsub!(")", "\)") + if field == '245' + string.gsub!(/(\$a\s)(.*?)(\$.)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3") + elsif field == '260' + #puts 'gets here' + string.gsub!(/(\$c\s)([\[0-9A-Za-z\]]*)(.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3") + + #string.gsub!(/(\$c)(.*)(\$\s)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3") + #string.gsub!(/(\$c)(.*)(\.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3") + elsif field == '300' + string.gsub!(/(\$a)(.*?)(\$|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3") + elsif field == 'record' + string.sub!(/(LEADER.{19})(.{1})/, "\\1<%= color(\"\\2\", :headline) %>") #colorizes the value of the standard (AACR2, ISBD, or none) + end + + string.gsub!( /\$(.)/, "<%= color('$\\1', :marc_tag) %>" ) + string.gsub!( /^(\d\d\d)\s/, "<%= color('\\1 ', :marc_tag) %>") + string + end + + def ZCC.not_valid_value + print $clear_code + say("\a<%= color(\"That's not a valid value. Try again.\", :headline) %> ") + sleep 1 + print "\a" + end + + +end + + +class Array + def zcc_select_good_marc(take_how_many) #puts self[0] unless self[0].is_a? MARC::Record raise ArgumentError, "This Array doesn't have a MARC::Record!" end - #puts self - rec_copy = self.dup - #print "rec_copy.length: ", rec_copy.length - #print "rec_copy.class: ", rec_copy.class - #puts rec_copy[3] #if it chokes on a record uncomment and include the record number - #i = 0 + rec_copy = self.dup + rec_copy = rec_copy.sort_by {|rec| rec['245']['a']} + recs_to_return = [] loop { - rec_copy.each_index do #This block lists - |index| - puts "#{index}\t#{rec_copy[index]['245']}" - puts "\t#{rec_copy[index]['260']}" if rec_copy[index]['260'] - puts "\t#{rec_copy[index]['300']}" if rec_copy[index]['300'] - puts "\n\n" + print $clear_code + rec_copy.each_index do |index| + ZCC.display_menu(rec_copy, index) + puts "\n\n" end - + + + whichrec = '' if take_how_many =='one' - print "\nEnter # | s# | c#-# | l# | none : " + whichrec = ask("\n<%= color('Enter # | s# | c#-# | l# | none :', UNDERLINE) %> ", String){ |q| q.readline = true } else - print "\nEnter # | n | s# | c#-# | l# | d : " + whichrec = ask("\n<%= color('Enter # | n | s# | c#-# | l# | d :', UNDERLINE) %> ", String){ |q| q.readline = true } end - whichrec = STDIN.gets.chomp! - + #puts "whichrec #{whichrec[0,1]}" #puts whichrec.class #whichrec = whichrec.to_i unless whichrec.respond_to?(:upcase) first_bit = whichrec[0,1] puts "whichrec is an Integer" if whichrec.is_a?(Integer) see_num = whichrec[1,9].to_i if first_bit == 's' - puts rec_copy[see_num] - print "\n\nHit enter to continue." - STDIN.gets.chomp + print $clear_code + print "\a" + say("#{ZCC.zcc_marc_str_bold(rec_copy[see_num].to_s, 'record')}") + ask("<%= color('Hit ENTER to continue...', :headline) %> ") + #STDIN.gets next elsif first_bit == 'c' - puts "comparison time!" + say("<%= color('comparison:', :headline) %> ") comparison = whichrec[1,99] compare_nums = comparison.split('-') rec_copy[compare_nums[0].to_i].compare_marc(rec_copy[compare_nums[1].to_i]) - puts "\nHit enter to continue." - STDIN.gets + ask("<%= color('Hit ENTER to continue...', :headline) %> ") + #STDIN.gets next elsif first_bit == 'l' #puts rec_copy[whichrec[1,99].to_i] #gets rec_copy[whichrec[1,99].to_i].linter - puts "\nHit enter to continue." - STDIN.gets + ask("<%= color('Hit ENTER to continue...', :headline) %> ") + #STDIN.gets next elsif take_how_many == 'one' if ( whichrec == 'none' ) puts "Since you cannot decide on a good record, please refer the book to a cataloger." return "none" elsif ( first_bit =~ /[a-z]/i or whichrec == '' ) - puts "that's not a valid value. try again." + ZCC.not_valid_value next else if whichrec.to_i > (rec_copy.length - 1) puts "Your number exceeds the number of records in your retrieved set." next @@ -74,11 +147,11 @@ recs_to_return << "done" elsif ( whichrec == 'n' or whichrec == '' ) puts "recs that will be returned #{recs_to_return.length}" return recs_to_return elsif whichrec[0,1] =~ /[a-z]/i - puts "that's not a valid value. try again." + ZCC.not_valid_value next else if whichrec.to_i > (rec_copy.length - 1) puts "Your number exceeds the number of records in your retrieved set." next @@ -96,5 +169,8 @@ return recs_to_return } end end + + +