-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.rb
executable file
·56 lines (48 loc) · 1.75 KB
/
generate.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
#!/usr/bin/env ruby
require "csv"
require "cgi"
data_file = "vendorpol.csv"
vendor_data = Hash.new { |h, k| h[k] = {} } # A hash of hashes
CSV.foreach(data_file, headers: true, header_converters: :symbol) do |row|
vendor_data[row[:vendor]][row[:title]] = {
account: row[:account],
privacy_url: row[:privacy_url],
tc_url: row[:tc_url]
}
end
puts <<HEAD
<p>
When you use electronic resources purchased by York University Libraries and provided by third-party vendors, you are subject to the vendor's policies. This page has links to the privacy policies and terms and conditions of use (if they exist) for all of the vendors and products that the Libraries purchases. It also shows whether creating an account is required or optional to use the product.
</p>
HEAD
# Index
puts "<h2>Index</h2>"
puts "<ul>"
vendor_data.sort_by { |v| v[0] }.each do |vendor|
vendor_name = CGI.escapeHTML(vendor[0])
puts %( <li> <a href="##{vendor_name}">#{vendor_name}</a> </li>)
end
puts "</ul>"
puts "<h2>Vendors and policies</h2>"
vendor_data.sort_by { |v| v[0] }.each do |vendor|
vendor_name = CGI.escapeHTML(vendor[0])
puts %(<h3 id="#{vendor_name}">#{vendor_name}</h3>)
puts " <ul>"
vendor[1].sort_by { |p| p[0] }.each do |product|
print " <li> " + CGI.escapeHTML(product[0]) + ": "
unless product[1][:privacy_url].nil?
print %(<a href="#{product[1][:privacy_url]}">privacy</a>)
print ", " unless product[1][:tc_url].nil?
end
unless product[1][:tc_url].nil?
print %(<a href="#{product[1][:tc_url]}">t&c</a>)
end
if product[1][:account] == "optional"
print " (account optional)"
elsif product[1][:account] == "mandatory"
print " (account mandatory)"
end
puts "</li>"
end
puts " </ul>"
end