<commit_before>class Licence < ActiveRecord::Base
  include ModelSupport
  include LicenceText

  belongs_to :study

  attr_accessible :signed_by, :email, :access_mode, :signed_date

  validates_presence_of :signed_by, :if => :checking,
    :message => "Name required."
  validates_presence_of :email, :if => :checking,
    :message => "Contact email required."
  validates_presence_of :access_mode, :if => :checking,
    :message => "Please select one."
  validates_presence_of :signed_date, :if => :checking,
    :message => "Date required."

  validates_format_of   :signed_by, :with => /\A[\w -]*\Z/,
    :if => :checking,
    :message => "Only letters, spaces and hyphens are allowed."
  validates_format_of   :signed_by, :with => /\A[^\d_]*\Z/,
    :if => :checking,
    :message => "Only letters, spaces and hyphens are allowed."
  validates_format_of   :email,
    :with => /\A([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})?\Z/i,
    :if => :checking,
    :message => "Does not look like email address."

  validates_inclusion_of :access_mode, :in => ['', 'A', 'B', 'S'],
                         :if => :checking,
                         :message => "Value must be A, B or S."

  validates_each :signed_date do |record, attr, value|
    record.parse_and_validate_date(attr, value, Date.today.year - 1)
  end

  attr_reader :checking

  def selections(column)
    case column.to_sym
    when :access_mode
      [ [ "A - Unrestricted (see 3.i)", "A"],
        [ "B - By permission (see 3.ii)", "B" ],
        [ "S - To be negotiated", "S" ] ]
    end
  end

  def empty_selection(column)
    column.to_sym == :access_mode ? "" : false
  end

  def text(html = true)
    text = full_text(access_mode)
    unless html
      text.gsub!(/<\/?[^>]*>/, "")  # strips html tags<commit_msg>Licence validation now requires a complete signature date.<commit_after>class Licence < ActiveRecord::Base
  include ModelSupport
  include LicenceText

  belongs_to :study

  attr_accessible :signed_by, :email, :access_mode, :signed_date

  validates_presence_of :signed_by, :if => :checking,
    :message => "Name required."
  validates_presence_of :email, :if => :checking,
    :message => "Contact email required."
  validates_presence_of :access_mode, :if => :checking,
    :message => "Please select one."
  validates_presence_of :signed_date, :if => :checking,
    :message => "Date required."

  validates_format_of   :signed_by, :with => /\A[\w -]*\Z/,
    :if => :checking,
    :message => "Only letters, spaces and hyphens are allowed."
  validates_format_of   :signed_by, :with => /\A[^\d_]*\Z/,
    :if => :checking,
    :message => "Only letters, spaces and hyphens are allowed."
  validates_format_of   :email,
    :with => /\A([A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4})?\Z/i,
    :if => :checking,
    :message => "Does not look like email address."

  validates_inclusion_of :access_mode, :in => ['', 'A', 'B', 'S'],
                         :if => :checking,
                         :message => "Value must be A, B or S."

  validates_each :signed_date do |record, attr, value|
    date = record.parse_and_validate_date(attr, value, Date.today.year - 1)
    record.errors.add attr, "Incomplete date." if date and date.day.nil?
  end

  attr_reader :checking

  def selections(column)
    case column.to_sym
    when :access_mode
      [ [ "A - Unrestricted (see 3.i)", "A"],
        [ "B - By permission (see 3.ii)", "B" ],
        [ "S - To be negotiated", "S" ] ]
    end
  end

  def empty_selection(column)
    column.to_sym == :access_mode ? "" : false
  end

  def text(html = true)
    text = full_text(access_mode)
    unless html
      text.gsub!(/<\/?[^>]*>/, "")  # strips html tags
{'fraction_non_alphanumeric': 0.15894936366098023, 'fraction_numerical': 0.00487408610885459, 'mean_word_length': 2.955032119914347, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, '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': '1639671', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1247, 'n_words': 327}