<commit_before>require "dotenv"

module GhDiff
  class Option
    def initialize(opts)
      @opts = opts
    end

    def dotenv
      @dotenv ||= begin
        Dotenv.load.inject({}) do |h, (k, v)|
          h[k.downcase] = v; h
        end
      end
    end

    # returns: ENV variables prefixed with 'GH_'(default)
    #          and variables defined in dotenv file.
    def env(prefix='GH_')
      envs =
        ENV.select { |env| env.start_with? prefix }
           .inject({}) do |h, (k, v)|
             h[k.sub(/^#{prefix}/, '').downcase] = v; h
           end
      envs.merge(dotenv)
    end

    def update_options_with_dotenv(options)
      @@dotenv ||= Dotenv.load
      envs = ENV.select { |env| env.start_with?('GH_') }
                .inject({}) { |h, (k, v)| h[k.sub(/^GH_/, '')] = v; h }
      envs.update(@@dotenv)
      envs.select! { |env| ENV_KEYS.include? env }
      envs.each do |key, val|
        env = key.downcase
        options.update(env => val) unless options[env]
      end
      options
    end
    
  end
end<commit_msg>implement #with_env<commit_after>require "dotenv"

module GhDiff
  class Option
    def initialize(opts)
      @opts = opts.inject({}) do |h, (k, v)|
        h[k.to_s] = v; h
      end
    end

    def dotenv
      @dotenv ||= begin
        Dotenv.load.inject({}) do |h, (k, v)|
          h[k.downcase] = v; h
        end
      end
    end

    # returns: ENV variables prefixed with 'GH_'(default)
    #          and variables defined in dotenv file.
    def env(prefix='GH_')
      @envs ||= begin
        ENV.select { |env| env.start_with? prefix }
           .inject({}) do |h, (k, v)|
             h[k.sub(/^#{prefix}/, '').downcase] = v; h
           end
      end
      @envs.merge(dotenv)
    end

    def with_env(prefix='GH_')
      @opts.merge(env(prefix))
    end

    def update_options_with_dotenv(options)
      @@dotenv ||= Dotenv.load
      envs = ENV.select { |env| env.start_with?('GH_') }
                .inject({}) { |h, (k, v)| h[k.sub(/^GH_/, '')] = v; h }
      envs.update(@@dotenv)
      envs.select! { |env| ENV_KEYS.include? env }
      envs.each do |key, val|
        env = key.downcase
        options.update(env => val) unless options[env]
      end
      options
    end
    
  end
end
{'fraction_non_alphanumeric': 0.14925373134328357, 'fraction_numerical': 0.0, 'mean_word_length': 1.8523153942428034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4081032', 'n_tokens_mistral': 834, 'n_tokens_neox': 810, 'n_words': 198}