Sha256: 69a119aa1885d4a9a04cd01d44e736559b2e60a97d2225d9e8717e1837a5423d

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module  PrivatePlease::Report

  class Table

    def initialize(col_1, col_2)
      @col_1, @col_2 = col_1, col_2

      prepare_data
    end

  #----------------------------------------------------------------------------
  # QUERIES:
  #----------------------------------------------------------------------------

    attr_reader :col_1,
                :col_2,
                :rows,
                :longest_value_length

    def empty?
      col_1.empty? && col_2.empty?
    end

  #----------------------------------------------------------------------------
  # COMMANDS:
  #----------------------------------------------------------------------------

    # none (immutable)

  #----------------------------------------------------------------------------
  private

    def prepare_data
      @longest_value_length = [col_1 + col_2].flatten.map(&:length).max || 0

      # pad whichever column is shorter
      @col_1[@col_2.length-1] ||= nil  unless @col_2.empty?
      @col_2[@col_1.length-1] ||= nil  unless @col_1.empty?

      @rows = @col_1.zip(@col_2)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
private_please-0.0.5 lib/private_please/report/table.rb
private_please-0.0.4 lib/private_please/report/table.rb