Sha256: 04f07cd1047e6be7a77ee233c4bf20439b1e03d2bb192fc61c4e1addc92ae672

Contents?: true

Size: 1.01 KB

Versions: 5

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)
        node if subpath.empty?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.24.0 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.23.4 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.23.3 app/helpers/eac_rails_utils/data_table_helper/column.rb
eac_rails_utils-0.23.2 app/helpers/eac_rails_utils/data_table_helper/column.rb