Class: DataBandRenderer
- Inherits:
-
Object
- Object
- DataBandRenderer
- Defined in:
- lib/data_band.rb
Instance Method Summary collapse
- #draw_row(row) ⇒ Object
-
#initialize(data, pdf, sql_conn, replacements, data_sources, y_off) ⇒ DataBandRenderer
constructor
A new instance of DataBandRenderer.
- #prepare_dataset ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(data, pdf, sql_conn, replacements, data_sources, y_off) ⇒ DataBandRenderer
Returns a new instance of DataBandRenderer.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/data_band.rb', line 4 def initialize(data, pdf, sql_conn, replacements, data_sources, y_off) @data = data @pdf = pdf @sql_conn = sql_conn @data_sources = data_sources @replacements = replacements @y_off = y_off @row_data = prepare_dataset end |
Instance Method Details
#draw_row(row) ⇒ Object
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 |
# File 'lib/data_band.rb', line 34 def draw_row(row) last_y_off = @y_off @data.xpath("Components/*[contains(.,'Text')]").each do |node| next if node.name == "Name" if node.name.start_with? "Text" x, y, w, h = Stylist.get_dimensions(node, @y_off) # Text text = node.xpath("Text").text # SQL replacements if text.include?("{") text.gsub!(/{.*}/) do |m| index = m.split(".")[1].sub("}","") text = row[index] text = Util.number_format(text) if Util.is_number?(text) text end end # Do painting @pdf.fill_color Stylist.get_text_colour(node) @pdf.text_box text, :at => [x + 1, y - 1], :height => h, :width => w, :align => Stylist.get_horizontal_align(node), :valign => Stylist.get_vertical_align(node), :size => Stylist.get_font_size(node), :font => Stylist.get_font_face(node), :style => Stylist.get_font_style(node) last_y_off = (720 + h - y) if (720 + h - y) > @y_off end end @y_off = last_y_off end |
#prepare_dataset ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/data_band.rb', line 23 def prepare_dataset data_source = @data.xpath("DataSourceName").text sql = @data_sources[data_source]["sql"] @replacements.each do |key, val| sql.sub!("{#{key}}", val) end return @sql_conn.query sql end |
#render ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/data_band.rb', line 15 def render @row_data.each do |row| draw_row(row) end return @y_off end |