-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummarize.rb
44 lines (40 loc) · 979 Bytes
/
summarize.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
require 'yaml'
# This script creates a summary of the status of each book so we can easily
# update the README.md file and show a list of books there.
books = Dir[File.join(File.dirname(__FILE__), 'pseudo_biblical', '*.md')].map do |file|
head = `head -20 '#{file}'`.encode( "UTF-8", "binary", :invalid => :replace, :undef => :replace)
begin
YAML::load(head).tap do |hash|
hash['file'] = file
end
rescue Exception
puts file
puts head
raise
end
end
def web_path(file)
file.sub(/^\.\//, '')
end
books.group_by do |b|
b['status']
end.sort_by do |status, books|
case status
when /(missing|incomplete)/i
'01'
when /image only/i
'02'
when /ocr only/i
'03'
else
status
end
end.each do |(status, books)|
puts "#{status}\n#{'-'*status.size}\n\n"
books.each do |book|
line = "- [#{book['short_title']}](#{web_path(book['file'])})"
line += " (#{book['year']})" if book['year']
puts line
end
puts
end