105 lines
3.2 KiB
Ruby
105 lines
3.2 KiB
Ruby
require "rubygems"
|
|
require "prawn"
|
|
require "prawn/measurement_extensions"
|
|
require "util.rb"
|
|
|
|
class NSFCnP
|
|
@@box_heights = [ 8.66.in, 7.085.in, 5.52.in, 3.97.in, 2.42.in ]
|
|
@@debug = false
|
|
|
|
def initialize(me, grants)
|
|
@me = me
|
|
@grants = grants.symbolize_json
|
|
end
|
|
|
|
def render(target)
|
|
grants = @grants
|
|
pi_name = @me
|
|
Prawn::Document.generate(target,
|
|
background: "lib/NSFCP.png",
|
|
background_scale: 0.5
|
|
) do
|
|
stroke_color 'ff0000' if @@debug
|
|
grants.take_groups(@@box_heights.length)
|
|
.each.with_index do |page_records, page|
|
|
puts "Rendering Page #{page}"
|
|
start_new_page unless page == 0;
|
|
|
|
bounding_box([0.8.in, 8.85.in], width: 2.5.in, height: 0.2.in) do
|
|
text pi_name
|
|
stroke_bounds if @@debug
|
|
end
|
|
|
|
page_records.zip(@@box_heights.take(page_records.length)).
|
|
each do |record, height|
|
|
bounding_box([-0.17.in, height], width: 7.85.in, height: 1.59.in) do
|
|
stroke_bounds if @@debug
|
|
|
|
######## Support Type ########
|
|
offset =
|
|
case record.fetch(:status, record.fetch("status", :pending))
|
|
when :pending, "submitted" then 2.21.in
|
|
when :current, "accepted" then 1.16.in
|
|
when :planned, "planned" then 3.32.in
|
|
when :transfer then 6.07.in
|
|
else raise "Unknown status: #{record[:support]}"
|
|
end
|
|
# puts "Offset: #{record.fetch(:title)} -> #{offset}; #{record[:status]} -- #{record["status"]}"
|
|
### Make the checkbox ###
|
|
bounding_box([offset,1.57.in], width: 0.2.in, height: 0.2.in) do
|
|
text "X"
|
|
end
|
|
|
|
######## Title ########
|
|
bounding_box([0.1.in, 1.20.in], width: 7.6.in, height: 0.38.in) do
|
|
stroke_bounds if @@debug
|
|
text record.fetch(:title)
|
|
end
|
|
|
|
######## Agency ########
|
|
bounding_box([1.23.in, 0.8.in], width: 6.47.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text record.fetch(:agency)
|
|
end
|
|
|
|
######## Amount ########
|
|
bounding_box([1.5.in, 0.6.in], width: 1.4.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text record.fetch(:amount).to_s
|
|
end
|
|
|
|
######## Period ########
|
|
bounding_box([4.7.in, 0.6.in], width: 3.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text "#{record.fetch(:start)} -- #{record.fetch(:end)}"
|
|
end
|
|
|
|
######## Location ########
|
|
bounding_box([1.23.in, 0.4.in], width: 6.47.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text record.fetch(:location, "University at Buffalo, Buffalo, NY")
|
|
end
|
|
|
|
######## Commitment ########
|
|
commitment = record.fetch(:commitment)
|
|
bounding_box([4.4.in, 0.2.in], width: 0.6.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text commitment.fetch(:calendar, 0).to_s, align: :center
|
|
|
|
end
|
|
bounding_box([5.45.in, 0.2.in], width: 0.55.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text commitment.fetch(:schoolyear, 0).to_s, align: :center
|
|
end
|
|
bounding_box([6.4.in, 0.2.in], width: 1.in, height: 0.19.in) do
|
|
stroke_bounds if @@debug
|
|
text commitment.fetch(:summer, 0).to_s, align: :center
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|