<commit_before>#
# Copyright (c) 2013-2016 SKYARCH NETWORKS INC.
#
# This software is released under the MIT License.
#
# http://opensource.org/licenses/mit-license.php
#

class ProjectParameter < ActiveRecord::Base
  belongs_to :project
  validates :project_id, uniqueness: {scope: [:key]}
  validates :key, format: { with: /\<KEY> }

  class << self
    # @param [String] target
    # @param [Project] project
    # @param [Integer] project_id
    # @return [String]
    def exec(target, project: nil, project_id: nil)
      raise ArgumentError if !(project_id || project)

      params = self.where(project_id: project_id || project.id)
      re = /(?<!\\)\$\{(?<key>#{params.map(&:key).join('|')})\}/
      target.gsub(re) do |matched|
        key = $~[:key]
        params.find_by(key: key).value
      end
    end
  end
end<commit_msg>Remove unused parameter<commit_after>#
# Copyright (c) 2013-2016 SKYARCH NETWORKS INC.
#
# This software is released under the MIT License.
#
# http://opensource.org/licenses/mit-license.php
#

class ProjectParameter < ActiveRecord::Base
  belongs_to :project
  validates :project_id, uniqueness: {scope: [:key]}
  validates :key, format: { with: /\<KEY> }

  class << self
    # @param [String] target
    # @param [Project] project
    # @param [Integer] project_id
    # @return [String]
    def exec(target, project: nil, project_id: nil)
      raise ArgumentError if !(project_id || project)

      params = self.where(project_id: project_id || project.id)
      re = /(?<!\\)\$\{(?<key>#{params.map(&:key).join('|')})\}/
      target.gsub(re) do
        key = $~[:key]
        params.find_by(key: key).value
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1581450653983353, 'fraction_numerical': 0.009512485136741973, 'mean_word_length': 3.2075, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1339852', 'n_tokens_mistral': 582, 'n_tokens_neox': 563, 'n_words': 144}