Sha256: bb9643a0f1e4171db235e20e8e3d6066b1e9cacaa5a555c68ad936cceb270e18

Contents?: true

Size: 1022 Bytes

Versions: 9

Compression:

Stored size: 1022 Bytes

Contents

module Rubyxls
  module Builders
    class CellBuilder

      attr_reader :cells

      def initialize(**opts)
        @model_data_rows = opts.fetch(:model_data_rows)
        @start_row = opts.fetch(:start_row, 1)
        @start_column = opts.fetch(:start_column, "A")
        @cells = []
        build_cells!
      end

      private

      def build_cells!
        assign_row_column!
        @cells = @model_data_rows.flatten
      end

      def assign_row_column!
        @model_data_rows.each_with_index do |data_row, table_row_index|
          data_row.each_with_index do |data_cell, table_column_index|
            data_cell[:row] = @start_row + table_row_index
            data_cell[:column] = retrieve_cell_column_letter(@start_column, table_column_index)
          end
        end
      end

      def retrieve_cell_column_letter(start_column, table_column_index)
         cell_column = start_column.clone
         table_column_index.times { cell_column.next! }
         cell_column
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubyxls-1.2.1 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.2.0 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.1.0 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.5 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.4 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.3 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.2 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.1 lib/rubyxls/builders/cell_builder.rb
rubyxls-1.0.0 lib/rubyxls/builders/cell_builder.rb