<commit_before># frozen_string_literal: true

FactoryBot.define do
  factory :meal_signup, class: "Meals::Signup" do
    transient do
      # Type-agnostic way of requesting a specific number of diners be included in the signup
      diner_count { nil }

      # Array of integers defining multiple diner counts.
      diner_counts { nil }
    end

    household
    meal

    after(:build) do |signup, evaluator|
      signup.adult_meat = evaluator.diner_count if evaluator.diner_count
      meal = signup.meal

      if evaluator.diner_counts.nil?
        # 73 TODO: Remove
        Meals::Signup::SIGNUP_TYPES.each do |st|
          next unless (count = signup.send(st)) && count > 0
          type = Meals::Type.new(community: meal.community,
                                 name: st.split("_").map(&:capitalize).join(" "),
                                 category: st.split("_")[-1].capitalize)
          signup.parts.build(count: count, type: type)
        end
      else
        # Create types and parts for the given share values.
        evaluator.diner_counts.each_with_index do |count, index|
          next if count.zero?
          signup.parts.build(count: count, type: signup.types[index])

          # 73 TODO: Remove
          # Need this to keep things in sync and avoid old validation errors.
          signup[Meals::Signup::SIGNUP_TYPES[index]] = count
        end
      end
    end

    trait :with_nums do
      adult_meat { 2 }
      little_kid_veg { 1 }
    end
  end
end<commit_msg>72: Fix with_nums trait<commit_after># frozen_string_literal: true

FactoryBot.define do
  factory :meal_signup, class: "Meals::Signup" do
    transient do
      # Type-agnostic way of requesting a specific number of diners be included in the signup
      diner_count { nil }

      # Array of integers defining multiple diner counts.
      diner_counts { nil }
    end

    household
    meal

    after(:build) do |signup, evaluator|
      signup.adult_meat = evaluator.diner_count if evaluator.diner_count
      meal = signup.meal

      if evaluator.diner_counts.nil?
        # 73 TODO: Remove
        Meals::Signup::SIGNUP_TYPES.each do |st|
          next unless (count = signup.send(st)) && count > 0
          type = Meals::Type.new(community: meal.community,
                                 name: st.split("_").map(&:capitalize).join(" "),
                                 category: st.split("_")[-1].capitalize)
          signup.parts.build(count: count, type: type)
        end
      else
        # Create types and parts for the given share values.
        evaluator.diner_counts.each_with_index do |count, index|
          break if index >= signup.types.size
          next if count.zero?
          signup.parts.build(count: count, type: signup.types[index])

          # 73 TODO: Remove
          # Need this to keep things in sync and avoid old validation errors.
          signup[Meals::Signup::SIGNUP_TYPES[index]] = count
        end
      end
    end

    trait :with_nums do
      diner_counts { [1, 2] }
    end
  end
end
{'fraction_non_alphanumeric': 0.0898360655737705, 'fraction_numerical': 0.005901639344262295, 'mean_word_length': 2.138888888888889, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5511201', 'n_tokens_mistral': 951, 'n_tokens_neox': 921, 'n_words': 259}