module BrInvoicesPdf::Util::BaseRenderer

Constants

CNPJ_FORMAT
CPF_FORMAT
PAYMENTS_TABLE_BASE_DATA

Public Instance Methods

box(pdf, position, width) { || ... } click to toggle source
# File lib/br_invoices_pdf/util/base_renderer.rb, line 8
def box(pdf, position, width)
  pdf.bounding_box(position, width: width) do
    pdf.pad(2) do
      pdf.indent(2, 2) do
        yield
      end
    end

    pdf.stroke_bounds
  end
end
execute_payment_form(pdf, date_from_table) click to toggle source
# File lib/br_invoices_pdf/util/base_renderer.rb, line 72
def execute_payment_form(pdf, date_from_table)
  pdf.font_size(6) do
    width = page_content_width(pdf)
    table_data = date_from_table
    render_table(pdf, table_data, width)
  end

  pdf.move_down(5)
end
format_cnpj(cnpj) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 85
def format_cnpj(cnpj)
  format(CNPJ_FORMAT, cnpj[0, 2].to_i, cnpj[2, 3].to_i, cnpj[5, 3].to_i,
         cnpj[8, 4].to_i, cnpj[12, 2].to_i)
end
format_cpf(cpf) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 92
def format_cpf(cpf)
  format(CPF_FORMAT, cpf[0, 3].to_i, cpf[3, 3].to_i, cpf[6, 3].to_i, cpf[9, 2].to_i)
end
format_currency(number_string) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 97
def format_currency(number_string)
  number = BigDecimal(number_string)
  format('%.2f', number.truncate(2)).tr('.', ',')
end
format_number(number_string, prec: 4) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 103
def format_number(number_string, prec: 4)
  number = BigDecimal(number_string)
  format("%.#{prec}f", number.truncate(prec)).tr('.', ',')
end
generate_qr_code_data(qr_code_string, qrcode_size) click to toggle source
# File lib/br_invoices_pdf/util/base_renderer.rb, line 65
def generate_qr_code_data(qr_code_string, qrcode_size)
  qrcode = RQRCode::QRCode.new(qr_code_string)
  blob = qrcode.as_png(size: qrcode_size.to_i, border_modules: 0).to_blob
  StringIO.new(blob)
end
insert_box(pdf, params) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 31
def insert_box(pdf, params)
  box(pdf, [params[:xpos], params[:ypos]], params[:third_width]) do
    insert_texts(pdf, params[:title], params[:value])
  end
end
insert_box_info(pdf, data, xpos = 0) click to toggle source
# File lib/br_invoices_pdf/util/base_renderer.rb, line 20
def insert_box_info(pdf, data, xpos = 0)
  third_width = page_content_width(pdf) * 0.333333333
  ypos = pdf.cursor
  box_info(data[:totals]).each do |(title, value)|
    insert_box(pdf, title: title, value: value, xpos: xpos, ypos: ypos, third_width: third_width)
    xpos += third_width
  end
end
insert_texts(pdf, title, value) click to toggle source
# File lib/br_invoices_pdf/util/base_renderer.rb, line 38
def insert_texts(pdf, title, value)
  pdf.text(title, style: :italic)
  pdf.text(value, align: :right)
end
mount_payment_data(data) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 58
def mount_payment_data(data)
  data[:payments].reduce(PAYMENTS_TABLE_BASE_DATA) do |result, cur|
    result + [[cur[:type], format_currency(cur[:amount])]]
  end
end
page_content_width(pdf) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 114
def page_content_width(pdf)
  page = pdf.page
  margins = page.margins
  page_paper_width(page.size) - margins[:left] - margins[:right]
end
page_paper_width(name) click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 109
def page_paper_width(name)
  (name.is_a?(Array) ? name : PDF::Core::PageGeometry::SIZES[name]).first
end
pdf_setup(pdf) { || ... } click to toggle source

:reek: FeatureEnvy

# File lib/br_invoices_pdf/util/base_renderer.rb, line 45
def pdf_setup(pdf)
  pdf.bounding_box([0, pdf.cursor], width: page_content_width(pdf)) do
    pdf.pad(10) do
      pdf.indent(10, 10) do
        yield
      end
    end
    pdf.stroke_bounds
  end
end