<commit_before>class Craft < ApplicationRecord
  belongs_to :user
  has_many :craft_tags
  has_many :tags, through: :craft_tags

  accepts_nested_attributes_for :tags, reject_if: proc { |attributes| attributes['name'].blank? } ## for temporary use, need to use custom attribute writer

  validates_presence_of :title, :difficulty, :description, :instructions
  validates :difficulty, inclusion: { in: %w(easy medium hard), message: "%{value} is not a valid difficulty" }
end<commit_msg>added custom attribute writer for tags<commit_after>class Craft < ApplicationRecord
  belongs_to :user
  has_many :craft_tags
  has_many :tags, through: :craft_tags

  validates_presence_of :title, :difficulty, :description, :instructions
  validates :difficulty, inclusion: { in: %w(easy medium hard), message: "%{value} is not a valid difficulty" }

  def tags_attributes=(tags_attributes)
    tags_attributes.values.each do |tag_attributes|
     tag = Tag.find_or_create_by(tag_attributes)
     tags << tag if tag.persisted? && !tag.name.blank?
   end
  end
end
{'fraction_non_alphanumeric': 0.0980952380952381, 'fraction_numerical': 0.0, 'mean_word_length': 5.527950310559007, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4090276', 'n_tokens_mistral': 324, 'n_tokens_neox': 316, 'n_words': 95}