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
12 #puts rec_copy.inspect
14 #rec_copy = rec_copy.sort_by {|rec| rec['245']['a']}
20 help_n = "Next Z39.50 server/group of zservers.\n> n"
22 help_num = "View that record by typing in the index number\n> 16." # this represents the '#'
24 help_p = "Pick the record at that index position into the result set to work on and save."
26 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"
28 #help_v = "View the record. Shows the full MARC record."
30 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."
32 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 '-'"
34 help_l = "Lint the record."
36 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."
38 help_f = "Forwards through the result set"
39 help_b = "backwards through the result set"
40 help_all = "Select all the records in the result set to work on and save."
41 help_none = "Select none of the records from the final set."
43 not_implemented = "This feature is not yet implemented."
45 #take_how_many = 'multi' #'one' # 'multi'
53 rec_copy.each_index do |index|
54 ZCC.display_menu(rec_copy, index)
58 recs_length = rec_copy.length
59 index_range = (0..recs_length - 1)
65 menu.layout = :one_line
68 menu.prompt = "Enter "
69 menu.select_by = :name
72 menu.choice('#'.intern, help_num) do |command, details|
76 menu.hidden("#{x}".intern, help_num) do |cmd, details|
78 say("#{ZCC.zcc_marc_str_bold(rec_copy[cmd.to_s.to_i].marc.to_s, 'record')}")
79 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
84 if take_how_many == 'multi'
85 menu.choice(:n, help_n) do |command, details|
91 menu.choice("p#".intern, help_p) { |cmd, d| say_help(help_p) }
92 menu.hidden(:pick, help_p) { |cmd, d| say_help(help_p) }
94 menu.hidden("p#{x}") do |cmd, d|
95 num_picked = cmd[1,99]
96 recs_to_return << rec_copy[num_picked.to_i]
97 if take_how_many == 'one'
105 menu.hidden('sort', help_s) do |command, details|
113 menu.hidden(:remove, help_r) {|cmd, d| puts "this command doesn't work yet. :("}
116 menu.choice('c#-#', help_c) do |command, details|
120 for x in (0..recs_length-1)
121 for y in (0..recs_length-1)
123 comparison << 'c' + x.to_s + '-' + y.to_s
127 comparison.each do |compare|
128 menu.hidden(compare, help_c) do |cmd, details|
129 say("<%= color('comparison:', :headline) %>")
131 compare_nums = cmd.split('-')
132 compare_marc(rec_copy[compare_nums[0].to_i], rec_copy[compare_nums[1].to_i])
133 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
140 menu.choice('l#', help_l) do |cmd, d|
142 #ask("Which record do you want to lint? ")
144 menu.hidden(:lint) {|cmd, d| say(help_l)}
145 for x in (0..recs_length - 1)
146 menu.hidden("l#{x}") do |cmd, d|
147 rec_copy[cmd[1,99].to_i].marc.linter
148 ask("<%= color('Hit ENTER to continue...', :headline) %> ")
152 # done => selected as many
153 unless take_how_many == 'one'
154 menu.choice(:d, help_d) do |cmd, d|
155 say("You will not search any more z-servers!")
156 recs_to_return << "done"
157 return recs_to_return
161 # none -- only for final record taking
162 if take_how_many == 'one'
163 menu.choice(:none, help_none) do |cmd, d|
164 say("Since you cannot decide on a good record, please refer the book to a cataloger.")
170 menu.hidden(:f, help_f) {|cmd, d| say(not_implemented)}
173 menu.hidden(:b, help_b) {|cmd, d| say(not_implemented)}
175 # ALL => select all from the result set
176 menu.hidden(:all, help_all) do |cmd, d|
182 menu.choice(:quit, "Exit program.") { |cmd, d| exit}
188 def display_menu(rec_copy, index)
190 #puts rec_copy[index].class
192 field_width = $term_width - 8
193 say("<%= color(\"#{index}\", :index) %> ")
194 puts rec_copy[index].zserver.to_s
195 ['245', '260', '300'].each do |field|
196 string = rec_copy[index].marc[field].to_s
199 if string.length < field_width
200 say("\t#{ZCC.zcc_marc_str_bold(string, field)}")
202 better_string = ZCC.wrap_field(string, field_width)
204 say("\t#{ZCC.zcc_marc_str_bold(better_string, field)}")
210 #currently this goes word by word. how difficult to go field by subfield?
211 def wrap_field(s, width)
214 smaller_width = width - 7
215 s.split(/\s+/).each do |word|
216 if (line.size + word.size) >= (width - 3)
219 width = smaller_width
226 lines << line if line
227 return lines.join("\n\t\t")
231 def zcc_marc_str_bold(string, field)
233 string.gsub!("'", "\'")
234 #string.gsub!("(", "\(")
235 #string.gsub!(")", "\)")
237 string.gsub!(/(\$a\s)(.*?)(\$.)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
240 string.gsub!(/(\$c\s)([\[0-9A-Za-z\]]*)(.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
242 #string.gsub!(/(\$c)(.*)(\$\s)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
243 #string.gsub!(/(\$c)(.*)(\.|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
245 string.gsub!(/(\$a)(.*?)(\$|$)/, "\\1<%= color(\"\\2\", :field_hilite) %>\\3")
246 elsif field == 'record'
247 string.sub!(/(LEADER.{19})(.{1})/, "\\1<%= color(\"\\2\", :headline) %>") #colorizes the value of the standard (AACR2, ISBD, or none)
250 string.gsub!( /\$(.)/, "<%= color('$\\1', :marc_tag) %>" )
251 string.gsub!( /^(\d\d\d)\s/, "<%= color('\\1 ', :marc_tag) %>")
257 say("\a<%= color(\"That's not a valid value. Try again.\", :headline) %> ")
265 ask("Hit enter to continue.")
268 def sort_menu records
271 menu.layout = :menu_only
275 menu.select_by = :index_or_name
276 menu.choice(:author){|cmd, d| say("not implemented yet") }
277 menu.choice(:date){|cmd, d| say("not implemented yet")}
278 menu.choice(:subfield, "in the form of 245a"){|cmd, d| say("not implemented yet")}
279 menu.choice(:relevancy){|cmd, d| say("not implemented yet")}