Sha256: 4620cd767bb63de62e356496dbe1de86f88f10eb1fc6f428b6a5802b1833cee5

Contents?: true

Size: 668 Bytes

Versions: 4

Compression:

Stored size: 668 Bytes

Contents

# frozen_string_literal: true

module Phlexi
  module Table
    module Components
      module Options
        module Labels
          def label(label = nil)
            if label.nil?
              options[:label] = options.fetch(:label) { calculate_label }
            else
              options[:label] = label
              self
            end
          end

          private

          def calculate_label
            if sample.class.respond_to?(:human_attribute_name)
              sample.class.human_attribute_name(key.to_s, {base: sample})
            else
              key.to_s.humanize
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phlexi-table-0.0.5 lib/phlexi/table/components/options/labels.rb
phlexi-table-0.0.4 lib/phlexi/table/components/options/labels.rb
phlexi-table-0.0.3 lib/phlexi/table/components/options/labels.rb
phlexi-table-0.0.2 lib/phlexi/table/components/options/labels.rb