<commit_before>class Line < ApplicationRecord
  belongs_to :auth, :class_name => "User"
  belongs_to :corpse, optional: true
  validates :text, presence: true, length: {maximum: 200}
  validate :word_count, unless: Proc.new {|a| a.corpse != nil && a.corpse.current_scribe.nil? }

  def lose_word
    if self.text.split.length > 1
      prev_line = self.text.split
      prev_line.delete_at(rand(prev_line.length))
      self.text = prev_line.join(" ")
      self.save
    end
  end

  private
  def word_count
    @count = text.scan(/[[:alpha:]]+/).count
    if @count < 10
      errors.add(:text, "That's #{10 - @count} too few words for the line.")
    elsif @count > 20
      errors.add(:text, "That's #{@count - 20} too many words for the line.")
    end
  end

end
<commit_msg>added comments<commit_after>class Line < ApplicationRecord
  belongs_to :auth, :class_name => "User"
  belongs_to :corpse, optional: true
  validates :text, presence: true, length: {maximum: 200}
  validate :word_count, unless: Proc.new {|a| a.corpse != nil && a.corpse.current_scribe.nil? } #the exception allows decompose to reduce word count below 10

  def lose_word
    if self.text.split.length > 1
      prev_line = self.text.split
      prev_line.delete_at(rand(prev_line.length))
      self.text = prev_line.join(" ")
      self.save
    end
  end

  private
  def word_count
    @count = text.scan(/[[:alpha:]]+/).count
    if @count < 10
      errors.add(:text, "That's #{10 - @count} too few words for the line.")
    elsif @count > 20
      errors.add(:text, "That's #{@count - 20} too many words for the line.")
    end
  end

end

{'fraction_non_alphanumeric': 0.13214505224339274, 'fraction_numerical': 0.015980331899200985, 'mean_word_length': 3.090452261306533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1829380', 'n_tokens_mistral': 583, 'n_tokens_neox': 547, 'n_words': 157}