<commit_before>class Organization
  include Mongoid::Document
  field :name, type: String
  field :description, type: String
  field :street_address, type: String
  field :zipcode, type: String
  field :city, type: String
  field :state, type: String
  field :urls, type: Array
  field :emails, type: Array
  field :phone, type: String
  field :faxes, type: Array
  field :ttys, type: Array
  field :service_hours, type: String
  field :phones, type: Array
  field :coordinates, type: Array
  field :latitude, type: Float
  field :longitude, type: Float
  field :business_hours, type: Hash
  field :market_match, type: Boolean
  field :schedule, type: String
  field :payments_accepted, type: Array
  field :products_sold, type: Array
  field :languages_spoken, type: Array
  field :keywords, type: Array 
  field :target_group, type: String
  field :eligibility_requirements, type: String
  field :fees, type: String
  field :how_to_apply, type: String
  field :service_wait, type: String
  field :transportation_availability, type: String
  field :accessibility, type: String
  field :services_provided, type: String

  validates_presence_of :name
  
  extend ValidatesFormattingOf::ModelAdditions
  validates_formatting_of :zipcode, using: :us_zip, allow_blank: true, message: "Please enter a valid ZIP code"
  validates_formatting_of :phone, using: :us_phone, allow_blank: true, message: "Please enter a valid US phone number"
  
  validate :validate_emails
  validate :validate_urls

  include Geocoder::Model::Mongoid
  geocoded_by :address               # can also be an IP address
  after_validation :geocode          # auto-fetch coordinates

  scope :find_by_keyword,  lambda { |keyword| any_of({name: /\b#{keyword}\b/i}, {keywords: /\b#{keyword}\b/i}) } 
  scope :find_by_location, lambda {|location, radius| near(location, radius) }
  default_scope order_by(:name => :asc)

  def address
    "#{self.street_address}, #{self.city}, #{self.state} #{self.zipcode}"
  end

  def formatted_name
    if name.present?
      fname = name.split(/(^.*\d)(th)(\s.*)/)
      return fname
    end
  end 

  def validate_emails
    if emails.present?
      emails.each do |email|
        unless email.match(/\A([^@\s]+)@((?:(?!-)[-a-z0-9]+(?<!-)\.)+[a-z]{2,})\z/i)
          errors.add(:emails, "#{email} is not a valid email address.")
        end
      end
    end
  end

  def validate_urls
    if urls.present?<commit_msg>Changes regex to match word boundary<commit_after>class Organization
  include Mongoid::Document
  field :name, type: String
  field :description, type: String
  field :street_address, type: String
  field :zipcode, type: String
  field :city, type: String
  field :state, type: String
  field :urls, type: Array
  field :emails, type: Array
  field :phone, type: String
  field :faxes, type: Array
  field :ttys, type: Array
  field :service_hours, type: String
  field :phones, type: Array
  field :coordinates, type: Array
  field :latitude, type: Float
  field :longitude, type: Float
  field :business_hours, type: Hash
  field :market_match, type: Boolean
  field :schedule, type: String
  field :payments_accepted, type: Array
  field :products_sold, type: Array
  field :languages_spoken, type: Array
  field :keywords, type: Array 
  field :target_group, type: String
  field :eligibility_requirements, type: String
  field :fees, type: String
  field :how_to_apply, type: String
  field :service_wait, type: String
  field :transportation_availability, type: String
  field :accessibility, type: String
  field :services_provided, type: String

  validates_presence_of :name
  
  extend ValidatesFormattingOf::ModelAdditions
  validates_formatting_of :zipcode, using: :us_zip, allow_blank: true, message: "Please enter a valid ZIP code"
  validates_formatting_of :phone, using: :us_phone, allow_blank: true, message: "Please enter a valid US phone number"
  
  validate :validate_emails
  validate :validate_urls

  include Geocoder::Model::Mongoid
  geocoded_by :address               # can also be an IP address
  after_validation :geocode          # auto-fetch coordinates

  scope :find_by_keyword,  lambda { |keyword| any_of({name: /\b#{keyword}\b/i}, {keywords: /\b#{keyword}\b/i}) } 
  scope :find_by_location, lambda {|location, radius| near(location, radius) }
  default_scope order_by(:name => :asc)

  def address
    "#{self.street_address}, #{self.city}, #{self.state} #{self.zipcode}"
  end

  def formatted_name
    if name.present?
      fname = name.split(/(^.*\d)(th)(\b.*)/)
      return fname
    end
  end 

  def validate_emails
    if emails.present?
      emails.each do |email|
        unless email.match(/\A([^@\s]+)@((?:(?!-)[-a-z0-9]+(?<!-)\.)+[a-z]{2,})\z/i)
          errors.add(:emails, "#{email} is not a valid email address.")
        end
      end
    end
  end

  def validate_urls
    if urls.present?
{'fraction_non_alphanumeric': 0.1166084992814617, 'fraction_numerical': 0.0012317799219872716, 'mean_word_length': 3.852589641434263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4196195', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1573, 'n_words': 478}