<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: percentage code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 17:36:04 GMT</pubDate>
    <description>DZone Snippets: percentage code</description>
    <item>
      <title>Simple % bar in a pdf using Ruby</title>
      <link>http://snippets.dzone.com/posts/show/3648</link>
      <description>Will create a bar, filled to the percentage provided, and draw it in a PDF.&lt;br /&gt;&lt;br /&gt;Requires PDF Writer, call method after setting up PDF to @pdf&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def generate_pdf_bar(p = 50, x = 10, y = 'center', w = 200, h = 10)&lt;br /&gt;     # adjustments&lt;br /&gt;    if y == 'center'&lt;br /&gt;      y = @pdf.page_height / 2 - h&lt;br /&gt;    else&lt;br /&gt;      y = @pdf.page_height - y - h&lt;br /&gt;    end&lt;br /&gt;    p = w / 100 * p&lt;br /&gt;&lt;br /&gt;      # Empty&lt;br /&gt;    @pdf.stroke_color  Color::RGB::Black&lt;br /&gt;    @pdf.rectangle(x, y, w, h).close_stroke&lt;br /&gt;&lt;br /&gt;     # Fill&lt;br /&gt;    @pdf.fill_color    Color::RGB::Black&lt;br /&gt;    @pdf.stroke_color  Color::RGB::Black&lt;br /&gt;    @pdf.rectangle(x, y, p, h).close_fill_stroke&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Mar 2007 12:01:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3648</guid>
      <author>abscond (James Darling)</author>
    </item>
  </channel>
</rss>
