<commit_before>require "usernamegen/version"
require "securerandom"
require "active_support"
require "active_support/core_ext"

class Usernamegen
  ROOT = File.expand_path("../..", __FILE__)

  def self.one(opts = {}, &block)
    new(opts).one(&block)
  end

  def self.all(opts = {}, &block)
    new(opts).all(&block)
  end

  def self.all_for_thing(thing, opts = {}, &block)
    new(opts).all_for_thing(thing, &block)
  end

  def self.all_for_desc(desc, opts = {}, &block)
    new(opts).all_for_desc(desc, &block)
  end

  def initialize opts = {}
    @opts = opts.reverse_merge({
      descriptions: "#{ROOT}/lib/usernamegen/descriptions.txt",
      things: "#{ROOT}/lib/usernamegen/things.txt",
      rng: ::SecureRandom.urlsafe_base64(128),
    })
    @descriptions = load_file @opts[:descriptions]
    @things = load_file @opts[:things]
  end

  def load_file file
    File.read(file).split("\n").map(&:strip).reject(&:blank?)
  end

  def one(&block)
    username_arr = [@descriptions.sample(1, random: @opts[:rng]), @things.sample(1, random: @opts[:rng])]

    formatted = if block_given?
      yield username_arr
    else
      username_arr.join(" ").titleize
    end

    formatted
  end

  def all(&block)
    all_usernames = if block_given?
      @descriptions.product(@things).map{|combination| yield combination }
    else
      @descriptions.product(@things).map{|combination| combination.join(" ").titleize }
    end

    all_usernames
  end

  def all_for_thing(thing, &block)
    all_usernames = if block_given?
      @descriptions.product([thing]).map{|combination| yield combination }
    else
      @descriptions.product([thing]).map{|combination| combination.join(" ").titleize }
    end

    all_usernames
  end

  def all_for_desc(desc, &block)
    all_usernames = if block_given?
      [desc].product(@things).map{|combination| yield combination }
    else
      [desc].product(@things).map{|combination| combination.join(" ").titleize }
    end

    all_usernames
  end
end<commit_msg>Change code style to closer match my (worse?) one :)<commit_after>require "usernamegen/version"
require "securerandom"
require "active_support"
require "active_support/core_ext"

class Usernamegen
  ROOT = File.expand_path("../..", __FILE__)

  def self.one(opts = {}, &block)
    new(opts).one(&block)
  end

  def self.all(opts = {}, &block)
    new(opts).all(&block)
  end

  def self.all_for_thing(thing, opts = {}, &block)
    new(opts).all_for_thing(thing, &block)
  end

  def self.all_for_desc(desc, opts = {}, &block)
    new(opts).all_for_desc(desc, &block)
  end

  def initialize opts = {}
    @opts = opts.reverse_merge({
      descriptions: "#{ROOT}/lib/usernamegen/descriptions.txt",
      things: "#{ROOT}/lib/usernamegen/things.txt",
      rng: ::SecureRandom.urlsafe_base64(128),
    })
    @descriptions = load_file @opts[:descriptions]
    @things = load_file @opts[:things]
  end

  def load_file file
    File.read(file).split("\n").map(&:strip).reject(&:blank?)
  end

  def one
    username_arr = [@descriptions.sample(1, random: @opts[:rng]), @things.sample(1, random: @opts[:rng])]

    if block_given?
      yield username_arr
    else
      username_arr.join(" ").titleize
    end
  end

  def all
    if block_given?
      @descriptions.product(@things).map{|combination| yield combination }
    else
      @descriptions.product(@things).map{|combination| combination.join(" ").titleize }
    end
  end

  def all_for_thing thing
    if block_given?
      @descriptions.product([thing]).map{|combination| yield combination }
    else
      @descriptions.product([thing]).map{|combination| combination.join(" ").titleize }
    end
  end

  def all_for_desc desc
    if block_given?
      [desc].product(@things).map{|combination| yield combination }
    else
      [desc].product(@things).map{|combination| combination.join(" ").titleize }
    end
  end
end
{'fraction_non_alphanumeric': 0.14549653579676675, 'fraction_numerical': 0.00359250705671029, 'mean_word_length': 3.607565011820331, 'pattern_counts': {'":': 0, '<': 3, '<?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': '872888', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1280, 'n_words': 256}