<commit_before>class SampleAttribute < ActiveRecord::Base
  attr_accessible :sample_attribute_type_id, :title, :required, :sample_attribute_type, :pos, :sample_type_id,
                  :_destroy, :sample_type, :unit, :unit_id

  belongs_to :sample_attribute_type
  belongs_to :sample_type, inverse_of: :sample_attributes
  belongs_to :unit

  validates :title, :sample_attribute_type, presence: true
  validates :sample_type, presence: true
  validates :unit, presence: true

  before_save :default_pos

  def validate_value?(value)
    return false if required? && value.blank?
    (value.blank? && !required?) || sample_attribute_type.validate_value?(value)
  end

  # the name for the sample accessor based on the attribute title, spaces are replaced with underscore, and all downcase
  def accessor_name
    title.gsub(' ', '_').downcase
  end

  private

  # if not set, takes the next value for that sample type<commit_msg>Unit isn't required!<commit_after>class SampleAttribute < ActiveRecord::Base
  attr_accessible :sample_attribute_type_id, :title, :required, :sample_attribute_type, :pos, :sample_type_id,
                  :_destroy, :sample_type, :unit, :unit_id

  belongs_to :sample_attribute_type
  belongs_to :sample_type, inverse_of: :sample_attributes
  belongs_to :unit

  validates :title, :sample_attribute_type, presence: true
  validates :sample_type, presence: true
  validates :unit

  before_save :default_pos

  def validate_value?(value)
    return false if required? && value.blank?
    (value.blank? && !required?) || sample_attribute_type.validate_value?(value)
  end

  # the name for the sample accessor based on the attribute title, spaces are replaced with underscore, and all downcase
  def accessor_name
    title.gsub(' ', '_').downcase
  end

  private

  # if not set, takes the next value for that sample type
{'fraction_non_alphanumeric': 0.08526713437668645, 'fraction_numerical': 0.0, 'mean_word_length': 4.704615384615384, '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': '1758378', 'n_tokens_mistral': 560, 'n_tokens_neox': 548, 'n_words': 167}