Sha256: 6443c386f03d26bd4a469d57d7260ece377ad4c883b6605e9dead8226160a50f

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

#
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Proforma
  module Modeling
    class DataTable
      # An explicit table column that understands how to compile header, body, and footer cells
      # from records.
      class Column
        include Modeling::Types::Align
        include Compiling::Compilable
        acts_as_hashable

        attr_writer :align,
                    :body,
                    :footer,
                    :header,
                    :width

        def initialize(
          align: LEFT,
          body: '',
          footer: '',
          header: '',
          width: nil
        )
          @align  = align
          @body   = body
          @footer = footer
          @header = header
          @width  = width
        end

        def align
          @align || LEFT
        end

        def body
          @body.to_s
        end

        def footer
          @footer.to_s
        end

        def header
          @header.to_s
        end

        def width
          @width ? @width.to_f : nil
        end

        def compile_header_cell(record, evaluator)
          Modeling::Table::Cell.new(
            align: align,
            text: evaluator.text(record, header),
            width: width
          )
        end

        def compile_body_cell(record, evaluator)
          Modeling::Table::Cell.new(
            align: align,
            text: evaluator.text(record, body),
            width: width
          )
        end

        def compile_footer_cell(record, evaluator)
          Modeling::Table::Cell.new(
            align: align,
            text: evaluator.text(record, footer),
            width: width
          )
        end

        def footer?
          !footer.to_s.empty?
        end

        def header?
          !header.to_s.empty?
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
proforma-1.0.2 lib/proforma/modeling/data_table/column.rb
proforma-1.0.1 lib/proforma/modeling/data_table/column.rb
proforma-1.0.0 lib/proforma/modeling/data_table/column.rb
proforma-1.0.0.pre.alpha lib/proforma/modeling/data_table/column.rb