-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_book
51 lines (43 loc) · 2.13 KB
/
generate_book
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
require 'prawn'
require 'prawn/measurement_extensions'
require 'CSV'
def denil!(row) #return empty string for nil fields
row.each do |k,v|
row[k] = "" if v.nil?
end
end
Prawn::Document.generate("/Users/jdunruh/Desktop/implicit.pdf" , :page_size => [5.5.send(:in), 8.5.send(:in)]) do
orc = rc = nil
first = true
rc_table_header = [[]]
rc_table_body = []
i = 0 # counter to track row for table body
CSV.foreach("/Users/jdunruh/Desktop/resource_directory.csv", :headers => true) do |row|
rc = row["Resource Category"]
if rc != nil # have an actual category, not a "header" line for human use only
if rc != orc # have a column break
if first
first = false
else
rc_table = [[rc_table_header], rc_table_body]
table rc_table_body, :header => true, :cell_style => {:border_width => 0}
end
rc_table_header = [make_table([[row["Resource Category"]], [row["Spanish"]]], :cell_style => {:border_width => 0, :align => :right})] # Create table header for category
rc_table_body = [] # empty array body for new category
rc_table_body << rc_table_header
end
denil!(row)
# rc_table_body << make_table([[[{:content => row["Resource Name"], :colspan => 2}, {:content => row["Phone1"], :colspan => 2}],
# [{:content => row["Specialty / Comments"], :colspan => 2}, {:content => row["Phone 2"], :colspan => 2}],
# [row["Address"], row["City"], row["State"], row["Zip Code(5)"]]]]) # append next detail row
rc_table_body << [make_table([[row["Resource Name"], "", "", row["Phone 1"]],
[row["Specialty / Comments"],"","", row["Phone 2"]],
[row["Address"], row["City"], row["State"], row["Zip Code(5)"]]]) do
row(0).borders = [:left, :top, :right]
row(1).borders = [:left, :right]
row(2).borders = [:left, :bottom, :right]
end ] # append next detail row
orc = rc # save the resource category so we can see if it changes on the next row
end
end
end