-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathht.rb
75 lines (60 loc) · 2.36 KB
/
ht.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#####################################
############ HATHITRUST STUFF #######
#####################################
#
# #fill_print_holdings! calls a mock object if NO_DB or the like is set.
each_record do |_r, context|
context.clipboard[:ht][:items].fill_print_holdings! if context.clipboard[:ht][:has_items]
end
## OK, so one weird thing we need to do is have different ht_json docs for mirlyn vs hathitrust, since they have differently-formatted 974s. Pass in the :ht symbol only for HT and the to_json will do the Right Thing.
to_field 'ht_json' do |_record, acc, context|
acc << context.clipboard[:ht][:items].to_json(:ht) if context.clipboard[:ht][:has_items]
end
# callnumber from the bib, instead of the item
LC_MAYBE = /\A\s*[A-Z]+\s*\d+/.freeze
to_field 'callnumber', extract_marc('050ab:090ab') do |_rec, acc|
acc.delete_if { |x| !LC_MAYBE.match(x) }
end
to_field 'callnoletters', extract_marc('050ab:090ab', first: true) do |_rec, acc|
unless acc.empty?
m = /\A([A-Za-z]+)/.match(acc[0])
acc[0] = m[1] if m
end
end
# make use of the HathiTrust::ItemSet object stuffed into
# [:ht][:items] to pull out all the other stuff we need.
to_field 'ht_searchonly' do |_record, acc, context|
acc << !context.clipboard[:ht][:items].us_fulltext?
end
to_field 'ht_searchonly_intl' do |_record, acc, context|
acc << !context.clipboard[:ht][:items].intl_fulltext?
end
# Language 008 as string
to_field 'language008_full', marc_languages('008[35-37]') do |_record, acc|
acc.map! { |x| x.gsub(/\|/, '') }
end
# Compute the title_item_sortkey and author_item_sortkey
# Is this used anywhere????? Dead code???
each_record do |r, context|
items = context.clipboard[:ht][:items]
fields = context.output_hash
bibdate = HathiTrust::BibDate.get_bib_date(r)
items.each do |item|
item.title_sortkey = [
fields['title_sortkey'],
fields['author_sortkey'],
item.enum_pubdate, # from 974$y, which always has a value
item.enumchron_sortstring
].join(' AAA ').downcase
item.author_sortkey = [
fields['author_sortkey'],
fields['title_sortkey'],
item.enum_pubdate, # from 974$y, which always has a value
item.enumchron_sortstring
].join(' AAA ').downcase
end
end
# All the print holdings from all the items
to_field 'print_holdings' do |_record, acc, context|
acc.replace context.clipboard[:ht][:items].print_holdings
end