<commit_before>module Cucumber
  module Salad
    class Table
      extend Forwardable

      include Enumerable
      include Conversions

      module Transformations
        def self.pass
          ->(val) { val }
        end
      end

      class Mapping
        def initialize(settings = {})
          self.key               = settings[:key]
          self.value_transformer = transformer(settings[:value_transformer], :pass)
        end

        def set(instance, row, key, value)
          row[transform_key(instance, key)] = transform_value(instance, value)
        end

        private

        attr_accessor :key, :value_transformer

        def transform_key(_, key)
          (self.key || key.squeeze(' ').strip.gsub(' ', '_')).to_sym
        end

        def transform_value(instance, value)
          instance.instance_exec(value, &value_transformer)
        end

        def transformer(set, fallback)
          set || Transformations.send(fallback)
        end
      end

      class << self
        def map(name, options = {}, &block)<commit_msg>Extract keyword transformation.<commit_after>module Cucumber
  module Salad
    class Table
      extend Forwardable

      include Enumerable
      include Conversions

      module Transformations
        def self.keyword
          ->(val) { val.squeeze(' ').strip.gsub(' ', '_').to_sym }
        end

        def self.pass
          ->(val) { val }
        end
      end

      class Mapping
        def initialize(settings = {})
          self.key               = settings[:key]
          self.value_transformer = transformer(settings[:value_transformer], :pass)
        end

        def set(instance, row, key, value)
          row[transform_key(instance, key)] = transform_value(instance, value)
        end

        private

        attr_accessor :key, :value_transformer

        def transform_key(_, key)
          (self.key || Transformations.keyword.(key))
        end

        def transform_value(instance, value)
          instance.instance_exec(value, &value_transformer)
        end

        def transformer(set, fallback)
          set || Transformations.send(fallback)
        end
      end

      class << self
        def map(name, options = {}, &block)
{'fraction_non_alphanumeric': 0.09033989266547406, 'fraction_numerical': 0.0, 'mean_word_length': 1.9203655352480418, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92689', 'n_tokens_mistral': 619, 'n_tokens_neox': 585, 'n_words': 148}