<commit_before>require "open-uri"
require "nokogiri"
require "drophunter/page"
require "drophunter/file_types/image"

module Drophunter
  class Worker < Struct.new(:strategy)
    ALLOWED_CHARS = [*"a".."z", *"A".."Z"]

    def run
      send("#{strategy || :default}_strategy")
    end

    private

    def save_file(id)
      Drophunter::Page.new(id).save(Drophunter::FileTypes::Image)
    end

    def default_strategy
      ALLOWED_CHARS.repeated_permutation(4).each do |id_as_array|
        save_file(id_as_array.join)
      end
    end

    def random_strategy
      Enumerator.new do |enumerator|
        loop do
          enumerator.yield(4.times.map { ALLOWED_CHARS[Random.rand(0..ALLOWED_CHARS.length)] }.join)
        end
      end.each do |id|
        save_file(id)
      end
    end
  end
end<commit_msg>Allow to connect to strategy from inside app<commit_after>require "open-uri"
require "nokogiri"
require "drophunter/page"
require "drophunter/file_types/image"

module Drophunter
  class Worker < Struct.new(:strategy)
    ALLOWED_CHARS = [*"a".."z", *"A".."Z"]

    def run
      send("#{strategy || :default}_strategy")
    end

    def save_file(id)
      Drophunter::Page.new(id).save(Drophunter::FileTypes::Image)
    end

    def default_strategy
      ALLOWED_CHARS.repeated_permutation(4).each do |id_as_array|
        save_file(id_as_array.join)
      end
    end

    def random_strategy(&block)
      Enumerator.new do |enumerator|
        loop do
          enumerator.yield(4.times.map { ALLOWED_CHARS[Random.rand(0..ALLOWED_CHARS.length)] }.join)
        end
      end.each { |id| block.call(id) }
    end
  end
end
{'fraction_non_alphanumeric': 0.1192214111922141, 'fraction_numerical': 0.0036496350364963502, 'mean_word_length': 2.9448441247002397, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1517766', 'n_tokens_mistral': 609, 'n_tokens_neox': 589, 'n_words': 109}