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!"
16 help_help = "help_help"
18 help_n = "#".bold + "Next Z39.50 server/group of zservers.\n> n"
20 help_num = "View that record by typing in the index number\n> 16." # this represents the '#'
22 help_p = "Pick the record at that index position into the result set to work on and save."
26 Hit 's' to get a menu of sort possibilities.
27 Possible sorts include: title, date, subfield, content standard.
30 sort by content: s -> c
31 Paths to sort by subfield:
33 sort -> subfield -> 260a
34 sort -> subfield -> 260 which equals 260a
37 Sorting reindexes the result set and removes nil values.
40 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.\n
41 Alternately, just enter 'r' and you will have the chance to enter a range to remove."
43 help_c = "Compare two records. Compares the records line by line. Lines with an 'm' match each other. Lines with a plus sign are in the first record but not the second. Lines with a minus sign '-'"
45 help_l = "Lint the record."
47 help_d = "Done selecting records. If at least one record has been selected you continue on. If no records have been selected you are presented with a search prompt again."
49 help_f = "Forwards through the result set"
50 help_b = "backwards through the result set"
51 help_all = "Select all the records in the result set to work on and save."
52 help_none = "Select none of the records from the final set."
53 help_u = "Unselect a record from the result set."
54 not_implemented = "This feature is not yet implemented."
56 #take_how_many = 'multi' #'one' # 'multi'
61 rec_copy = results.records
65 menu.layout = :one_line
68 menu.prompt = "Enter "
69 menu.select_by = :name
71 menu.help("help", help_help)
73 rec_copy.each_index do |index|
74 ZCC.display_menu(rec_copy, index)
78 recs_length = rec_copy.length
79 index_range = (0..recs_length - 1)
81 menu.hidden("help", help_help) do |cmd, d|
85 say_help("not completed: #{d}")
90 menu.choice('#'.intern, help_num) do |command, details|
94 menu.hidden("#{x}".intern, help_num) do |cmd, details|
96 say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].to_s, 'record')}")
97 ask("Hit ENTER to continue...".headlinez)
103 if take_how_many == 'multi'
104 menu.choice(:n, help_n) do |command, details|
110 menu.choice("p#".intern, help_p) { |cmd, d| say_help(help_p) }
111 menu.hidden(:pick, help_p) { |cmd, d| say_help(help_p) }
113 menu.hidden("p#{x}") do |cmd, d|
114 num_picked = cmd[1,99]
115 rec_copy[num_picked.to_i].selected = true
116 if take_how_many == 'one'
125 #menu.hidden("r#".intern, help_r) { |cmd, d| say_help(help_r) }
126 menu.hidden(:remove, help_r) { |cmd, d| say_help(help_r) }
127 menu.choice(:r, help_r) do |cmd, d|
129 range = ask("Enter range to remove like '2-5' remove records 2, 3, 4 and 5.".boldz)
130 range_a = range.split('-').collect{|i| i.to_i}
132 for r in range_a[0]..range_a[1]
136 rec_copy[range_a[0]] = nil
139 menu.hidden(:remove, help_r) { |cmd, d| say_help(help_r) }
142 menu.hidden("r#{x}", help_r) do |cmd, d|
143 num_picked = cmd[1,99]
144 rec_copy[num_picked.to_i] = nil
152 menu.choice("u#".intern, help_u) { |cmd, d| say_help(help_u) }
153 menu.hidden(:unselect, help_u) { |cmd, d| say_help(help_u) }
155 menu.hidden("u#{x}", help_u) do |cmd, d|
156 num_picked = cmd[1,99]
157 rec_copy[num_picked.to_i].selected = false
163 menu.hidden(:sort, help_s){|cmd, d| say(help_s)}
164 menu.choice(:s, help_s) do |command, details|
166 choose do |sort_menu|
168 sort_menu.layout = :one_line
169 sort_menu.readline = true
170 sort_menu.shell = true
171 sort_menu.prompt = "Enter "
172 sort_menu.select_by = :name
174 sort_menu.choice(:title, help_s){|cmd, d| results.sort_by_title!}
175 sort_menu.choice(:date, help_s){|cmd, d| results.sort_by_date!}
176 sort_menu.choice(:content, help_s){|cmd, d| results.sort_by_standard!}
177 sort_menu.choice(:subfield, help_s){|cmd, d|
180 field_subfield = ask("Enter field and subfield like so: 245c > ")
181 results.sort_by_subfield!(field_subfield)
183 results.sort_by_subfield!(d)
194 menu.choice('c#-#', help_c) do |command, details|
198 for x in (0..recs_length-1)
199 for y in (0..recs_length-1)
201 comparison << 'c' + x.to_s + '-' + y.to_s
205 comparison.each do |compare|
206 menu.hidden(compare, help_c) do |cmd, details|
207 say("comparison:".headline)
209 compare_nums = cmd.split('-')
210 compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i])
211 ask("Hit ENTER to continue...".headlinez)
218 menu.choice('l#', help_l) do |cmd, d|
220 #ask("Which record do you want to lint? ")
222 menu.hidden(:lint) {|cmd, d| say(help_l)}
223 for x in (0..recs_length - 1)
224 menu.hidden("l#{x}") do |cmd, d|
225 rec_copy[cmd[1,99].to_i].linter
226 ask("Hit ENTER to continue...".headlinez)
231 # done => selected as many
232 unless take_how_many == 'one'
233 menu.choice(:d, help_d) do |cmd, d|
234 #say("You will not search any more z-servers!".headline)
235 #recs_to_return << "done"
240 # none -- only for final record taking
241 if take_how_many == 'one'
242 menu.choice(:none, help_none) do |cmd, d|
243 say("Since you cannot decide on a good record, please refer the book to a cataloger.".headline)
249 menu.hidden(:f, help_f) {|cmd, d| say(not_implemented)}
252 menu.hidden(:b, help_b) {|cmd, d| say(not_implemented)}
255 menu.choice(:quit, "Exit program.") { |cmd, d| exit}
261 def display_menu(rec_copy, index)
262 field_width = $term_width - 8
263 if rec_copy[index].nil?
264 #say("<%= color(\"#{index}\") %> ")
265 #say("\tYou deleted this record from the set!")
267 if rec_copy[index].selected
268 say(index.to_s.headlinez)
270 say(index.to_s.red.boldz)
273 say("\t\t" + rec_copy[index].zserver.to_s)
274 ['245', '260', '300'].each do |field|
275 string = rec_copy[index].marc[field].to_s
279 if string.length < field_width
280 say("\t" + ZCC.zcc_marc_str_bold(string, field))
282 better_string = ZCC.wrap_field(string, field_width)
284 say("\t" + ZCC.zcc_marc_str_bold(better_string, field))
287 #The dp here stands for display problem.
288 puts " dp\t#{rec_copy[index].marc[field].to_s}"
296 #currently this goes word by word. how difficult to go field by subfield?
297 def wrap_field(s, width)
300 smaller_width = width - 7
301 s.split(/\s+/).each do |word|
302 if (line.size + word.size) >= (width - 3)
305 width = smaller_width
312 lines << line if line
313 return lines.join("\n\t\t")
317 def zcc_marc_str_bold(string, field)
319 #string.gsub!("'", "\'")
320 #unless field == 'record'
321 # string.gsub!('"', '\"')
323 #string.gsub!("(", "\(")
324 #string.gsub!(")", "\)")
326 string.gsub!(/(\$a\s)(.*?)(\$.|$)/, "\\1" + "\\2".blue + "\\3")
329 string.gsub!(/(\$c\s)([\[0-9A-Za-z\]]*)(.|$)/, "\\1" + "\\2".blue + "\\3")
330 #string.gsub!(/(\$c)(.*)(\$\s)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
331 #string.gsub!(/(\$c)(.*)(\.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
333 string.gsub!(/(\$a)(.*?)(\$|$)/, "\\1" + "\\2".blue + "\\3")
334 elsif field == 'record'
335 string.sub!(/(LEADER.{19})(.{1})/, "\\1" + "\\2".bold.blue) #colorizes the value of the standard (AACR2, ISBD, or none)
336 string.sub!(/(LEADER.{10})(.{1})/, "\\1" + "\\2".bold.blue) #colorizes the
338 string.gsub!( /(\$.)/, "\\1".bold )
339 string.gsub!( /^(\d\d\d)\s/, "\\1 ".bold)
345 say("\aThat's not a valid value. Try again.".headline)
353 ask("Hit enter to continue.".boldz)
357 def sort_menu records
360 menu.layout = :menu_only
364 menu.select_by = :index_or_name
365 menu.choice(:author){|cmd, d| say("not implemented yet") }
366 menu.choice(:date){|cmd, d| say("not implemented yet")}
367 menu.choice(:subfield, "in the form of 245a"){|cmd, d| say("not implemented yet")}
368 menu.choice(:relevancy){|cmd, d| say("not implemented yet")}
379 # Override HighLine's own defaults so that our large menu options do not display.
380 # This needs work to have better help for these error messages.
384 def update_responses( )
385 append_default unless default.nil?
386 @responses = { :ambiguous_completion => "Ambiguous choice. ", :ask_on_error => "? ", :invalid_type => "You must enter a valid option.", :no_completion => "You must choose a valid option.", :not_in_range => "Your answer isn't within the expected range " , :not_valid => "Your answer isn't valid." }.merge(@responses)