<commit_before>class Period < ActiveRecord::Base
  belongs_to :squat

  validates :start_year, presence: true
  validates :start_month, presence: true, if: :start_day
  validates :end_year, presence: true, if: :end_month
  validates :end_month, presence: true, if: :end_day

  # todo validations:
  # years in 1900 .. today
  # months in 1..12
  # days in 1..31

  def to_s

    start_string = ""
    if start_year
      start_string << start_year.to_s
    end
    if start_month
      start_string << "-" + start_month.to_s
    end
    if start_day
      start_string << "-" + start_day.to_s
    end

    unless start_string.blank?
      start_string = I18n.t(:period_from).capitalize + ": " + start_string
    end

    end_string = ""
    if end_year
      end_string << end_year.to_s
    end
    if end_month
      end_string << "-" + end_month.to_s
    end
    if end_day
      end_string << "-" + end_day.to_s
    end

    unless end_string.blank?
      end_string = I18n.t(:period_to) + ": " + end_string
    end

    if !end_string.blank?
      start_string + " - " + end_string
    else 
      start_string
    end

  end

end
<commit_msg>add period validations<commit_after>class Period < ActiveRecord::Base
  belongs_to :squat

  validates :start_year, presence: true
  validates :start_month, presence: true, if: :start_day
  validates :end_year, presence: true, if: :end_month
  validates :end_month, presence: true, if: :end_day
  validates :start_year,
            :end_year,
            inclusion: { in: 1900..Date.today.year }
  validates :start_month,
            :end_month,
            inclusion: { in: 1..12 }
  validates :start_day,
            :end_day,
            inclusion: { in: 1..31 }
  validates :start_year, numericality: { less_than_or_equal_to: :end_year }

  def to_s

    start_string = ""
    if start_year
      start_string << start_year.to_s
    end
    if start_month
      start_string << "-" + start_month.to_s
    end
    if start_day
      start_string << "-" + start_day.to_s
    end

    unless start_string.blank?
      start_string = I18n.t(:period_from).capitalize + ": " + start_string
    end

    end_string = ""
    if end_year
      end_string << end_year.to_s
    end
    if end_month
      end_string << "-" + end_month.to_s
    end
    if end_day
      end_string << "-" + end_day.to_s
    end

    unless end_string.blank?
      end_string = I18n.t(:period_to) + ": " + end_string
    end

    if !end_string.blank?
      start_string + " - " + end_string
    else 
      start_string
    end

  end

end

{'fraction_non_alphanumeric': 0.09836065573770492, 'fraction_numerical': 0.01092896174863388, 'mean_word_length': 2.39021164021164, 'pattern_counts': {'":': 4, '<': 29, '<?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': '1834336', 'n_tokens_mistral': 930, 'n_tokens_neox': 890, 'n_words': 201}