# frozen_string_literal: true module DataTable class Column attr_reader :name attr_accessor :display, :index, :options, :css_class, :attributes def initialize(name, description = '', opts = {}, &renderer) @name = name @description = description @data_type = opts[:data_type] @help_text = opts[:help_text] @css_class = opts[:css_class] @attributes = opts[:attributes] || {} @width = opts[:width] @options = opts @display = true @index = 0 @renderer = renderer end def render_cell(cell_data, row = nil, row_index = 0, col_index = 0) @data_type ||= type(cell_data) html = [] html << if @renderer && row case @renderer.arity when 1 then @renderer.call(cell_data).to_s when 2 then @renderer.call(cell_data, row).to_s when 3 then @renderer.call(cell_data, row, row_index).to_s when 4 then @renderer.call(cell_data, row, row_index, self).to_s when 5 then @renderer.call(cell_data, row, row_index, self, col_index).to_s end else cell_data.to_s end html << '' # Doing this here b/c you can't change @css_class if this is done before the renderer is called "