Sha256: 2cb24a2a5270720918d2dfdcfd98d328434f218df46af1fe67527610312331f0

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 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.
#

require_relative 'table/cell'
require_relative 'table/row'
require_relative 'table/section'

module Proforma
  module Modeling
    # A basic table structure modeled off of an HTML table:
    # A table has three sections: header, body, footer.
    # Each section has rows.
    # Each row has cells.
    class Table
      acts_as_hashable

      attr_writer :body, :footer, :header

      def initialize(body: Section.new, footer: Section.new, header: Section.new)
        @body   = Section.make(body)
        @footer = Section.make(footer)
        @header = Section.make(header)
      end

      def body
        @body || Section.new
      end

      def footer
        @footer || Section.new
      end

      def header
        @header || Section.new
      end

      def compile(data, evaluator)
        self.class.new(
          body: body.compile(data, evaluator),
          footer: footer.compile(data, evaluator),
          header: header.compile(data, evaluator)
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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