3 def zcc_select_good_marc(results, take_how_many)
5 #unless taken[0].is_a? MARC::Record
6 # raise ArgumentError, "This Array doesn't have a MARC::Record!"
10 rec_copy = results.records
11 if results.records.empty?
12 puts "Your search returned no records!"
16 #puts rec_copy.inspect
18 #rec_copy = rec_copy.sort_by {|rec| rec['245']['a']}
24 help_n = "Next Z39.50 server/group of zservers.\n> n"
26 help_num = "View that record by typing in the index number\n> 16." # this represents the '#'
28 help_p = "Pick the record at that index position into the result set to work on and save."
30 help_s = "Select sort. Hit 's' to get a menu of sort possibilities. Possible sorts will include: relevancy, title, author, date, date_fixed, subfield (in form of 245a)...\n> s5"
32 #help_v = "View the record. Shows the full MARC record."
34 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."
36 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 '-'"
38 help_l = "Lint the record."
40 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."
42 help_f = "Forwards through the result set"
43 help_b = "backwards through the result set"
44 help_all = "Select all the records in the result set to work on and save."
45 help_none = "Select none of the records from the final set."
46 help_u = "Unselect a record from the result set."
47 not_implemented = "This feature is not yet implemented."
49 #take_how_many = 'multi' #'one' # 'multi'
57 rec_copy.each_index do |index|
58 ZCC.display_menu(rec_copy, index)
62 recs_length = rec_copy.length
63 index_range = (0..recs_length - 1)
69 menu.layout = :one_line
72 menu.prompt = "Enter "
73 menu.select_by = :name
76 menu.choice('#'.intern, help_num) do |command, details|
80 menu.hidden("#{x}".intern, help_num) do |cmd, details|
82 say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].marc.to_s, 'record')}")
83 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
88 if take_how_many == 'multi'
89 menu.choice(:n, help_n) do |command, details|
95 menu.choice("p#".intern, help_p) { |cmd, d| say_help(help_p) }
96 menu.hidden(:pick, help_p) { |cmd, d| say_help(help_p) }
98 menu.hidden("p#{x}") do |cmd, d|
99 num_picked = cmd[1,99]
100 rec_copy[num_picked.to_i].selected = true
101 if take_how_many == 'one'
109 menu.hidden(:remove, help_r) {|cmd, d| puts "this command doesn't work yet. :("}
112 menu.choice("u#".intern, help_u) { |cmd, d| say_help(help_u) }
113 menu.hidden(:unselect, help_u) { |cmd, d| say_help(help_u) }
115 menu.hidden("u#{x}", help_u) do |cmd, d|
116 num_picked = cmd[1,99]
117 rec_copy[num_picked.to_i].selected = false
123 menu.hidden('sort', help_s) do |command, details|
133 menu.choice('c#-#', help_c) do |command, details|
137 for x in (0..recs_length-1)
138 for y in (0..recs_length-1)
140 comparison << 'c' + x.to_s + '-' + y.to_s
144 comparison.each do |compare|
145 menu.hidden(compare, help_c) do |cmd, details|
146 say("<%= color('comparison:', :headline) %>")
148 compare_nums = cmd.split('-')
149 compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i])
150 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
157 menu.choice('l#', help_l) do |cmd, d|
159 #ask("Which record do you want to lint? ")
161 menu.hidden(:lint) {|cmd, d| say(help_l)}
162 for x in (0..recs_length - 1)
163 menu.hidden("l#{x}") do |cmd, d|
164 rec_copy[cmd[1,99].to_i].linter
165 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
169 # done => selected as many
170 unless take_how_many == 'one'
171 menu.choice(:d, help_d) do |cmd, d|
172 say("You will not search any more z-servers!")
173 #recs_to_return << "done"
178 # none -- only for final record taking
179 if take_how_many == 'one'
180 menu.choice(:none, help_none) do |cmd, d|
181 say("Since you cannot decide on a good record, please refer the book to a cataloger.")
187 menu.hidden(:f, help_f) {|cmd, d| say(not_implemented)}
190 menu.hidden(:b, help_b) {|cmd, d| say(not_implemented)}
192 # ALL => select all from the result set
193 menu.hidden(:all, help_all) do |cmd, d|
199 menu.choice(:quit, "Exit program.") { |cmd, d| exit}
205 def display_menu(rec_copy, index)
207 #puts rec_copy[index].class
209 field_width = $term_width - 8
210 say("<%= color(\"#{index}\", :index) %> ")
211 puts rec_copy[index].zserver.to_s
212 ['245', '260', '300'].each do |field|
213 #puts rec_copy[index].marc.to_s
214 string = rec_copy[index].marc[field].to_s
219 if string.length < field_width
220 say("\t#{ZCC.zcc_marc_str_bold(string, field)}")
222 better_string = ZCC.wrap_field(string, field_width)
224 say("\t#{ZCC.zcc_marc_str_bold(better_string, field)}")
227 puts "Skipping record ##{index}"
233 #currently this goes word by word. how difficult to go field by subfield?
234 def wrap_field(s, width)
237 smaller_width = width - 7
238 s.split(/\s+/).each do |word|
239 if (line.size + word.size) >= (width - 3)
242 width = smaller_width
249 lines << line if line
250 return lines.join("\n\t\t")
254 def zcc_marc_str_bold(string, field)
256 string.gsub!("'", "\'")
257 unless field == 'record'
258 string.gsub!('"', '\"')
260 #string.gsub!("(", "\(")
261 #string.gsub!(")", "\)")
263 string.gsub!(/(\$a\s)(.*?)(\$.)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
266 string.gsub!(/(\$c\s)([\[0-9A-Za-z\]]*)(.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
268 #string.gsub!(/(\$c)(.*)(\$\s)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
269 #string.gsub!(/(\$c)(.*)(\.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
271 string.gsub!(/(\$a)(.*?)(\$|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
272 elsif field == 'record'
273 string.sub!(/(LEADER.{19})(.{1})/, "\\1<%= color(\"\\2\", :headline) %>") #colorizes the value of the standard (AACR2, ISBD, or none)
276 string.gsub!( /\$(.)/, "<%= color('$\\1', :marc_tag) %>" )
277 string.gsub!( /^(\d\d\d)\s/, "<%= color('\\1 ', :marc_tag) %>")
283 say("\a<%= color(\"That's not a valid value. Try again.\", :headline) %> ")
291 ask("Hit enter to continue.")
294 def sort_menu records
297 menu.layout = :menu_only
301 menu.select_by = :index_or_name
302 menu.choice(:author){|cmd, d| say("not implemented yet") }
303 menu.choice(:date){|cmd, d| say("not implemented yet")}
304 menu.choice(:subfield, "in the form of 245a"){|cmd, d| say("not implemented yet")}
305 menu.choice(:relevancy){|cmd, d| say("not implemented yet")}