Sha256: 4d2a9bbbbf38988b84229175dd7f538d73c666bc4038552a0b620c0a31bb5a45

Contents?: true

Size: 1.6 KB

Versions: 23

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

module BrInvoicesPdf
  module Util
    module ProductTable
      module_function

      PRODUCT_TABLE_BASE_DATA = [['CÓD.', 'DESCRIÇÃO', 'QTD.', 'UND.', 'V.UNIT', 'V.TOT']].freeze
      # :reek:FeatureEnvy
      def product_table_data(data)
        data[:products].reduce(PRODUCT_TABLE_BASE_DATA) do |result, cur|
          result + [[
            cur[:code],
            cur[:description],
            format_number(cur[:quantity]),
            cur[:unit_label],
            format_currency(cur[:unit_value]),
            format_currency(cur[:total_value])
          ]]
        end
      end
      private_class_method :product_table_data

      def format_table(pdf, table_data)
        width = page_content_width(pdf)
        pdf.table(table_data, width: width) do |table|
          format_row(table.row(0))
          format_columns(table)
        end
      end
      private_class_method :format_table

      def format_row(row)
        row.font_style = :bold
        row.align = :center
      end
      private_class_method :format_row

      # :reek:FeatureEnvy
      def format_columns(table)
        table.columns(0..5).valign = :center
        table.columns([2, 4, 5]).align = :right
        table.column(3).align = :center
        table_widths(table, table.width)
      end
      private_class_method :format_columns

      # :reek:FeatureEnvy
      def table_widths(table, width)
        table.column(0).width = width * 0.16
        table.columns([2, 3]).width = width * 0.155
        table.column([4, 5]).width = width * 0.135
      end
      private_class_method :table_widths
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
br_invoices_pdf-0.2.24 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.23 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.22 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.21 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.20 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.19 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.18 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.17 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.16 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.15 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.14 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.14.alpha.23 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.13 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.13.alpha.22 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.12.alpha.21 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.12.alpha.20 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.12 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.11 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.10 lib/br_invoices_pdf/util/product_table.rb
br_invoices_pdf-0.2.9 lib/br_invoices_pdf/util/product_table.rb