2 HighLine.track_eof = false
3 def zcc_select_good_marc(results, take_how_many)
5 unless results.is_a? ZCC::ResultSet
6 raise ArgumentError, "This Array doesn't have a MARC::Record!"
14 For help on a particular topic:
34 help_num = "View a record by typing in the index number\n> 16."
35 help_p = "Pick the record at that index position into the result set to work on and save.\n> p3"
36 help_u = "Unselect a record.\nIf you have chosen to pick a record and no longer want it,\nyou can unselect it.\n> u2"
37 help_r = "Remove the record from the result set. This is a way to narrow the result set.\n> r4\nRemoves record 4 from the result set and unclutter the screen some.\n
38 Alternately, just enter 'r' and you will have the chance to enter a range to remove."
42 Hit 's' to get a menu of sort possibilities.
43 Possible sorts include: title, date, subfield, content standard.
46 sort by content: s -> c
47 Paths to sort by subfield:
49 sort -> subfield -> 260a
50 sort -> subfield -> 260 which equals 260a
53 Sorting reindexes the result set and removes nil values.
56 help_c = "Compare two records.\nCompares the records line by line.\nLines with an 'm' match each other.\nLines with a plus sign are in the first record but not the second. Lines with a minus sign '-' are from the second record but not the first.\nEven the difference of a period matters here.\n> c [ENTER] 4-2"
57 help_l = "Lint the record.\nCheck for errors such as wrong indicator values or poor punctuation.\n> l5"
59 help_f = "Forwards through the result set.\nThe number of results shown per page is configured in zcc.yaml."
60 help_b = "backwards through the result set.\nThe number of results shown per page is configured in zcc.yaml."
61 help_n = "Next Z39.50 server/group of zservers.\nIf there are no more zservers to search, you are presented with you combined picks or a new search prompt.\n> n"
62 help_d = "Done selecting records.\nIf at least one record has been selected you continue on to final selection.\nIf no records have been selected you are presented with a search prompt again."
63 help_d = "Quit the program."
65 #the following are not implemented
66 help_all = "Select all the records in the result set to work on and save."
67 help_none = "Select none of the records from the final set."
69 not_implemented = "This feature is not yet implemented."
71 #take_how_many = 'multi' #'one' # 'multi'
76 rec_copy = results.records
80 menu.layout = :one_line
83 menu.prompt = "Enter "
84 menu.select_by = :name
86 menu.help("help", help_help)
88 rec_copy.each_index do |index|
89 showings = results.index_start + results.index_pos
91 if index >= results.index_start && index <= showings
92 ZCC.display_menu(rec_copy, index)
96 puts "Highest position: " + (results.size - 1).to_s
97 say("\aYou are currently in the winnowing stage.\nEnter 'done' if you want to process all selected records.\nIf you 'unselect' all records you will return to search. \n".bold) if take_how_many == 'winnow'
99 recs_length = rec_copy.length
100 index_range = (0..recs_length - 1)
102 menu.hidden("help", help_help) do |cmd, d|
131 menu.choice('#'.intern, help_num) do |command, details|
135 menu.hidden("#{x}".intern, help_num) do |cmd, details|
136 if rec_copy[cmd.to_s.to_i] == nil
137 say("You removed that record!")
140 say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].to_s, 'record')}")
142 ask("Hit ENTER to continue...".headlinez)
147 menu.choice("p#".intern, help_p) { |cmd, d| say_help(help_p) }
148 menu.hidden(:p, help_p){|cmd, d| say_help(help_p)}
149 menu.hidden(:pick, help_p) { |cmd, d| say_help(help_p) }
151 menu.hidden("p#{x}") do |cmd, d|
152 num_picked = cmd[1,99]
153 rec_copy[num_picked.to_i].selected = true if rec_copy[num_picked.to_i] != nil
154 if take_how_many == 'one'
161 menu.choice("u#".intern, help_u) { |cmd, d| say_help(help_u) }
162 menu.hidden(:u, help_u) { |cmd, d| say_help(help_u) }
163 menu.hidden(:unselect, help_u) { |cmd, d| say_help(help_u) }
165 menu.hidden("u#{x}", help_u) do |cmd, d|
166 num_picked = cmd[1,99]
167 if rec_copy[num_picked.to_i] != nil
168 rec_copy[num_picked.to_i].selected = false
175 #menu.hidden("r#".intern, help_r) { |cmd, d| say_help(help_r) }
176 menu.hidden(:remove, help_r) { |cmd, d| say_help(help_r) }
177 menu.choice(:r, help_r) do |cmd, d|
179 range = ask("Enter range to remove like '2-5' remove records 2, 3, 4 and 5.".boldz)
180 range_a = range.split('-').collect{|i| i.to_i}
182 for r in range_a[0]..range_a[1]
183 rec_copy[r] = nil if rec_copy[r]
186 rec_copy[range_a[0]] = nil
189 menu.hidden(:remove, help_r) { |cmd, d| say_help(help_r) }
192 menu.hidden("r#{x}", help_r) do |cmd, d|
193 num_picked = cmd[1,99]
194 rec_copy[num_picked.to_i] = nil
200 menu.hidden(:sort, help_s){|cmd, d| say(help_s)}
201 menu.choice(:s, help_s) do |command, details|
203 choose do |sort_menu|
205 sort_menu.layout = :one_line
206 sort_menu.readline = true
207 sort_menu.shell = true
208 sort_menu.prompt = "Enter "
209 sort_menu.select_by = :name
211 sort_menu.choice(:title, help_s){|cmd, d| results.sort_by_title!}
212 sort_menu.choice(:date, help_s){|cmd, d| results.sort_by_date!}
213 sort_menu.choice(:content, help_s){|cmd, d| results.sort_by_standard!}
214 sort_menu.choice(:subfield, help_s){|cmd, d|
217 field_subfield = ask("Enter field and subfield like so: 245c > ")
218 results.sort_by_subfield!(field_subfield)
220 results.sort_by_subfield!(d)
228 menu.hidden(:compare, help_c){|c,d| say_help(help_c)}
229 menu.choice(:c, help_c) do |c,d|
231 comparitors = ask("Enter the two to compare. 1-2 compares record 1 to record 2.".boldz)
232 compare_nums = comparitors.split('-').collect{|i| i.to_i}
233 if rec_copy[compare_nums[0].to_i] == nil || rec_copy[compare_nums[1].to_i] == nil
234 say_help("One of the records has been removed!")
236 say("comparison:".headline)
237 compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i])
238 ask("Hit ENTER to continue...".headlinez)
242 #this always gave an Ambiguous choice error in many cases for instance c1-2 would throw the Highline error. Would like to get this to work as originally intended.
243 #menu.choice('c#-#', help_c) do |command, details|
247 # for x in (0..recs_length-1)
248 # for y in (0..recs_length-1)
250 # comparison << 'c' + x.to_s + '-' + y.to_s
254 # comparison.each do |compare|
255 # menu.hidden(compare, help_c) do |cmd, details|
257 # compare_nums = cmd.split('-')
258 # if rec_copy[compare_nums[0].to_i] == nil || rec_copy[compare_nums[1].to_i] == nil
259 # say_help("One of the records has been removed!")
261 # say("comparison:".headline)
262 # compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i])
263 # ask("Hit ENTER to continue...".headlinez)
270 menu.hidden(:l, help_l){|c,d| say_help(help_l)}
271 menu.choice('l#', help_l) do |cmd, d|
273 #ask("Which record do you want to lint? ")
275 menu.hidden(:lint) {|cmd, d| say(help_l)}
276 for x in (0..recs_length - 1)
277 menu.hidden("l#{x}") do |cmd, d|
278 if rec_copy[cmd[1,99].to_i] != nil
279 rec_copy[cmd[1,99].to_i].linter
280 ask("Hit ENTER to continue...".headlinez)
286 menu.choice(:f, help_f) do |cmd, d|
287 unless results.index_start + results.index_pos + 1 >= results.size
288 results.index_start += results.index_pos + 1
295 menu.choice(:b, help_b) do |cmd, d|
296 unless results.index_start == 0
297 results.index_start -= (results.index_pos + 1)
304 if take_how_many == 'multi'
305 menu.choice(:n, help_n) do |command, details|
310 # done => selected as many
311 unless take_how_many == 'one'
312 menu.choice(:d, help_d) do |cmd, d|
318 menu.choice(:quit, "Exit program.") { |cmd, d| exit}
320 # none -- only for final record taking. not currently used
321 if take_how_many == 'one'
322 menu.choice(:none, help_none) do |cmd, d|
323 say("Since you cannot decide on a good record, please refer the book to a cataloger.".headline)
332 def display_menu(rec_copy, index)
333 field_width = $term_width - 8
334 if rec_copy[index].nil?
335 say(index.to_s + " Removed from set.")
337 if rec_copy[index].selected
338 say(index.to_s.headlinez)
340 say(index.to_s.red.boldz)
344 if rec_copy[index].rank >= 10
346 elsif rec_copy[index].rank >= 5
351 say("\t\t" + rec_copy[index].zserver.to_s)
352 #['245', '260', '300'].each do |field|
353 FIELDS_TO_SHOW.each do |field|
355 string = rec_copy[index].marc[field].to_s
359 if string.length < field_width
360 say("\t" + ZCC.zcc_marc_str_bold(string, field))
362 better_string = ZCC.wrap_field(string, field_width)
363 say("\t" + ZCC.zcc_marc_str_bold(better_string, field))
366 #The dp here stands for display problem.
367 puts " dp\t#{rec_copy[index].marc[field].to_s}"
375 #currently this goes word by word. how difficult to go field by subfield?
376 def wrap_field(s, width)
379 smaller_width = width - 7
380 s.split(/\s+/).each do |word|
381 if (line.size + word.size) >= (width - 3)
384 width = smaller_width
391 lines << line if line
392 return lines.join("\n\t\t")
396 def zcc_marc_str_bold(string, field)
398 #string.gsub!("'", "\'")
399 #unless field == 'record'
400 # string.gsub!('"', '\"')
402 #string.gsub!("(", "\(")
403 #string.gsub!(")", "\)")
405 string.gsub!(/(\$a\s)(.*?)(\$.|$)/, "\\1" + "\\2".blue + "\\3")
408 string.gsub!(/(\$c\s)([\[0-9A-Za-z\]]*)(.|$)/, "\\1" + "\\2".blue + "\\3")
409 #string.gsub!(/(\$c)(.*)(\$\s)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
410 #string.gsub!(/(\$c)(.*)(\.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
412 string.gsub!(/(\$a)(.*?)(\$|$)/, "\\1" + "\\2".blue + "\\3")
413 elsif field == 'record'
414 string.sub!(/(LEADER.{19})(.{1})/, "\\1" + "\\2".bold.blue) #colorizes the value of the standard (AACR2, ISBD, or none)
415 string.sub!(/(LEADER.{10})(.{1})/, "\\1" + "\\2".bold.blue) #colorizes the
417 string.gsub!( /(\$.)/, "\\1".bold )
418 string.gsub!( /^(\d\d\d)\s/, "\\1 ".bold)
424 say("\aThat's not a valid value. Try again.".headline)
432 ask("Hit enter to continue.".boldz)
436 def sort_menu records
439 menu.layout = :menu_only
443 menu.select_by = :index_or_name
444 menu.choice(:author){|cmd, d| say("not implemented yet") }
445 menu.choice(:date){|cmd, d| say("not implemented yet")}
446 menu.choice(:subfield, "in the form of 245a"){|cmd, d| say("not implemented yet")}
447 menu.choice(:relevancy){|cmd, d| say("not implemented yet")}
458 # Override HighLine's own defaults so that our large menu options do not display.
459 # This needs work to have better help for these error messages.
463 def update_responses( )
464 append_default unless default.nil?
466 :ambiguous_completion => "Ambiguous choice. ",
467 :ask_on_error => "? ",
468 :invalid_type => "You must enter a valid option.", :no_completion => "You must pick a valid option.", :not_in_range => "You must input a valid option." ,
469 :not_valid => "You must have a valid option."