Sha256: 9b0ef6b524f9c6ddc36b36ef5dd2b099ac726508bbb9425e67130c0bf45820c1

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacRailsUtils
  module DataTableHelper
    class Column
      EMPTY_VALUE = '-'

      common_constructor :args, :block

      # @return [String]
      def label
        args[0]
      end

      # @return [String]
      def path
        args[1].to_s.split('.')
      end

      def record_value(record)
        v = ::EacRailsUtils::DataTableHelper::ColumnNode.new(record, path).value
        if v.present?
          block ? block.call(v) : v
        else
          EMPTY_VALUE
        end
      end

      # @param attribute [Symbol]
      # @param value [Proc, Object]
      # @return [self]
      def value_cell(attribute, value = nil, &block)
        value_cell_attributes[attribute.to_sym] = block.if_present(value)

        self
      end

      # @return [Hash]
      def value_cell_attributes
        @value_cell_attributes ||= {}
      end

      private

      def node_value(node, subpath)
        return node if subpath.empty?
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
eac_rails_utils-0.23.1 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.23.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.22.3 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.22.2 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.22.1 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.22.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.21.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.20.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.19.0 app/helpers/eac_rails_utils/data_table_helper/column.rb