Class: Insulin::Pdf
- Inherits:
-
Object
- Object
- Insulin::Pdf
- Defined in:
- lib/insulin/pdf.rb
Instance Method Summary collapse
-
#initialize(period, outfile) ⇒ Pdf
constructor
A new instance of Pdf.
- #render ⇒ Object
Constructor Details
#initialize(period, outfile) ⇒ Pdf
Returns a new instance of Pdf.
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/insulin/pdf.rb', line 6 def initialize period, outfile @period = period @outfile = outfile @default_colour = "007700" @pdf = Prawn::Document.new @pdf.font "Courier" @pdf.font_size 12 @pdf.formatted_text [{ :text => "insulin", :styles => [ :bold ], :color => "AA0000", :size => 16 }, { :text => " report for %s beginning %s" % [ @period.descriptor, @period.start_date ] }] s = " report for %s beginning %s" % [ @period.descriptor, @period.start_date ] @pdf.text "\n" @pdf.text "\n" @pdf.font_size 8 colour = @default_colour if @period.average_glucose < 4 colour = 'FF0000' end if @period.average_glucose > 8 colour = '0000FF' end @pdf.table [ [ "latest hba1c (from %s)" % [ @period.hba1c["date"], ], "%0.1f%s" % [ @period.hba1c["value"], @period.hba1c["units"] ] ], [ "average blood glucose for %s commencing %s" % [ @period.descriptor, @period.start_date ], "<color rgb='%s'>%0.2f%s</color>" % [ colour, @period.average_glucose, @period[0].glucose_units ] ] ], :position => :center, :column_widths => [ 300, 200 ], :row_colors => [ "F0F0F0", "D0D0D0" ], :cell_style => { :border_color => "333333", :border_width => 1, :inline_format => true } @pdf.text "\n" @pdf.text "\n" @pdf.text "\n" @period.each do |d| @pdf.formatted_text [{ :text => "%s (%s)" % [ d.date, d.day ], :color => "AA0000", :size => 10 }] @pdf.text "\n" @grid = [] @pdf.font_size 8 d["all"].each do |e| colour = "000000" if e.simple? if e["type"] == "glucose" colour = @default_colour if e["value"] < 4 colour = "0000FF" end if e["value"] > 8 colour = "FF0000" end end @grid << [ e["short_time"], e["tag"], e["type"], e["subtype"], "<color rgb='%s'>%s</color>" % [ colour, e["formatted_value_with_units"] ] ] end end @pdf.table @grid, :position => :center, :column_widths => [ 100, 100, 100, 100, 100 ], :row_colors => [ "F0F0F0", "D0D0D0" ], :cell_style => { :border_color => "333333", :border_width => 1, :inline_format => true } @pdf.text "\n" @pdf.text "\n" @pdf.text "\n" end @pdf.stroke_horizontal_rule @pdf.text "\n" @pdf.text "\n" @pdf.text "\n" @pdf.formatted_text [{ :text => "insulin", :color => "007700", :link => "http://pikesley.github.com/insulin/" }, { :text => " written and maintained by Sam Pikesley" }] end |
Instance Method Details
#render ⇒ Object
163 164 165 |
# File 'lib/insulin/pdf.rb', line 163 def render @pdf.render_file @outfile end |