<commit_before>class Ticket < ActiveRecord::Base
  attr_accessor :age
  belongs_to :show

  validates :show_id, :first_name, :last_name, :email_address, presence: true
  validates :email_address, confirmation: true
  # validate :check_age

  


  def check_card_is_valid?(number)
    number = :credit_card_number
    array_of_numbers = []
    total = 0
    number.to_s.split(//).reverse.each_slice(2) do |x|
      array_of_numbers << (x.last.to_i*2)
      array_of_numbers << (x.first.to_i)
    end
    array_of_numbers.each do |num|
      if num.to_i > 9
        total += (num.to_i % 10)+1
      else 
        total += num.to_i
      end
    end
    n = number.to_s.split('')
    unless total % 10 == 0 || n.size >= 13 && n.size <=19
      errors.add(:credit_card_number, "has an error, please check the numbers")
    end
  end
  
end<commit_msg>add check_age validation and credit card length validations<commit_after>class Ticket < ActiveRecord::Base
  attr_accessor :age 
  belongs_to :show

  validates :show_id, :first_name, :last_name, :email_address, presence: true
  validates :email_address, confirmation: true
  validates :credit_card_number, length: { minimum: 13 }
  validates :credit_card_number, length: { maximum: 19 }
  validate  :check_age

  


  def check_card_is_valid?(number)
    number = :credit_card_number
    array_of_numbers = []
    total = 0
    number.to_s.split(//).reverse.each_slice(2) do |x|
      array_of_numbers << (x.last.to_i*2)
      array_of_numbers << (x.first.to_i)
    end
    array_of_numbers.each do |num|
      if num.to_i > 9
        total += (num.to_i % 10)+1
      else 
        total += num.to_i
      end
    end
    n = number.to_s.split('')
    unless total % 10 == 0 || n.size >= 13 && n.size <=19
      errors.add(:credit_card_number, "has an error, please check the numbers")
    end
  end

  def check_age
    age_to_validate = Date.new(@age[1], @age[2], @age[3])
    if age_to_validate <= Date.current - 18.years
      return true
    else
      errors.add(:age, "needs to be at least 18 years old to purchase the ticket.")
    end
  end
  
end
{'fraction_non_alphanumeric': 0.1126425855513308, 'fraction_numerical': 0.0185361216730038, 'mean_word_length': 2.876611418047882, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 7, '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': '616786', 'n_tokens_mistral': 786, 'n_tokens_neox': 733, 'n_words': 184}